UNPKG

4.51 kBJavaScriptView Raw
1"use strict";
2/* eslint-disable no-console, @typescript-eslint/no-misused-promises */
3var __importDefault = (this && this.__importDefault) || function (mod) {
4 return (mod && mod.__esModule) ? mod : { "default": mod };
5};
6Object.defineProperty(exports, "__esModule", { value: true });
7const path_1 = __importDefault(require("path"));
8const chalk_1 = __importDefault(require("chalk"));
9const yargs_1 = __importDefault(require("yargs"));
10const core_1 = __importDefault(require("@beemo/core"));
11// @ts-ignore
12const package_json_1 = __importDefault(require("@beemo/core/package.json"));
13const parseSpecialArgv_1 = __importDefault(require("./parseSpecialArgv"));
14// 0 node, 1 beemo, 2 command
15const { main, parallel } = parseSpecialArgv_1.default(process.argv.slice(2));
16// Initialize
17const binName = path_1.default.basename(process.argv[1]);
18const beemo = new core_1.default(main.slice(1), binName);
19const app = yargs_1.default(main);
20const manualURL = process.env.BEEMO_MANUAL_URL || 'https://milesj.gitbook.io/beemo';
21// Bootstrap the module
22beemo.bootstrapConfigModule();
23// Register global options
24beemo.bootstrapCLI(app);
25// Add a command for each driver
26beemo.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// Add Beemo commands
57app.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));
62app.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));
89app.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));
110app.command('*', false, {}, () => {
111 console.error(chalk_1.default.red(beemo.msg('errors:cliNoCommand')));
112});
113// Run application
114// eslint-disable-next-line no-unused-expressions
115app
116 .usage(`${binName} <command> [args..]`)
117 .epilogue(
118// prettier-ignore
119chalk_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;