Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the app name before proceeding. #628

Merged
merged 6 commits into from
Sep 11, 2016
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ createApp(commands[0], argv.verbose, argv['scripts-version']);

function createApp(name, verbose, version) {
var root = path.resolve(name);
var appName = path.basename(root);

// NPM is whining about installing packages with names equal to appName.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can be removed.

checkAppName(appName);

if (!pathExists.sync(name)) {
fs.mkdirSync(root);
} else if (!isSafeToCreateProjectIn(root)) {
console.log('The directory `' + name + '` contains file(s) that could conflict. Aborting.');
process.exit(1);
}

var appName = path.basename(root);
console.log(
'Creating a new React app in ' + root + '.'
);
Expand Down Expand Up @@ -167,6 +171,26 @@ 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a few semicolons here.


if (allDependencies.indexOf(appName) >= 0) {
console.error(
chalk.red(
'The name of your app ' + chalk.red.bold('MUST NOT') + ' match any of the following:\n\n' +

chalk.cyan(
allDependencies.map(depName => ` ${depName}`).join('\n')
)
)
);
process.exit(1);
}
}

// If project only contains files generated by GH, it’s safe.
// We also special case IJ-based products .idea because it integrates with CRA:
// https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
Expand Down