1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const command_1 = require("@oclif/command");
|
4 | const config_1 = require("../lib/config");
|
5 | const debug_1 = require("../lib/debug");
|
6 | const packages_1 = require("../lib/packages");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | class Run extends command_1.Command {
|
15 | |
16 |
|
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 |
|
62 |
|
63 | Run.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 |
|
66 |
|
67 | Run.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 |
|
94 |
|
95 | Run.args = [{ name: 'script', required: true }];
|
96 |
|
97 |
|
98 |
|
99 | Run.strict = false;
|
100 | exports.default = Run;
|
101 |
|
\ | No newline at end of file |