-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathcli.js
executable file
·42 lines (34 loc) · 1.1 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
#!/usr/bin/env node
'use strict';
const { program } = require('commander');
const dependencyTree = require('../index.js');
const { name, description, version } = require('../package.json');
program
.name(name)
.description(description)
.version(version)
.usage('[options] <filename>')
.option('-d, --directory <path>', 'location of files of supported filetypes')
.option('-c, --require-config <path>', 'path to a requirejs config')
.option('-w, --webpack-config <path>', 'path to a webpack config')
.option('-t, --ts-config <path>', 'path to a typescript config')
.option('--list-form', 'output the list form of the tree (one element per line)')
.parse();
const cliOptions = program.opts();
const options = {
filename: program.args[0],
root: cliOptions.directory,
config: cliOptions.requireConfig,
webpackConfig: cliOptions.webpackConfig,
tsConfig: cliOptions.tsConfig
};
let tree;
if (cliOptions.listForm) {
tree = dependencyTree.toList(options);
for (const node of tree) {
console.log(node);
}
} else {
tree = dependencyTree(options);
console.log(JSON.stringify(tree));
}