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

Change error wording and list conflicting files when initializing app #2785

Merged
merged 3 commits into from
Jul 14, 2017
Merged
Changes from 2 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
31 changes: 24 additions & 7 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ function createApp(name, verbose, version, template) {

checkAppName(appName);
fs.ensureDirSync(name);
if (!isSafeToCreateProjectIn(root)) {
console.log(
`The directory ${chalk.green(name)} contains files that could conflict.`
);
console.log('Try using a new directory name.');
if (!isSafeToCreateProjectIn(root, name)) {
process.exit(1);
}

Expand Down Expand Up @@ -571,7 +567,7 @@ function setCaretRangeForRuntimeDeps(packageName) {
// 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
function isSafeToCreateProjectIn(root) {
function isSafeToCreateProjectIn(root, name) {
const validFiles = [
'.DS_Store',
'Thumbs.db',
Expand All @@ -585,7 +581,28 @@ function isSafeToCreateProjectIn(root) {
'.hgignore',
'.hgcheck',
];
return fs.readdirSync(root).every(file => validFiles.indexOf(file) >= 0);
console.log();

const conflicts = fs
.readdirSync(root)
.filter(file => !validFiles.includes(file));
if (conflicts.length < 1) {
return true;
}

console.log(
`The directory ${chalk.green(name)} contains files that could conflict.`
);
console.log();
for (const file of conflicts) {
console.log(` ${file}`);
}
console.log();
console.log(
'Either try using a new directory name, or remove the files listed above.'
);

return false;
}

function checkIfOnline(useYarn) {
Expand Down