Revision 8d7fd2e69199e6632a4132ce630832f0ccbdee0b authored by Wesley Wigham on 27 September 2019, 19:06:05 UTC, committed by GitHub on 27 September 2019, 19:06:05 UTC
1 parent a34fdb2
Raw File
run-sequence.js
// @ts-check
const cp = require("child_process");
/**
 * 
 * @param {[string, string[]][]} tasks
 * @param {cp.SpawnSyncOptions} opts
 */
function runSequence(tasks, opts = { timeout: 100000, shell: true }) {
    let lastResult;
    for (const task of tasks) {
        console.log(`${task[0]} ${task[1].join(" ")}`);
        const result = cp.spawnSync(task[0], task[1], opts);
        if (result.status !== 0) throw new Error(`${task[0]} ${task[1].join(" ")} failed: ${result.stderr && result.stderr.toString()}`);
        console.log(result.stdout && result.stdout.toString());
        lastResult = result;
    }
    return lastResult && lastResult.stdout && lastResult.stdout.toString();
}

exports.runSequence = runSequence;
back to top