Skip to content

Commit

Permalink
Make --scripts-version work with forked react-scripts (facebook#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck authored and feiqitian committed Oct 25, 2016
1 parent 7b62590 commit 72c2bd1
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ function createApp(name, verbose, version) {
}

function run(root, appName, version, verbose, originalDirectory) {
var installPackage = getInstallPackage(version);
var packageName = getPackageName(installPackage);
var args = [
'install',
verbose && '--verbose',
'--save-dev',
'--save-exact',
getInstallPackage(version),
installPackage,
].filter(function(e) { return e; });
var proc = spawn('npm', args, {stdio: 'inherit'});
proc.on('close', function (code) {
Expand All @@ -118,12 +120,12 @@ function run(root, appName, version, verbose, originalDirectory) {
return;
}

checkNodeVersion();
checkNodeVersion(packageName);

var scriptsPath = path.resolve(
process.cwd(),
'node_modules',
'react-scripts',
packageName,
'scripts',
'init.js'
);
Expand All @@ -144,11 +146,21 @@ function getInstallPackage(version) {
return packageToInstall;
}

function checkNodeVersion() {
// Extract package name from tarball url or path.
function getPackageName(installPackage) {
if (~installPackage.indexOf('.tgz')) {
return installPackage.match(/^.+\/(.+)-.+\.tgz$/)[1];
} else if (~installPackage.indexOf('@')) {
return installPackage.split('@')[0];
}
return installPackage;
}

function checkNodeVersion(packageName) {
var packageJsonPath = path.resolve(
process.cwd(),
'node_modules',
'react-scripts',
packageName,
'package.json'
);
var packageJson = require(packageJsonPath);
Expand Down

0 comments on commit 72c2bd1

Please sign in to comment.