mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Pass args as an array
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
const chalk = require('chalk');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const runCommand = require('./runCommand');
|
||||
const execFileSync = require('child_process').execFileSync;
|
||||
|
||||
const shouldWrite = process.argv[2] === 'write';
|
||||
const isWindows = process.platform === 'win32';
|
||||
@@ -36,6 +36,12 @@ const config = {
|
||||
},
|
||||
};
|
||||
|
||||
function exec(command, args) {
|
||||
console.log('> ' + [command].concat(args).join(' '));
|
||||
var options = {};
|
||||
return execFileSync(command, args, options).toString();
|
||||
}
|
||||
|
||||
Object.keys(config).forEach(key => {
|
||||
const patterns = config[key].patterns;
|
||||
const options = config[key].options;
|
||||
@@ -49,14 +55,14 @@ Object.keys(config).forEach(key => {
|
||||
const args = Object.keys(defaultOptions).map(
|
||||
k => `--${k}=${(options && options[k]) || defaultOptions[k]}`
|
||||
);
|
||||
args.push(`--${shouldWrite ? 'write' : 'l'} {${files.join(' ')}}`);
|
||||
args.push(`--${shouldWrite ? 'write' : 'l'}`);
|
||||
|
||||
try {
|
||||
runCommand(prettierCmd, args.join(' '), path.resolve(__dirname, '../..'));
|
||||
exec(prettierCmd, [...args, ...files]);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
if (!shouldWrite) {
|
||||
console.log(
|
||||
'\n' +
|
||||
chalk.red(
|
||||
` This project uses prettier to format all JavaScript code.\n`
|
||||
) +
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const chalk = require('chalk');
|
||||
const spawn = require('child_process').spawnSync;
|
||||
|
||||
module.exports = function runCommand(cmd, args, cwd) {
|
||||
if (!cwd) {
|
||||
cwd = __dirname;
|
||||
}
|
||||
|
||||
const callArgs = args.split(' ');
|
||||
console.log(
|
||||
chalk.dim('$ cd ' + cwd) +
|
||||
'\n' +
|
||||
chalk.dim(
|
||||
' $ ' +
|
||||
cmd +
|
||||
' ' +
|
||||
(args.length > 1000 ? args.slice(0, 1000) + '...' : args)
|
||||
) +
|
||||
'\n'
|
||||
);
|
||||
const result = spawn(cmd, callArgs, {
|
||||
cwd,
|
||||
stdio: 'inherit',
|
||||
});
|
||||
if (result.error || result.status !== 0) {
|
||||
const message = 'Error running command.';
|
||||
const error = new Error(message);
|
||||
error.stack = message;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user