1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.run = exports.cmd = exports.args = exports.description = exports.alias = exports.name = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var common_1 = require("../common");
|
6 | var listCommand = require("./ls.cmd");
|
7 | exports.name = 'run';
|
8 | exports.alias = 'r';
|
9 | exports.description = 'Runs the given command on all modules.';
|
10 | exports.args = {
|
11 | '<command>': 'The shell command to invoke.',
|
12 | '-i': 'Include ignored modules.',
|
13 | '-c': 'Run command concurrently against all modules. (Default: false).',
|
14 | };
|
15 | function cmd(args) {
|
16 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
17 | var cmd, options, includeIgnored, concurrent;
|
18 | return tslib_1.__generator(this, function (_a) {
|
19 | switch (_a.label) {
|
20 | case 0:
|
21 | cmd = (args && args.params && args.params.join(' ')) || '';
|
22 | options = (args && args.options) || {};
|
23 | includeIgnored = options.i || false;
|
24 | concurrent = options.c || false;
|
25 | return [4, run(cmd, { includeIgnored: includeIgnored, concurrent: concurrent })];
|
26 | case 1:
|
27 | _a.sent();
|
28 | return [2];
|
29 | }
|
30 | });
|
31 | });
|
32 | }
|
33 | exports.cmd = cmd;
|
34 | function run(cmd, options) {
|
35 | if (options === void 0) { options = {}; }
|
36 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
37 | var _a, includeIgnored, _b, concurrent, settings, modules, tasks, runner, error_1;
|
38 | var _this = this;
|
39 | return tslib_1.__generator(this, function (_c) {
|
40 | switch (_c.label) {
|
41 | case 0:
|
42 | _a = options.includeIgnored, includeIgnored = _a === void 0 ? false : _a, _b = options.concurrent, concurrent = _b === void 0 ? false : _b;
|
43 | if (!cmd) {
|
44 | common_1.log.info.red("No command specified.\n");
|
45 | return [2];
|
46 | }
|
47 | return [4, common_1.loadSettings()];
|
48 | case 1:
|
49 | settings = _c.sent();
|
50 | if (!settings) {
|
51 | common_1.log.warn.yellow(common_1.constants.CONFIG_NOT_FOUND_ERROR);
|
52 | return [2];
|
53 | }
|
54 | modules = options.modules || settings.modules.filter(function (pkg) { return common_1.filter.includeIgnored(pkg, includeIgnored); });
|
55 | if (common_1.value.defaultValue(options.printStatus, true)) {
|
56 | common_1.log.info.magenta("\nRun " + common_1.log.cyan(cmd) + " on:");
|
57 | listCommand.printTable(modules, { showPath: true });
|
58 | common_1.log.info();
|
59 | }
|
60 | tasks = modules.map(function (pkg) {
|
61 | return {
|
62 | title: common_1.log.cyan(pkg.name) + " " + common_1.log.magenta(cmd),
|
63 | task: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
64 | var command;
|
65 | return tslib_1.__generator(this, function (_a) {
|
66 | command = "cd " + pkg.dir + " && " + cmd;
|
67 | return [2, common_1.exec.cmd.run(command, { silent: true })];
|
68 | });
|
69 | }); },
|
70 | };
|
71 | });
|
72 | runner = common_1.listr(tasks, { concurrent: concurrent, exitOnError: false });
|
73 | _c.label = 2;
|
74 | case 2:
|
75 | _c.trys.push([2, 4, , 5]);
|
76 | return [4, runner.run()];
|
77 | case 3:
|
78 | _c.sent();
|
79 | return [3, 5];
|
80 | case 4:
|
81 | error_1 = _c.sent();
|
82 | return [3, 5];
|
83 | case 5:
|
84 | common_1.log.info();
|
85 | return [2];
|
86 | }
|
87 | });
|
88 | });
|
89 | }
|
90 | exports.run = run;
|