1 | #!/usr/bin/env node
|
2 |
|
3 | const chalk = require('chalk');
|
4 | const nopt = require('nopt');
|
5 | const update = require('update-notifier');
|
6 | const pkg = require('../package.json');
|
7 | const nitro = require('../lib');
|
8 |
|
9 |
|
10 | process.on('SIGINT', () => {
|
11 | process.exit();
|
12 | });
|
13 |
|
14 |
|
15 | const options = {
|
16 | config: String,
|
17 | launch: String,
|
18 | publish: String
|
19 | };
|
20 |
|
21 |
|
22 | const shorthands = {
|
23 | v: '--version',
|
24 | c: 'config',
|
25 | l: 'launch',
|
26 | p: 'publish'
|
27 | };
|
28 |
|
29 | const parsed = nopt(options, shorthands);
|
30 |
|
31 |
|
32 |
|
33 | const cmd = {
|
34 | args: parsed.argv.remain,
|
35 | opts: parsed
|
36 | };
|
37 |
|
38 |
|
39 | const notifier = update({
|
40 | packageName: pkg.name,
|
41 | packageVersion: pkg.version
|
42 | });
|
43 |
|
44 | if (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 |
|
56 | if (typeof cmd.args[0] === 'undefined') {
|
57 | if (typeof cmd.opts.version === 'undefined') {
|
58 |
|
59 | nitro.help();
|
60 | } else {
|
61 |
|
62 | process.stdout.write('APEX Nitro version ' + pkg.version + '\n');
|
63 | }
|
64 | } else if (typeof nitro[cmd.args[0]] === 'undefined') {
|
65 |
|
66 |
|
67 | nitro.help();
|
68 | } else {
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | nitro[cmd.args[0]](cmd.args.slice(1), cmd.opts);
|
74 | }
|