-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.js
111 lines (103 loc) · 2.45 KB
/
prog.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const prog = require('caporal');
const packageJSON = require('./package.json');
const surfaceAction = require('./cli/surface');
const dependenciesAction = require('./cli/dependencies');
const dependentAction = require('./cli/dependent');
const nayliasAction = require('./cli/naylias');
prog.version(packageJSON.version);
const GLOBAL_OPTIONS = [
['--target-dir <path>', 'Target scan directory', prog.STRING, '.'],
['--project-root <path>', 'Project root path', prog.STRING, process.cwd()],
['--ext <extensions>', 'File extensions to be matched', prog.LIST, 'js'],
[
'--incl <glob-patterns>',
'Glob patterns to include in scan',
prog.LIST,
'**/*.js'
],
[
'--excl <glob-patterns>',
'Glob patterns to exclude in scan',
prog.LIST,
'node_modules/**'
],
[
'--alias <aliases>',
'Alias used within your project. E.g: my-alias-name:path/to/my/alias',
prog.REPEATABLE,
'',
false
],
[
'--rescan <boolean>',
'Invalidates chipper cache and forces a rescan',
prog.BOOL,
false,
false
],
[
'--silence-console <boolean>',
'Disable all console messages',
prog.BOOL,
false,
false
],
[
'--file-scan-parallelism <number>',
'Number of files to scan at once',
prog.INTEGER,
50
],
[
'--output-format <format>',
'return output in JSON format',
prog.STRING,
false,
false
]
];
const surfaceCmd = prog
.command(
'surface',
'Examine the surface area of a module or a directory of modules'
)
.alias('surf')
.argument(
'target',
'Target module or directory of modules to analyse usage.',
prog.STRING
)
.action(surfaceAction);
const depsCmd = prog
.command(
'dependencies',
'List all imports by a module or a directory of modules'
)
.alias('dep')
.argument(
'target',
'Target module or directory of modules to see all imports for',
prog.STRING
)
.action(dependenciesAction);
const dependentCmd = prog
.command('dependent', 'Check if a module depends on another module')
.argument(
'source',
'Source module to check if it is dependent on target module',
prog.STRING
)
.argument('target', 'target module', prog.STRING)
.action(dependentAction);
const nayliasCmd = prog
.command('naylias', 'List all modules where an alias could be utilized')
.alias('nay')
.argument('alias', 'Alias to check for utilization', prog.STRING)
.action(nayliasAction);
GLOBAL_OPTIONS.forEach(o => {
surfaceCmd.option(...o);
depsCmd.option(...o);
nayliasCmd.option(...o);
dependentCmd.option(...o);
});
module.exports = prog;