-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.js
More file actions
74 lines (63 loc) · 1.66 KB
/
Copy pathcli.js
File metadata and controls
74 lines (63 loc) · 1.66 KB
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
import arg from 'arg'
import chalk from 'chalk'
import spawn from 'cross-spawn'
import packageJson from './package.json'
const commands = ['connect', 'init']
const args = arg(
{
// Types
'--version': Boolean,
'--help': Boolean,
// Aliases
'-v': '--version',
'-h': '--help',
},
{
permissive: true,
}
)
if (args['--version']) {
console.log(packageJson.version)
process.exit(0)
}
if (args['--help'] || !args._.length) {
console.log(`
Usage:
$ mould <command> [workdir]
Available commands:
${commands.join(', ')}
Options:
--version, -v output the version number
--help, -h output usage information
`)
process.exit(0)
}
const [command, workdir = '.'] = args._
if (commands.includes(command)) {
const result = spawn.sync(
'node',
['-r', 'esm', require.resolve(`./commands/${command}`)],
{ env: { ...process.env, WORKDIR: workdir }, stdio: 'inherit' }
)
if (result.signal) {
if (result.signal === 'SIGKILL') {
console.log(
'The script failed because ' +
'the process received a request for its immediate termination.'
)
} else if (result.signal === 'SIGTERM') {
console.log(
'The script failed because ' +
'the process received a request for its termination.'
)
}
process.exit(1)
}
process.exit(result.status)
} else {
console.error(
`Unknown command:\n\n` +
` ${chalk.cyan('mould')} ${chalk.red(command)}\n`
)
process.exit(1)
}