UNPKG

3.34 kBJavaScriptView Raw
1"use strict";
2/* eslint-disable no-console */
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"));
11const checkVersion_1 = __importDefault(require("./checkVersion"));
12const parseSpecialArgv_1 = __importDefault(require("./parseSpecialArgv"));
13// 0 node, 1 beemo, 2 command
14const { main, parallel } = parseSpecialArgv_1.default(process.argv.slice(2));
15// Initialize
16const binName = path_1.default.basename(process.argv[1]);
17const beemo = new core_1.default(main.slice(1), binName);
18const { tool } = beemo;
19const app = yargs_1.default(main); // TEMP as yargs types are broken
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
26tool.getPlugins('driver').forEach(driver => {
27 const { command, metadata } = driver;
28 app.command(driver.name, metadata.description || tool.msg('app:run', { title: metadata.title }), Object.assign({}, command, { concurrency: {
29 description: tool.msg('app:cliOptionConcurrency'),
30 number: true,
31 }, live: {
32 boolean: true,
33 default: false,
34 description: tool.msg('app:cliOptionLive'),
35 }, priority: {
36 boolean: true,
37 description: tool.msg('app:cliOptionPriority'),
38 }, workspaces: {
39 description: tool.msg('app:cliOptionWorkspaces'),
40 string: true,
41 } }), (args) => beemo.executeDriver(args, driver.name, parallel));
42});
43// Add Beemo commands
44app.command(['create-config [names..]', 'config [names..]'], tool.msg('app:cliCommandConfig'), {}, (args) => beemo.createConfigFiles(args, args.names));
45app.command(['run-script <name>', 'run <name>'], tool.msg('app:cliCommandRunScript'), {
46 concurrency: {
47 description: tool.msg('app:cliOptionConcurrency'),
48 number: true,
49 },
50 priority: {
51 boolean: false,
52 description: tool.msg('app:cliOptionPriority'),
53 },
54 workspaces: {
55 description: tool.msg('app:cliOptionWorkspaces'),
56 string: true,
57 },
58}, (args) => beemo.executeScript(args, args.name));
59app.command('scaffold <generator> <action>', tool.msg('app:cliCommandScaffold'), {
60 dry: {
61 boolean: true,
62 default: false,
63 description: tool.msg('app:cliOptionDryRun'),
64 },
65}, (args) => beemo.scaffold(args, args.generator, args.action));
66app.command('*', false, {}, () => {
67 console.error(chalk_1.default.red(tool.msg('errors:cliNoCommand')));
68});
69// Run application
70// eslint-disable-next-line no-unused-expressions
71app
72 .usage(`${binName} <command> [args..]`)
73 .epilogue(
74// prettier-ignore
75chalk_1.default.gray([
76 tool.msg('app:cliEpilogue', { manualURL }),
77 tool.msg('app:poweredBy', { version: checkVersion_1.default })
78].join('\n')))
79 .demandCommand(1, chalk_1.default.red(tool.msg('errors:cliNoCommand')))
80 .showHelpOnFail(true)
81 .help().argv;