1 | "use strict";
|
2 |
|
3 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
4 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
5 | };
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | const path_1 = __importDefault(require("path"));
|
8 | const chalk_1 = __importDefault(require("chalk"));
|
9 | const yargs_1 = __importDefault(require("yargs"));
|
10 | const core_1 = __importDefault(require("@beemo/core"));
|
11 |
|
12 | const package_json_1 = __importDefault(require("@beemo/core/package.json"));
|
13 | const parseSpecialArgv_1 = __importDefault(require("./parseSpecialArgv"));
|
14 |
|
15 | const { main, parallel } = parseSpecialArgv_1.default(process.argv.slice(2));
|
16 |
|
17 | const binName = path_1.default.basename(process.argv[1]);
|
18 | const beemo = new core_1.default(main.slice(1), binName);
|
19 | const app = yargs_1.default(main);
|
20 | const manualURL = process.env.BEEMO_MANUAL_URL || 'https://milesj.gitbook.io/beemo';
|
21 |
|
22 | beemo.bootstrapConfigModule();
|
23 |
|
24 | beemo.bootstrapCLI(app);
|
25 |
|
26 | beemo.getPlugins('driver').forEach(driver => {
|
27 | const { command, metadata } = driver;
|
28 | app.command(driver.name, metadata.description || beemo.msg('app:run', { title: metadata.title }), cmd => {
|
29 | Object.keys(command).forEach(key => {
|
30 | cmd.option(key, command[key]);
|
31 | });
|
32 | return cmd
|
33 | .option('concurrency', {
|
34 | default: 0,
|
35 | description: beemo.msg('app:cliOptionConcurrency'),
|
36 | number: true,
|
37 | })
|
38 | .option('graph', {
|
39 | boolean: true,
|
40 | default: true,
|
41 | description: beemo.msg('app:cliOptionGraph'),
|
42 | })
|
43 | .option('stdio', {
|
44 | choices: ['buffer', 'stream', 'inherit'],
|
45 | default: 'buffer',
|
46 | description: beemo.msg('app:cliOptionStdio'),
|
47 | string: true,
|
48 | })
|
49 | .option('workspaces', {
|
50 | default: '',
|
51 | description: beemo.msg('app:cliOptionWorkspaces'),
|
52 | string: true,
|
53 | });
|
54 | }, args => beemo.runDriver(args, driver.name, parallel));
|
55 | });
|
56 |
|
57 | app.command(['create-config [names..]', 'config [names..]'], beemo.msg('app:cliCommandConfig'), cmd => cmd.positional('names', {
|
58 | default: [],
|
59 | description: beemo.msg('app:cliArgConfigNames'),
|
60 | type: 'string',
|
61 | }), args => beemo.createConfigFiles(args, args.names));
|
62 | app.command(['run-script <name>', 'run <name>'], beemo.msg('app:cliCommandRunScript'), cmd => cmd
|
63 | .positional('name', {
|
64 | default: '',
|
65 | description: beemo.msg('app:cliArgScriptName'),
|
66 | type: 'string',
|
67 | })
|
68 | .option('concurrency', {
|
69 | default: 0,
|
70 | description: beemo.msg('app:cliOptionConcurrency'),
|
71 | number: true,
|
72 | })
|
73 | .option('graph', {
|
74 | boolean: true,
|
75 | default: false,
|
76 | description: beemo.msg('app:cliOptionGraph'),
|
77 | })
|
78 | .option('stdio', {
|
79 | choices: ['buffer', 'stream', 'inherit'],
|
80 | default: 'buffer',
|
81 | description: beemo.msg('app:cliOptionStdio'),
|
82 | string: true,
|
83 | })
|
84 | .option('workspaces', {
|
85 | default: '',
|
86 | description: beemo.msg('app:cliOptionWorkspaces'),
|
87 | string: true,
|
88 | }), args => beemo.runScript(args, args.name));
|
89 | app.command('scaffold <generator> <action> [name]', beemo.msg('app:cliCommandScaffold'), cmd => cmd
|
90 | .positional('generator', {
|
91 | default: '',
|
92 | description: beemo.msg('app:cliArgGenerator'),
|
93 | type: 'string',
|
94 | })
|
95 | .positional('action', {
|
96 | default: '',
|
97 | description: beemo.msg('app:cliArgGeneratorAction'),
|
98 | type: 'string',
|
99 | })
|
100 | .positional('name', {
|
101 | default: '',
|
102 | description: beemo.msg('app:cliArgGeneratorName'),
|
103 | type: 'string',
|
104 | })
|
105 | .option('dry', {
|
106 | boolean: true,
|
107 | default: false,
|
108 | description: beemo.msg('app:cliOptionDryRun'),
|
109 | }), args => beemo.scaffold(args, args.generator, args.action, args.name));
|
110 | app.command('*', false, {}, () => {
|
111 | console.error(chalk_1.default.red(beemo.msg('errors:cliNoCommand')));
|
112 | });
|
113 |
|
114 |
|
115 | app
|
116 | .usage(`${binName} <command> [args..]`)
|
117 | .epilogue(
|
118 |
|
119 | chalk_1.default.gray([
|
120 | beemo.msg('app:cliEpilogue', { manualURL }),
|
121 | beemo.msg('app:poweredBy', { version: package_json_1.default.version })
|
122 | ].join('\n')))
|
123 | .demandCommand(1, chalk_1.default.red(beemo.msg('errors:cliNoCommand')))
|
124 | .showHelpOnFail(true)
|
125 | .help().argv;
|