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 | const { config } = require('./src/config/user')
|
21 | cli
|
22 | .scriptName('aegir')
|
23 | .env('AEGIR')
|
24 | .usage('Usage: $0 <command> [options]')
|
25 | .example('$0 build', 'Runs the build command to bundle JS code for the browser.')
|
26 | .example('npx $0 build', 'Can be used with `npx` to use a local version')
|
27 | .example('$0 test -t webworker -- --browsers Firefox', 'If the command supports `--` can be used to forward options to the underlying tool.')
|
28 | .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.')
|
29 | .epilog('Use `$0 <command> --help` to learn more about each command.')
|
30 | .middleware((yargs) => {
|
31 | yargs.config = config()
|
32 | })
|
33 | .commandDir('cmds')
|
34 | .help()
|
35 | .alias('help', 'h')
|
36 | .alias('version', 'v')
|
37 | .option('debug', {
|
38 | desc: 'Show debug output.',
|
39 | type: 'boolean',
|
40 | default: false,
|
41 | alias: 'd'
|
42 | })
|
43 |
|
44 | .options('node', {
|
45 | type: 'boolean',
|
46 | describe: 'Flag to control if bundler should inject node globals or built-ins.',
|
47 | default: false
|
48 | })
|
49 | .options('ts', {
|
50 | type: 'boolean',
|
51 | describe: 'Enable support for Typescript',
|
52 | default: false
|
53 | })
|
54 | .group(['help', 'version', 'debug', 'node', 'ts'], 'Global Options:')
|
55 | .demandCommand(1, 'You need at least one command.')
|
56 | .wrap(cli.terminalWidth())
|
57 | .parserConfiguration({ 'populate--': true })
|
58 | .recommendCommands()
|
59 | .completion()
|
60 | .strictCommands()
|
61 |
|
62 | const args = cli.fail((msg, err, yargs) => {
|
63 | if (msg) {
|
64 | yargs.showHelp()
|
65 | console.error(chalk.red(msg))
|
66 | }
|
67 |
|
68 | if (err) {
|
69 | if (args.debug) {
|
70 | console.error('\n', err)
|
71 | } else {
|
72 | console.error(chalk.red(err.message))
|
73 | }
|
74 | }
|
75 |
|
76 | process.exit(1)
|
77 | })
|
78 | .argv
|