-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·87 lines (70 loc) · 2.16 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
81
82
83
84
85
86
87
#! /usr/bin/env node
/**
* Dive into source
*
*/
const parseArgs = require('minimist')
const defaultConfig = require('./config.js')
const Engine = require('./packages/engine/index.js')
// const validateCliOptions = require('./cli/validate-options.js')
const packageJson = require('./package.json')
const argvMap = parseArgs(process.argv.slice(2), {
alias: {
c: 'config',
d: 'debug',
s: 'signal',
p: 'port',
a: 'address',
v: 'version',
h: 'help',
},
})
const defaultRepoPath = './' // Default, We analyze files of curent dir
const { version } = packageJson
const printHelpMessage = () => `
Usage: divesource [OPTIONS] path-of-codebase
A tool to help you analyze youre code base.
Visit: https://github.com/92hackers/dive-into-source to get more details.
Options:
-c, --config Specify custom config directory, default: ~/.divesource/
--print-config Print configuration information that will be used by divesource
-d, --debug Output extra debug information
-s, --signal <stop, quit, reload> Send signal to a master process: stop, quit, reload
-p, --port Specify a custom port for divesource engine to listening on
-a, --address Specify a custom network address, Default is localhost
-v, --version Print version information and quit
-h, --help Print help messages
`
function exit() {
process.exit(0)
}
function processArgs(argv) {
let cliOptions = Object.create(null) // Pure map
const repoPath = argv._[0] || defaultRepoPath
cliOptions = { repoPath }
if (argv.help) { // show help page and exit
console.log(printHelpMessage())
exit()
}
if (argv.version) { // show version and exit
console.log(version)
exit()
}
return {
...cliOptions,
configDir: argv.config || {},
debug: argv.debug || false,
signal: argv.signal,
port: argv.port,
address: argv.address,
}
}
const cliOptions = processArgs(argvMap)
// TODO: Validate cli options
//
// if (validateCliOptions(cliOptions) > 0) {
// process.exit(1)
// }
const finalConfig = Object.seal({ ...defaultConfig, ...cliOptions })
const engine = Object.seal(new Engine(finalConfig))
engine.run()