-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsloc.js
62 lines (58 loc) · 1.64 KB
/
sloc.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs');
const path = require('path');
const sloc = require('sloc');
const include = [
path.resolve(__dirname, 'packages', 'react-use-snack/demo'),
path.resolve(__dirname, 'packages', 'react-use-snack/src'),
];
let scannner = function(dir, root, fileList = []) {
let files = fs.readdirSync(dir);
files.forEach(function(file) {
let abs = path.join(dir, file);
if(fs.statSync(abs).isDirectory()) {
if(abs.indexOf('node_modules') === -1) {
fileList = scannner(abs, root, fileList);
}
} else {
let included = false;
include.forEach(allowed => {
if(abs.indexOf(allowed) !== -1) {
included = true;
}
});
if(included) {
fileList.push(abs);
}
}
});
return fileList;
};
const directoryPath = path.join(__dirname, 'packages');
const files = scannner(directoryPath, directoryPath, []);
const stats = {
files: 0,
total: 0,
source: 0,
comment: 0,
single: 0,
block: 0,
mixed: 0,
empty: 0,
todo: 0,
blockEmpty: 0,
};
files.forEach((file) => {
const code = fs.readFileSync(file, 'utf8');
let fileStats = sloc(code, 'js');
stats.files++;
stats.total += fileStats.total;
stats.source += fileStats.source;
stats.comment += fileStats.comment;
stats.single += fileStats.single;
stats.block += fileStats.block;
stats.mixed += fileStats.mixed;
stats.empty += fileStats.empty;
stats.todo += fileStats.todo;
stats.blockEmpty += fileStats.blockEmpty;
});
console.log(stats)