UNPKG

3.84 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const command_1 = require("@oclif/command");
4const config_1 = require("../lib/config");
5const debug_1 = require("../lib/debug");
6const packages_1 = require("../lib/packages");
7/**
8 * Runs a script in each package directory. This is different from `exec` in
9 * that scripts should be defined in .clarkrc and may be overridden on a
10 * per-package basis via npm scripts. npm scripts defined only in subpackage
11 * package.jsons can be run this way, but only scripts named in .clarkrc will
12 * populate the help output.
13 */
14class Run extends command_1.Command {
15 /**
16 * implementation
17 */
18 async run() {
19 const { flags, args, argv } = this.parse(Run);
20 flags.packageName = []
21 .concat(flags.packageName)
22 .concat(flags['package-name'])
23 .concat(flags.package)
24 .filter(Boolean);
25 if (!flags.packageName.length) {
26 delete flags.packageName;
27 }
28 flags.failFast = flags.failFast || flags['fail-fast'];
29 const options = Object.assign({}, flags, args);
30 const script = options.script;
31 const extra = argv.join(' ').replace(script, '');
32 console.error(argv.join(' '), '\n', extra);
33 const config = config_1.load();
34 const fallbackScript = config.scripts && config.scripts[script];
35 await packages_1.apply({
36 before: (packages) => debug_1.format `Running ${script} against ${packages.length} packages`,
37 beforeEach: (packageName) => debug_1.format `Running ${script} against ${packageName}`,
38 afterEach: (packageName, error) => {
39 if (error) {
40 return `${script} failed against ${packageName}`;
41 }
42 return `Ran ${script} against ${packageName}`;
43 },
44 after: (packages, errors) => {
45 if (errors.length) {
46 return debug_1.format `clark run failed to execute the following command against ${errors.length} packages\n> ${script}\n`;
47 }
48 return `Ran ${script} successfully against ${packages.length}`;
49 },
50 }, async (packageName) => {
51 await packages_1.execScript({
52 args: extra,
53 fallbackScript,
54 packageName,
55 scriptName: script,
56 });
57 }, options);
58 }
59}
60/**
61 * description
62 */
63Run.description = 'Runs a script in each package directory. This is different from `exec` in that scripts should be defined in .clarkrc and may be overridden on a per-package basis via npm scripts. npm scripts defined only in subpackage package.jsons can be run this way, but only scripts named in .clarkrc will populate the help output.';
64/**
65 * flags
66 */
67Run.flags = {
68 failFast: command_1.flags.boolean({
69 description: 'Fail as soon as a command fails, rather than running all to completion',
70 }),
71 'fail-fast': command_1.flags.boolean({
72 description: 'Alias of --failFast',
73 }),
74 packageName: command_1.flags.string({
75 char: 'p',
76 description: 'The package against which to run this command. May be specified more than once.',
77 multiple: true,
78 }),
79 package: command_1.flags.string({
80 description: 'alias of --packageName',
81 multiple: true,
82 }),
83 'package-name': command_1.flags.string({
84 description: 'alias of --packageName',
85 multiple: true,
86 }),
87 silent: command_1.flags.boolean({
88 char: 's',
89 description: 'Indicates nothing should be printed to the stdout',
90 }),
91};
92/**
93 * args
94 */
95Run.args = [{ name: 'script', required: true }];
96/**
97 * Disable strict mode
98 */
99Run.strict = false;
100exports.default = Run;
101//# sourceMappingURL=run.js.map
\No newline at end of file