-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsloc.js
More file actions
66 lines (61 loc) · 1.78 KB
/
sloc.js
File metadata and controls
66 lines (61 loc) · 1.78 KB
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
63
64
65
66
import fs from 'node:fs';
import path from 'node:path';
import sloc from 'sloc';
import url from 'node:url';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
const include = [
path.resolve(__dirname, 'packages', 'demo/src'),
path.resolve(__dirname, 'packages', 'kit-codemirror/src'),
path.resolve(__dirname, 'packages', 'material-code/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)