2017-05-22 10:51:24 +00:00
|
|
|
/**
|
2018-02-17 02:24:55 +00:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
2017-05-22 10:51:24 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-10-31 10:44:59 +00:00
|
|
|
*
|
|
|
|
* @format
|
2017-05-22 10:51:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
const spawn = require('child_process').spawnSync;
|
|
|
|
const chalk = require('chalk');
|
|
|
|
|
|
|
|
module.exports = function runCommand(cmd, args, cwd) {
|
|
|
|
if (!cwd) {
|
|
|
|
cwd = __dirname;
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:44:59 +00:00
|
|
|
const displayArgs =
|
|
|
|
args.length > 25 ? args.slice(0, 25) + '...' : args.join(' ');
|
2018-02-13 14:16:55 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
2017-05-22 10:51:24 +00:00
|
|
|
console.log(chalk.dim('$ cd ' + cwd + `\n$ ${cmd} ${displayArgs}\n`));
|
|
|
|
const result = spawn(cmd, args, {
|
|
|
|
cwd,
|
|
|
|
stdio: 'inherit',
|
|
|
|
});
|
|
|
|
if (result.error || result.status !== 0) {
|
|
|
|
const message = 'Error running command.';
|
|
|
|
const error = new Error(message);
|
|
|
|
error.stack = message;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
};
|