Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beaufity output of eject.js script #769

Merged
merged 18 commits into from
Sep 30, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change formatting of the eject.js output and move colors to cyan
  • Loading branch information
azakordonets committed Sep 27, 2016
commit 822ad8cf97eb2e6abffca6a216042d8d75d083af
27 changes: 15 additions & 12 deletions packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ var rimrafSync = require('rimraf').sync;
var spawnSync = require('cross-spawn').sync;
var chalk = require('chalk');
var green = chalk.green;
var yellowUnderline = chalk.yellow.underline
var cyan = chalk.cyan;
var red = chalk.red;

prompt(
'Are you sure you want to eject? This action is permanent.',
false
).then(shouldEject => {
if (!shouldEject) {
console.log(green('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, '..', '..');
Expand Down Expand Up @@ -64,8 +64,10 @@ prompt(
fs.mkdirSync(path.join(appPath, 'config', 'jest'));
fs.mkdirSync(path.join(appPath, 'scripts'));

console.log();
console.log(cyan('Adding necessary files'));
files.forEach(function(file) {
console.log(green('Copying ') + yellowUnderline(file) + ' to ' + yellowUnderline(appPath));
console.log(cyan(' Copying ') + file+ ' to ' + appPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try making file and appPath cyan instead of Copying?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the output, it prints the same giant appPath on every single line.

Suggestion: could we put this path in the header instead?

Copying files to /Users/.../tempApp ...
  Copying .babelrc
  Copying .eslintrc

var content = fs
.readFileSync(path.join(ownPath, file), 'utf8')
// Remove dead code from .js files on eject
Expand All @@ -79,21 +81,21 @@ prompt(

var ownPackage = require(path.join(ownPath, 'package.json'));
var appPackage = require(path.join(appPath, 'package.json'));

console.log(cyan('Managing dependencies'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s call this Updating dependencies...

var ownPackageName = ownPackage.name;
console.log('Removing dependency: ' + yellowUnderline(ownPackageName));
console.log(red(' Removing dependency: ') + ownPackageName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s use yellow here so it doesn’t feel like an error

delete appPackage.devDependencies[ownPackageName];

Object.keys(ownPackage.dependencies).forEach(function (key) {
// For some reason optionalDependencies end up in dependencies after install
if (ownPackage.optionalDependencies[key]) {
return;
}
console.log(green('\tAdding dependency: ') + yellowUnderline(key));
console.log(cyan(' Adding dependency: ') + key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar, let’s make dependency name cyan (or yellow) instead of the label.

appPackage.devDependencies[key] = ownPackage.dependencies[key];
});

console.log('Updating scripts');
console.log();
console.log(cyan('Updating scripts'));
Copy link
Contributor

@gaearon gaearon Sep 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let’s add ...

delete appPackage.scripts['eject'];
Object.keys(appPackage.scripts).forEach(function (key) {
appPackage.scripts[key] = appPackage.scripts[key]
Copy link
Contributor

@gaearon gaearon Sep 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s print each step here?
For example:

  Replacing "react-scripts start" with "node scripts/start.js"

Expand All @@ -110,20 +112,21 @@ prompt(
true
);

console.log(green('Writing ') + yellowUnderline('package.json'));
console.log();
console.log(cyan('Writing ') + 'package.json');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

fs.writeFileSync(
path.join(appPath, 'package.json'),
JSON.stringify(appPackage, null, 2)
);
console.log();

console.log(green('Running ') + yellowUnderline('npm install...'));
console.log(cyan('Running npm install...'));
rimrafSync(ownPath);
spawnSync('npm', ['install'], {stdio: 'inherit'});
console.log(green('Ejected successfully!'));
console.log();

console.log(green('Please consider sharing why you ejected in this survey:'));
console.log('\t' + yellowUnderline('http:https://goo.gl/forms/Bi6CZjk1EqsdelXk1'));
console.log(green(' http:https://goo.gl/forms/Bi6CZjk1EqsdelXk1'));
console.log()
})