-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
49 lines (39 loc) · 1.25 KB
/
cli.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
#!/usr/bin/env node
const fs = require('fs');
const commandLineArgs = require('command-line-args');
const loadData = require('./lib');
const {
printUpdates,
} = require('./lib/updates');
const { path, repo, limit, message, ext = [], ignoreExt, json, till } = commandLineArgs([
{ name: 'repo', type: String, alias: 'r', description: 'test' },
{ name: 'limit', type: Number, alias: 'l', defaultValue: Infinity },
{ name: 'till', type: String, alias: 't', defaultValue: ''},
{ name: 'path', type: String, alias: 'p', defaultValue: '/' },
{ name: 'message', type: String, alias: 'm', defaultValue: '' },
{ name: 'ext', type: String, alias: 'e', multiple: true, },
{ name: 'ignoreExt', type: String, alias: 'i', multiple: true, },
{ name: 'json', type: String, alias: 'j' }
]);
printUpdates();
(async () => {
const [ ...entries ] = await loadData({
repo,
path,
limit,
till,
message,
ext,
ignoreExt,
});
if (!json) {
// eslint-disable-next-line
entries.forEach(entry => console.log(entry.join(' => ')));
return ;
}
const entriesAsObject = entries.reduce((R, [ fileName, occurrences ]) => {
R[fileName] = occurrences;
return R;
}, {});
fs.writeFileSync(json, JSON.stringify(entriesAsObject));
})();