Skip to content

Instantly share code, notes, and snippets.

@geta6
Last active October 28, 2015 02:17
Show Gist options
  • Save geta6/1863dbecfbf5d3e8bce1 to your computer and use it in GitHub Desktop.
Save geta6/1863dbecfbf5d3e8bce1 to your computer and use it in GitHub Desktop.
gulp.task('exec', async () => {
const exec = {
exec(command, options) {
return new Promise((resolve, reject) => {
cp.spawn(command, options, {stdio: 'inherit'}).on('error', reject).on('exit', resolve);
});
},
async local(commands) {
await this.exec(process.env.SHELL, ['-c', commands.join('&&')]);
},
async remote(commands) {
await this.exec('ssh', [process.env.REMOTE_HOST, commands.join('&&')]);
},
};
await exec.local([
'pwd',
'ls',
]);
await exec.remote([
'pwd',
'ls',
]);
});
gulp.task('exec', () => {
const exec = {
exec(command, options) {
return new Promise((resolve, reject) => {
cp.spawn(command, options, {stdio: 'inherit'}).on('error', reject).on('exit', resolve);
});
},
local(commands) {
return this.exec(process.env.SHELL, ['-c', commands.join('&&')]);
},
remote(commands) {
return this.exec('ssh', [process.env.REMOTE_HOST, commands.join('&&')]);
},
};
exec.local([
'pwd',
'ls',
]).then(() => {
return exec.remote([
'pwd',
'ls',
]);
}).catch(err => {
console.error(err.stack);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment