-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (70 loc) · 2.03 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { each } = require('lodash');
const { du, parseArgs, scanFiles } = require('./lib');
const extraFileExtensions = {
'.conf': 'Shell',
'.csv': 'Comma Separated Values',
'.emblem': 'Emblem',
'.fdoc': 'FDOC',
'.ipynb': 'Jupyter Notebook',
'.jmx': 'JMeter Maven Plugin',
'.js.snap': 'Jest',
'.jsx.snap': 'Jest',
'.make': 'Makefile',
'.mdown': 'Markdown',
'.pl': 'Perl', // language-detect considers .pl to be Prolog, but it rarely is
'.react.js': 'React',
'.react.jsx': 'React',
'.react.ts': 'React',
'.react.tsx': 'React',
'.ts': 'Typescript',
'.ts.snap': 'Jest',
'.tsx': 'Typescript',
'.tsx.snap': 'Jest',
'.tsv': 'Tab Separated Values',
};
const ignores = [
'**/.git',
'**/node_modules',
'**/package-lock.json',
];
const out = (...args) => {
console.log(...args);
};
parseArgs(process)
.then(async ({ absolute, debug, format, raw, summary, target }) => {
const scanner = scanFiles(
target,
{ absolute, debug, extraFileExtensions, ignores }
);
scanner.onError((err) => { console.error(err); });
if (raw) {
scanner.onScan(({ file, language, lines, bytes }) => {
if (format === 'csv') {
out(`"${file}","${language}",${lines},${bytes}`);
}
if (format === 'json') {
out(JSON.stringify({ file, language, lines, bytes }));
}
});
}
await scanner.onceComplete();
if (summary) {
const languages = scanner.getSummary();
out(`Target: ${target}`);
const diskUsage = await du(target);
out(`Disk Usage: ${diskUsage}`);
const arr = [];
each(languages, ({ files, lines, bytes }, language) => {
arr.push([language, files, lines, bytes]);
});
arr.sort((a, b) => b[2] - a[2]); // Sort by line count
out('Languages:');
each(arr, ([language, files, lines, bytes]) => {
out(` ${language}: ${files} files, ${lines} lines, ${bytes} bytes`);
});
}
})
.catch((err) => {
console.error(`Error: ${err.message || err}`);
process.exit(1);
});