UNPKG

sda

Version:

Software development assistant

65 lines 2.65 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const asyncExecuteCommands_1 = __importDefault(require("../command/asyncExecuteCommands")); const getCommands_1 = __importDefault(require("../command/getCommands")); const syncExecuteCommands_1 = __importDefault(require("../command/syncExecuteCommands")); const getEnvironment_1 = require("../getEnvironment"); const Log_1 = __importDefault(require("../Log")); /** * Executes all commands from the execution config. * If an environment is passed, it executes the commands in that environment instead of the one from the EC. */ function runCommands(ec) { return ec.runInAllEnvironments ? runInAllEnvironments(ec) : syncRunCommandsInEnv(ec, ec.env); } exports.default = runCommands; /** Executes the same commands on all environments */ function runInAllEnvironments(ec) { const envs = getEnvironment_1.getAllEnvironments(ec.config); const parallelRuns = Math.max(ec.parallelOperations, 1); if (parallelRuns > 1) { lodash_1.times(parallelRuns, () => asyncStartEnvironmentRun(envs, ec)); } else { // With one parallel run, we can synchronously, so we get live console updates syncRunEnvironments(envs, ec); } } async function asyncStartEnvironmentRun(envs, ec) { if (envs.length === 0) { return; } const env = envs.shift(); try { Log_1.default.log(`Environment "${env.id}"`); await asyncRunCommandsInEnv(ec, env); } catch (error) { Log_1.default.error(`Failed to run in environment "${env.id}". Inner error: ${error.message}`); } return asyncStartEnvironmentRun(envs, ec); } async function asyncRunCommandsInEnv(ec, env) { const commands = getCommands_1.default(env, ec.commands, ec.params); return asyncExecuteCommands_1.default(commands, env, ec); } function syncRunEnvironments(envs, ec) { envs.forEach((env) => { try { Log_1.default.log(`Environment "${env.id}"`); syncRunCommandsInEnv(ec, env); } catch (error) { Log_1.default.error(`Failed to run in environment "${env.id}". Inner error: ${error.message}`); } }); } function syncRunCommandsInEnv(ec, env) { const commands = getCommands_1.default(env, ec.commands, ec.params); return syncExecuteCommands_1.default(commands, env, ec); } //# sourceMappingURL=runCommands.js.map