1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const command_1 = require("@oclif/command");
|
4 | const debug_1 = require("../lib/debug");
|
5 | const packages_1 = require("../lib/packages");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | class Exec extends command_1.Command {
|
11 | |
12 |
|
13 |
|
14 | async run() {
|
15 | const { args, argv, flags } = this.parse(Exec);
|
16 | flags.packageName = []
|
17 | .concat(flags.packageName)
|
18 | .concat(flags['package-name'])
|
19 | .concat(flags.package)
|
20 | .filter(Boolean);
|
21 | if (!flags.packageName.length) {
|
22 | delete flags.packageName;
|
23 | }
|
24 | flags.failFast = flags.failFast || flags['fail-fast'];
|
25 | const options = Object.assign({}, flags, args);
|
26 | const command = argv.join(' ');
|
27 | await packages_1.apply({
|
28 | before: (packages) => debug_1.format `Running ${command} against ${packages.length} packages`,
|
29 | beforeEach: (packageName) => debug_1.format `Running ${command} against ${packageName}`,
|
30 | afterEach: (packageName, error) => {
|
31 | if (error) {
|
32 | return `${command} failed against ${packageName}`;
|
33 | }
|
34 | return `Ran ${command} against ${packageName}`;
|
35 | },
|
36 | after: (packages, errors) => {
|
37 | if (errors.length) {
|
38 | return debug_1.format `clark exec failed to execute the following command against ${errors.length} packages\n> ${command}\n`;
|
39 | }
|
40 | return `Ran ${command} successfully against ${packages.length}`;
|
41 | },
|
42 | }, async (packageName) => {
|
43 | await packages_1.exec(command, packageName);
|
44 | }, options);
|
45 | }
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 | Exec.description = 'Execute a command in each package directory. Note: commands with spaces and pipes are supported, but must be wrapped in quotes.';
|
51 |
|
52 |
|
53 |
|
54 | Exec.flags = {
|
55 | failFast: command_1.flags.boolean({
|
56 | description: 'Fail as soon as a command fails, rather than running all to completion',
|
57 | }),
|
58 | 'fail-fast': command_1.flags.boolean({
|
59 | description: 'Alias of --failFast',
|
60 | }),
|
61 | packageName: command_1.flags.string({
|
62 | char: 'p',
|
63 | description: 'The package against which to run this command. May be specified more than once.',
|
64 | multiple: true,
|
65 | }),
|
66 | package: command_1.flags.string({
|
67 | description: 'alias of --packageName',
|
68 | multiple: true,
|
69 | }),
|
70 | 'package-name': command_1.flags.string({
|
71 | description: 'alias of --packageName',
|
72 | multiple: true,
|
73 | }),
|
74 | silent: command_1.flags.boolean({
|
75 | char: 's',
|
76 | description: 'Indicates nothing should be printed to the stdout',
|
77 | }),
|
78 | };
|
79 |
|
80 |
|
81 |
|
82 | Exec.args = [
|
83 | {
|
84 | name: 'command',
|
85 | required: true,
|
86 | },
|
87 | ];
|
88 | exports.default = Exec;
|
89 |
|
\ | No newline at end of file |