diff --git a/global-cli/index.js b/global-cli/index.js index fdee786369..1ac63a81a2 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);