-
Notifications
You must be signed in to change notification settings - Fork 26
/
inspect.js
executable file
·73 lines (60 loc) · 2.17 KB
/
inspect.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
#!/usr/bin/env node
'use strict'
/* -----------------------------------------------------------------------------
* dependencies
* -------------------------------------------------------------------------- */
// 3rd party
const _ = require('lodash/fp')
const yargs = require('yargs')
const nodeflags = require('nodeflags')
// lib
const inspect = require('../lib/index')
/* -----------------------------------------------------------------------------
* usage
* -------------------------------------------------------------------------- */
const inspectCliOptions = {
'debug-exception': {
type: 'boolean',
description: 'Pause debuuger on exceptions.'
},
'log-level': {
type: 'string',
description: 'The level to display logs at.',
choices: ['silly', 'verbose', 'info'],
default: 'info'
}
}
// early parse in order to show inspect specific help options
yargs.options(inspectCliOptions)
.usage('\nUsage:\ninspect [inspect options] [node options] [v8 options] [script] [arguments]')
.version()
.help()
.argv
/* -----------------------------------------------------------------------------
* inspect
* -------------------------------------------------------------------------- */
nodeflags((err, flags) => {
if (err) {
throw new Error(err)
}
const parsed = yargs.options(flags).argv
const args = process.argv.slice(2)
const cmd = parsed._[0]
const cmdIndex = args.indexOf(cmd)
const processArgs = args.slice(0, cmdIndex)
// all keys after the cmd should be considered childArgs
const childArgs = args.slice(cmdIndex + 1)
// inspectOptions are just picked from our parsed args. We pass "options"
// rather than args because we are not proxying the args to the future
// child_process
const inspectKeys = _.keys(inspectCliOptions)
const inspectFlags = _.map((key) => '--' + key)(inspectKeys)
const inspectOptions = _.pick(inspectKeys)(parsed)
// node args are simply processArgs that are not inspectArgs
const nodeArgs = _.remove((arg) => {
return inspectFlags.includes(arg.split('=')[0])
})(processArgs)
inspect(cmd, { nodeArgs, childArgs, inspectOptions })
.then(() => process.exit())
.catch(() => process.exit(1))
})