UNPKG

1.94 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3const chalk = require('chalk');
4const nopt = require('nopt');
5const update = require('update-notifier');
6const pkg = require('../package.json');
7const nitro = require('../lib');
8
9// Workaround for MacOS which doesn't allow to sigint
10process.on('SIGINT', () => {
11 process.exit();
12});
13
14// Options that can be passed to commands
15const options = {
16 config: String,
17 launch: String,
18 publish: String
19};
20
21// Shorthands for the above commands
22const shorthands = {
23 v: '--version',
24 c: 'config',
25 l: 'launch',
26 p: 'publish'
27};
28
29const parsed = nopt(options, shorthands);
30
31// Cmd.args contains basic commands like "new" and "help"
32// cmd.opts contains options, like --libsass and --version
33const cmd = {
34 args: parsed.argv.remain,
35 opts: parsed
36};
37
38// Check for updates once a day
39const notifier = update({
40 packageName: pkg.name,
41 packageVersion: pkg.version
42});
43
44if (notifier.update) {
45 notifier.notify({
46 defer: false,
47 message: chalk.bold('APEX Nitro') + ' update available ' +
48 chalk.dim(notifier.update.current) +
49 chalk.reset(' → ') +
50 chalk.green(notifier.update.latest) +
51 ' \nRun:\n' + chalk.cyan.bold('npm install -g apex-nitro')
52 });
53}
54
55// No other arguments given
56if (typeof cmd.args[0] === 'undefined') {
57 if (typeof cmd.opts.version === 'undefined') {
58 // Otherwise, just show the help screen
59 nitro.help();
60 } else {
61 // If -v or --version was passed, show the version of the CLI
62 process.stdout.write('APEX Nitro version ' + pkg.version + '\n');
63 }
64} else if (typeof nitro[cmd.args[0]] === 'undefined') {
65 // Arguments given
66 // If the command typed in doesn't exist, show the help screen
67 nitro.help();
68} else {
69 // Otherwise, just run it already!
70 // Every command function is passed secondary commands, and options
71 // So if the user types "apex-nitro launch myApp --test",
72 // "myApp" is a secondary command, and "--test" is an option
73 nitro[cmd.args[0]](cmd.args.slice(1), cmd.opts);
74}