From d41fb11a4773c639264156035a97a45b0a97ed4e Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Mon, 12 Sep 2016 19:16:34 +0800 Subject: [PATCH] Make --scripts-version work with forked react-scripts --- global-cli/index.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/global-cli/index.js b/global-cli/index.js index fdee7863693..1ac63a81a27 100644 --- a/global-cli/index.js +++ b/global-cli/index.js @@ -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) { @@ -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' ); @@ -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);