Created
January 24, 2022 18:58
-
-
Save felippe-regazio/2997254d4fcbc839842bc58df38c86d2 to your computer and use it in GitHub Desktop.
Revisions
-
felippe-regazio created this gist
Jan 24, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #!/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<String> */ 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')); })();