-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
74 lines (58 loc) · 1.53 KB
/
cli.js
File metadata and controls
74 lines (58 loc) · 1.53 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
#!/usr/bin/env node
require('dotenv').config();
const arg = require('arg');
const fs = require('fs-extra');
const execa = require('execa');
process.on('unhandledRejection', (error) => {
console.log(error);
process.exit(0);
});
(async () => {
const commands = ['build', 'setup', 'deploy', 'create-addon', 'zip', 'sign'];
const defaultEnv = 'production';
const args = arg(
{
// Types
'--version': Boolean,
'--help': Boolean,
// Aliases
'-v': '--version',
'-h': '--help',
},
{
permissive: true,
}
);
const command = args._.find(cmd => commands.includes(cmd));
if (args['--version']) {
const { version } = await fs.readJson('package.json');
console.log(`v${version}`);
process.exit(0);
}
if (!command && args['--help']) {
console.log(`
Usage
$ sitevision-scripts <command>
Available commands
${commands.join(', ')}
Options
--version, -v Version number
--help, -h Displays this message
For more information run a command with the --help flag
$ sitevision-scripts build --help`);
process.exit(0);
}
if (!command || !commands.includes(command)) {
console.log(`Unknown command "${command}"`);
process.exit(0);
}
const bin = require.resolve(`./scripts/${command}`);
const forwardedArgs = args._.filter(a => a !== command);
if (args['--help']) {
forwardedArgs.push('--help');
}
process.env.NODE_ENV = process.env.NODE_ENV || defaultEnv;
execa('node', [bin, ...forwardedArgs], {
stdio: 'inherit',
});
})();