1 | #! /usr/bin/env node
|
2 |
|
3 |
|
4 | 'use strict'
|
5 |
|
6 | process.on('unhandledRejection', (err) => {
|
7 | throw err
|
8 | })
|
9 |
|
10 | const updateNotifier = require('update-notifier')
|
11 | const chalk = require('chalk')
|
12 | const pkg = require('./package.json')
|
13 |
|
14 | updateNotifier({
|
15 | pkg: pkg,
|
16 | isGlobal: false
|
17 | }).notify()
|
18 |
|
19 | const cli = require('yargs')
|
20 | cli
|
21 | .scriptName('aegir')
|
22 | .env('AEGIR')
|
23 | .usage('Usage: $0 <command> [options]')
|
24 | .example('$0 build', 'Runs the build command to bundle JS code for the browser.')
|
25 | .example('npx $0 build', 'Can be used with `npx` to use a local version')
|
26 | .example('$0 test -t webworker -- --browsers Firefox', 'If the command supports `--` can be used to forward options to the underlying tool.')
|
27 | .example('npm test -- -- --browsers Firefox', 'If `npm test` translates to `aegir test -t browser` and you want to forward options you need to use `-- --` instead.')
|
28 | .epilog('Use `$0 <command> --help` to learn more about each command.')
|
29 | .commandDir('cmds')
|
30 | .demandCommand(1, 'You need at least one command.')
|
31 | .option('D', {
|
32 | desc: 'Show debug output.',
|
33 | type: 'boolean',
|
34 | default: false,
|
35 | alias: 'debug'
|
36 | })
|
37 | .help()
|
38 | .alias('h', 'help')
|
39 | .alias('v', 'version')
|
40 | .group(['help', 'version', 'debug'], 'Global Options:')
|
41 | .wrap(cli.terminalWidth())
|
42 | .parserConfiguration({ 'populate--': true })
|
43 | .recommendCommands()
|
44 | .completion()
|
45 | .strictCommands()
|
46 |
|
47 | const args = cli.fail((msg, err, yargs) => {
|
48 | if (msg) {
|
49 | yargs.showHelp()
|
50 | console.error(chalk.red(msg))
|
51 | }
|
52 |
|
53 | if (err) {
|
54 | if (args.debug) {
|
55 | console.error('\n', err)
|
56 | } else {
|
57 | console.error('\n', chalk.red(err.message))
|
58 | }
|
59 | }
|
60 |
|
61 | process.exit(1)
|
62 | })
|
63 | .argv
|