From ed2f523525f3e6e9b13fc67c07e01fb4c7aa163d Mon Sep 17 00:00:00 2001 From: Andrew Zakordonets Date: Fri, 30 Sep 2016 19:39:24 +0200 Subject: [PATCH] Beaufity output of eject.js script (#769) * Beaufity output of eject.js script * change formatting of the eject.js output and move colors to cyan * change message about file copy * add missing three dots to some statements in eject.js script * change color of "copying files" line and do not repeat copy path anymore in log * fix merge conflict * Remove yellow color from "Removing dependency" line * changing color to "Adding dependency" line * Add line that outputs which react script is getting replaced by similar node script * remove not used anymore colors * add console line about updating Jest configs * fix typo * change formatting of replacing script output in eject.js * remove "Writing package.json" file console output * make quotes cyan in "Replacing script" console output * update console log output for Jest, Babel, ESLint update and group them under one statement * Style nits --- packages/react-scripts/scripts/eject.js | 44 +++++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index d48fe6680ec..c1355337b4c 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -13,18 +13,20 @@ var path = require('path'); var prompt = require('react-dev-utils/prompt'); var rimrafSync = require('rimraf').sync; var spawnSync = require('cross-spawn').sync; +var chalk = require('chalk'); +var green = chalk.green; +var cyan = chalk.cyan; prompt( 'Are you sure you want to eject? This action is permanent.', false ).then(shouldEject => { if (!shouldEject) { - console.log('Close one! Eject aborted.'); + console.log(cyan('Close one! Eject aborted.')); process.exit(1); } console.log('Ejecting...'); - console.log(); var ownPath = path.join(__dirname, '..'); var appPath = path.join(ownPath, '..', '..'); @@ -59,8 +61,10 @@ prompt( fs.mkdirSync(path.join(appPath, 'config', 'jest')); fs.mkdirSync(path.join(appPath, 'scripts')); + console.log(); + console.log('Copying files to ' + cyan(appPath)); files.forEach(function(file) { - console.log('Copying ' + file + ' to ' + appPath); + console.log(' Copying ' + cyan(file)); var content = fs .readFileSync(path.join(ownPath, file), 'utf8') // Remove dead code from .js files on eject @@ -77,8 +81,9 @@ prompt( var babelConfig = JSON.parse(fs.readFileSync(path.join(ownPath, '.babelrc'), 'utf8')); var eslintConfig = JSON.parse(fs.readFileSync(path.join(ownPath, '.eslintrc'), 'utf8')); + console.log(cyan('Updating dependencies...')); var ownPackageName = ownPackage.name; - console.log('Removing dependency: ' + ownPackageName); + console.log(' Removing dependency: ' + cyan(ownPackageName)); delete appPackage.devDependencies[ownPackageName]; Object.keys(ownPackage.dependencies).forEach(function (key) { @@ -86,18 +91,27 @@ prompt( if (ownPackage.optionalDependencies[key]) { return; } - console.log('Adding dependency: ' + key); + console.log(' Adding dependency: ' + cyan(key)); appPackage.devDependencies[key] = ownPackage.dependencies[key]; }); - - console.log('Updating scripts'); + console.log(); + console.log(cyan('Updating scripts...')); delete appPackage.scripts['eject']; Object.keys(appPackage.scripts).forEach(function (key) { appPackage.scripts[key] = appPackage.scripts[key] .replace(/react-scripts (\w+)/g, 'node scripts/$1.js'); + console.log( + ' Replacing ' + + cyan('\"react-scripts ' + key + '\"') + + ' with ' + + cyan('\"' + appPackage.scripts[key] + '\"') + ); }); + console.log(); + console.log(cyan('Adding configuration to ') + 'package.json' + cyan('...')); // Add Jest config + console.log(' Adding ' + cyan('Jest') + ' configuration'); appPackage.jest = createJestConfig( filePath => path.join('', filePath), null, @@ -105,25 +119,27 @@ prompt( ); // Add Babel config + + console.log(' Adding ' + cyan('Babel') + ' preset'); appPackage.babel = babelConfig; // Add ESlint config + console.log(' Adding ' + cyan('ESLint') +' configuration'); appPackage.eslintConfig = eslintConfig; - console.log('Writing package.json'); fs.writeFileSync( path.join(appPath, 'package.json'), JSON.stringify(appPackage, null, 2) ); console.log(); - console.log('Running npm install...'); + console.log(cyan('Running npm install...')); rimrafSync(ownPath); spawnSync('npm', ['install'], {stdio: 'inherit'}); - console.log('Ejected successfully!'); + console.log(green('Ejected successfully!')); console.log(); - console.log('Please consider sharing why you ejected in this survey:'); - console.log(' http://goo.gl/forms/Bi6CZjk1EqsdelXk1'); - console.log(); -}); + console.log(green('Please consider sharing why you ejected in this survey:')); + console.log(green(' http://goo.gl/forms/Bi6CZjk1EqsdelXk1')); + console.log() +})