1// @ts-check 2const cp = require("child_process"); 3/** 4 * 5 * @param {[string, string[]][]} tasks 6 * @param {cp.SpawnSyncOptions} opts 7 */ 8function runSequence(tasks, opts = { timeout: 100000, shell: true }) { 9 let lastResult; 10 for (const task of tasks) { 11 console.log(`${task[0]} ${task[1].join(" ")}`); 12 const result = cp.spawnSync(task[0], task[1], opts); 13 if (result.status !== 0) throw new Error(`${task[0]} ${task[1].join(" ")} failed: ${result.stderr && "stderr: " + result.stderr.toString()}${result.stdout && "\nstdout: " + result.stdout.toString()}`); 14 console.log(result.stdout && result.stdout.toString()); 15 lastResult = result; 16 } 17 return lastResult && lastResult.stdout && lastResult.stdout.toString(); 18} 19 20exports.runSequence = runSequence;