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

Use most recent React version #477

Merged
merged 5 commits into from
Aug 25, 2016
Merged
Changes from 2 commits
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
35 changes: 18 additions & 17 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@
var fs = require('fs-extra');
var path = require('path');
var spawn = require('cross-spawn');
var spawnSync = spawn.sync;
var pathExists = require('path-exists');
var chalk = require('chalk');

module.exports = function(appPath, appName, verbose, originalDirectory) {
var ownPath = path.join(appPath, 'node_modules', 'react-scripts');

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

// Copy over some of the devDependencies
appPackage.dependencies = appPackage.dependencies || {};
appPackage.devDependencies = appPackage.devDependencies || {};
['react', 'react-dom'].forEach(function (key) {
appPackage.dependencies[key] = ownPackage.devDependencies[key];
});
['react-test-renderer'].forEach(function (key) {
appPackage.devDependencies[key] = ownPackage.devDependencies[key];
});

// Setup the script rules
appPackage.scripts = {};
Expand Down Expand Up @@ -68,21 +62,28 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
}
});

// Run another npm install for react and react-dom
// Run npm installs for react and react-dom
console.log('Installing react and react-dom from npm...');
console.log();
// TODO: having to do two npm installs is bad, can we avoid it?
var args = [
'install',
verbose && '--verbose'
].filter(function(e) { return e; });
var proc = spawn('npm', args, {stdio: 'inherit'});
proc.on('close', function (code) {
if (code !== 0) {

var installFailed;
['react', 'react-dom', 'react-test-renderer'].forEach(function (pkg) {
var args = [
'install',
pkg,
pkg === 'react-test-renderer' ? '--save-dev' : '--save',
verbose && '--verbose'
].filter(function(e) { return e; });
var result = spawnSync('npm', args, {stdio: 'inherit'});
Copy link
Contributor

Choose a reason for hiding this comment

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

These should not be three separate spawns.
Let's just use --save for all of them, and do it as one spawn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok!


if (result.status !== 0) {
console.error('`npm ' + args.join(' ') + '` failed');
return;
installFailed = true;
}
});

if (!installFailed) {
// Display the most elegant way to cd.
// This needs to handle an undefined originalDirectory for
// backward compatibility with old global-cli's.
Expand Down Expand Up @@ -112,5 +113,5 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
}
console.log();
console.log('Happy hacking!');
});
}
};