UNPKG

1.7 kBJavaScriptView Raw
1#! /usr/bin/env node
2/* eslint-disable no-console */
3
4'use strict'
5
6process.on('unhandledRejection', (err) => {
7 throw err
8})
9
10const updateNotifier = require('update-notifier')
11const chalk = require('chalk')
12const pkg = require('./package.json')
13
14updateNotifier({
15 pkg: pkg,
16 isGlobal: false
17}).notify()
18
19const cli = require('yargs')
20cli
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
47const 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