Commit d8b65295 authored by Marek Suscak's avatar Marek Suscak Committed by Ville Immonen
Browse files

Check the app name before proceeding. (#628)

* Check the app name before proceeding.

* Refactor.

* Use arrow function and template string.

* Remove comment.

* Rephrase the error.

* Add missing semicolons.
parent 55f965aa
Showing with 27 additions and 1 deletion
+27 -1
...@@ -69,6 +69,10 @@ createApp(commands[0], argv.verbose, argv['scripts-version']); ...@@ -69,6 +69,10 @@ createApp(commands[0], argv.verbose, argv['scripts-version']);
function createApp(name, verbose, version) { function createApp(name, verbose, version) {
var root = path.resolve(name); var root = path.resolve(name);
var appName = path.basename(root);
checkAppName(appName);
if (!pathExists.sync(name)) { if (!pathExists.sync(name)) {
fs.mkdirSync(root); fs.mkdirSync(root);
} else if (!isSafeToCreateProjectIn(root)) { } else if (!isSafeToCreateProjectIn(root)) {
...@@ -76,7 +80,6 @@ function createApp(name, verbose, version) { ...@@ -76,7 +80,6 @@ function createApp(name, verbose, version) {
process.exit(1); process.exit(1);
} }
var appName = path.basename(root);
console.log( console.log(
'Creating a new React app in ' + root + '.' 'Creating a new React app in ' + root + '.'
); );
...@@ -167,6 +170,29 @@ function checkNodeVersion() { ...@@ -167,6 +170,29 @@ function checkNodeVersion() {
} }
} }
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(
`Can't use "${appName}" as the app name because a dependency with the same name exists.\n\n` +
`Following names ${chalk.red.bold('must not')} be used:\n\n`
)
+
chalk.cyan(
allDependencies.map(depName => ` ${depName}`).join('\n')
)
);
process.exit(1);
}
}
// If project only contains files generated by GH, it’s safe. // If project only contains files generated by GH, it’s safe.
// We also special case IJ-based products .idea because it integrates with CRA: // We also special case IJ-based products .idea because it integrates with CRA:
// https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094 // https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment