forked from opentiny/tiny-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount-api.js
34 lines (27 loc) · 879 Bytes
/
count-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs');
const basePath = './examples/sites/demos/pc/app';
const readFile = function (path) {
let componentCount = 0;
let apiCount = 0;
const readDir = fs.readdirSync(path);
readDir.forEach(i => {
const curDir = `${path}/${i}`;
const stat = fs.statSync(curDir);
if (stat.isFile() && i.endsWith('.js')) {
componentCount += 1;
const data = fs.readFileSync(curDir, 'utf-8');
let dataJson = null;
try {
dataJson = JSON.parse(data);
} catch (err) {
console.log('err:', err);
}
if (dataJson !== null) {
apiCount += (dataJson.attrs?.length || 0) + (dataJson.slots?.length || 0) + (dataJson.events?.length || 0) + (dataJson.methods?.length || 0);
}
}
});
console.log('componentCount:', componentCount);
console.log('apiCount:', apiCount);
}
readFile(basePath);