From 658832c3a2f64bfec348a1c6e06896ab4a931e55 Mon Sep 17 00:00:00 2001 From: wangyi <724003548@qq.com> Date: Tue, 30 Jul 2019 09:09:42 +0800 Subject: [PATCH] fix(cli): remove promise in install --- packages/cli/create-antd-site.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/cli/create-antd-site.js b/packages/cli/create-antd-site.js index fa0dc05..b3b585d 100644 --- a/packages/cli/create-antd-site.js +++ b/packages/cli/create-antd-site.js @@ -29,7 +29,7 @@ const program = new commander.Command(packageJson.name) .version(packageJson.version) .arguments('[project-directory]') .usage(`${chalk.green('[project-directory]')}`) - .action((name) => { + .action(name => { projectName = name; }) .option('--use-npm') @@ -39,7 +39,7 @@ createApp(projectName, program.useNpm); function printValidationResults(results) { if (typeof results !== 'undefined') { - results.forEach((error) => { + results.forEach(error => { console.error(chalk.red(` * ${error}`)); }); } @@ -69,7 +69,7 @@ function checkAppName(appName) { `Due to the way npm works, the following names are not allowed:\n\n` ) + chalk.hex('#29CDFF')( - dependencies.map((depName) => ` ${depName}`).join('\n') + dependencies.map(depName => ` ${depName}`).join('\n') ) + chalk.red('\n\nPlease choose a different project name.') ); @@ -87,14 +87,14 @@ function shouldUseYarn() { } function executeNodeScript({ cwd, initScriptPath }, data, source) { - return new Promise((resolve) => { + return new Promise(resolve => { const child = spawn( process.execPath, ['-e', source, '--', JSON.stringify(data), initScriptPath], { cwd, stdio: 'inherit' } ); - child.on('close', (code) => { + child.on('close', code => { if (code !== 0) { return; } @@ -121,13 +121,12 @@ function isSafeToCreateProjectIn(root, name) { const conflicts = fs .readdirSync(root) - .filter((file) => !validFiles.includes(file)) + .filter(file => !validFiles.includes(file)) // IntelliJ IDEA creates module files before CRA is launched - .filter((file) => !/\.iml$/.test(file)) + .filter(file => !/\.iml$/.test(file)) // Don't treat log files from previous installation as conflicts .filter( - (file) => - !errorLogFilePatterns.some((pattern) => file.indexOf(pattern) === 0) + file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0) ); if (conflicts.length > 0) { @@ -148,8 +147,8 @@ function isSafeToCreateProjectIn(root, name) { // Remove any remnant files from a previous installation const currentFiles = fs.readdirSync(path.join(root)); - currentFiles.forEach((file) => { - errorLogFilePatterns.forEach((errorLogFilePattern) => { + currentFiles.forEach(file => { + errorLogFilePatterns.forEach(errorLogFilePattern => { // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files if (file.indexOf(errorLogFilePattern) === 0) { fs.removeSync(path.join(root, file)); @@ -254,7 +253,6 @@ function run(root, dependencies, useYarn, appName, originalDirectory) { function install(root, useYarn, dependencies) { return new Promise((resolve, reject) => { - return resolve(); let command; let args; if (useYarn) { @@ -282,7 +280,7 @@ function install(root, useYarn, dependencies) { } const child = spawn(command, args, { stdio: 'inherit' }); - child.on('close', (code) => { + child.on('close', code => { if (code !== 0) { reject({ command: `${command} ${args.join(' ')}`