create-react-app
Advanced tools
Comparing version 0.3.0 to 0.4.2-alpha.8f28c56e
71
index.js
@@ -32,2 +32,5 @@ #!/usr/bin/env node | ||
// | ||
// Also be careful with new language features. | ||
// This file must work on Node 0.10+. | ||
// | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
@@ -45,3 +48,2 @@ // /!\ DO NOT MODIFY THIS FILE /!\ | ||
var argv = require('minimist')(process.argv.slice(2)); | ||
var pathExists = require('path-exists'); | ||
@@ -56,3 +58,3 @@ /** | ||
* - a .tgz archive from any npm repo: "https://registry.npmjs.org/react-scripts/-/react-scripts-0.20.0.tgz" | ||
* - a package prepared with `npm pack`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz" | ||
* - a package prepared with `tasks/clean_pack.sh`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz" | ||
*/ | ||
@@ -75,3 +77,7 @@ var commands = argv._; | ||
var root = path.resolve(name); | ||
if (!pathExists.sync(name)) { | ||
var appName = path.basename(root); | ||
checkAppName(appName); | ||
if (!pathExistsSync(name)) { | ||
fs.mkdirSync(root); | ||
@@ -83,3 +89,2 @@ } else if (!isSafeToCreateProjectIn(root)) { | ||
var appName = path.basename(root); | ||
console.log( | ||
@@ -110,2 +115,4 @@ 'Creating a new React app in ' + root + '.' | ||
function run(root, appName, version, verbose, originalDirectory) { | ||
var installPackage = getInstallPackage(version); | ||
var packageName = getPackageName(installPackage); | ||
var args = [ | ||
@@ -116,3 +123,3 @@ 'install', | ||
'--save-exact', | ||
getInstallPackage(version), | ||
installPackage, | ||
].filter(function(e) { return e; }); | ||
@@ -126,3 +133,3 @@ var proc = spawn('npm', args, {stdio: 'inherit'}); | ||
checkNodeVersion(); | ||
checkNodeVersion(packageName); | ||
@@ -132,3 +139,3 @@ var scriptsPath = path.resolve( | ||
'node_modules', | ||
'react-scripts', | ||
packageName, | ||
'scripts', | ||
@@ -154,7 +161,17 @@ 'init.js' | ||
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' | ||
@@ -180,2 +197,25 @@ ); | ||
function checkAppName(appName) { | ||
// TODO: there should be a single place that holds the dependencies | ||
var dependencies = ['react', 'react-dom']; | ||
var devDependencies = ['react-scripts']; | ||
var allDependencies = dependencies.concat(devDependencies).sort(); | ||
if (allDependencies.indexOf(appName) >= 0) { | ||
console.error( | ||
chalk.red( | ||
'We cannot create a project called `' + appName + '` because a dependency with the same name exists.\n' + | ||
'Due to the way npm works, the following names are not allowed:\n\n' | ||
) + | ||
chalk.cyan( | ||
allDependencies.map(function(depName) { | ||
return ' ' + depName; | ||
}).join('\n') | ||
) + | ||
chalk.red('\n\nPlease choose a different project name.') | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
// If project only contains files generated by GH, it’s safe. | ||
@@ -193,1 +233,14 @@ // We also special case IJ-based products .idea because it integrates with CRA: | ||
} | ||
// This is an ES5 version of https://github.com/sindresorhus/path-exists. | ||
// The reason it exists is so that the CLI doesn't break before being able to | ||
// warn the user they're using an unsupported version of Node. | ||
// See https://github.com/facebookincubator/create-react-app/issues/570 | ||
function pathExistsSync(fp) { | ||
try { | ||
fs.accessSync(fp); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
} |
{ | ||
"name": "create-react-app", | ||
"version": "0.3.0", | ||
"version": "0.4.2-alpha.8f28c56e", | ||
"keywords": [ | ||
@@ -10,2 +10,5 @@ "react" | ||
"license": "BSD-3-Clause", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"bugs": { | ||
@@ -24,5 +27,4 @@ "url": "https://github.com/facebookincubator/create-react-app/issues" | ||
"minimist": "^1.2.0", | ||
"path-exists": "^3.0.0", | ||
"semver": "^5.0.3" | ||
} | ||
} |
7814
4
210
- Removedpath-exists@^3.0.0
- Removedpath-exists@3.0.0(transitive)