Skip to content

Instantly share code, notes, and snippets.

@sebald
Last active November 4, 2016 13:34
Show Gist options
  • Save sebald/60f6891f1fdcd4eab6bdf3d7a64f72f4 to your computer and use it in GitHub Desktop.
Save sebald/60f6891f1fdcd4eab6bdf3d7a64f72f4 to your computer and use it in GitHub Desktop.
No graceful error? :(
.then(([{cmd, args}, dependencies]) => {
process.chdir(dir);
return new Promise((resolve, reject) => {
const spinner = ora(chalk.dim('Installing dependencies. This may take a while...')).start();
const stdio = verbose ? 'inherit' : [process.stdin, 'ignore', 'ignore'];
const child = spawn(cmd, args.concat(dependencies), { stdio });
child.on('error', err => reject(err));
child.on('exit', code => {
if (code > 0) {
spinner.text = 'Installation failed!';
spinner.fail();
return;
}
spinner.text = 'Installation complete!';
spinner.succeed();
resolve();
})
});
});
.then(([{cmd, args}, dependencies]) => {
process.chdir(dir);
const spinner = ora(chalk.dim('Installing dependencies. This may take a while...')).start();
const child = spawn(cmd, args.concat(dependencies))
// We have to do a nested catch, so we don't lose
// reference to the `spinner`.
.catch(err => {
// Just forward, we only want to stop the spinner.
spinner.text = 'Installation failed!';
spinner.fail();
return Promise.reject(err);
});
if(verbose) {
child.stdout.pipe(process.stdout);
}
return Promise.all([spinner, child]);
})
.then(([spinner, result]) => {
spinner.text = 'Installation complete!';
spinner.succeed();
return result;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment