#!/usr/bin/env node const exec = require('child_process').exec; /** * Cross-platform command execution script with promise pipe. * If any part of pipe fail, the entire pipe will also fail. * * @param command string * @returns Promise */ const run = command => new Promise(resolve => { exec(command, (error, stdout) => { if (error) { console.error(error); process.exit(1); } console.log(stdout); resolve(stdout); }); }); (async () => { run('echo "Command 1"') .then(async () => run('echo "Command 2"')) .then(async () => run('echo "Command 3"')) .then(async () => run('echo "And so on..."')) .then(() => console.log('All commands runned')); })();