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', ]); });