From 23e0792edb80051241e722f500d906b32b0b92aa Mon Sep 17 00:00:00 2001 From: Owen Flood Date: Thu, 13 Jul 2017 15:05:28 -0700 Subject: [PATCH 1/3] change error wording and list conflicting files when initializing app --- packages/create-react-app/createReactApp.js | 33 ++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 4509b49788d..78404c7c2fc 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -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); } @@ -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', @@ -585,7 +581,30 @@ function isSafeToCreateProjectIn(root) { '.hgignore', '.hgcheck', ]; - return fs.readdirSync(root).every(file => validFiles.indexOf(file) >= 0); + console.log(); + let conflicts = fs.readdirSync(root).map((file, index) => { + if (!validFiles.indexOf(file) >= 0) { + return file; + } + }); + + if (conflicts.length > 0) { + console.log( + `The directory ${chalk.green( + name + )} already exists and contains files that could cause conflicts:` + ); + console.log(); + console.log(JSON.stringify(conflicts, null, ' ')); + console.log(); + + console.log( + 'Either try using a new directory name, or remove the files listed above.' + ); + return false; + } + + return true; } function checkIfOnline(useYarn) { From f4142ec188114e39f8c4ad7b0bf89b43dc8400b8 Mon Sep 17 00:00:00 2001 From: Owen Flood Date: Thu, 13 Jul 2017 17:45:48 -0700 Subject: [PATCH 2/3] update code --- packages/create-react-app/createReactApp.js | 36 ++++++++++----------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 78404c7c2fc..a1e3aa7d9bb 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -582,29 +582,27 @@ function isSafeToCreateProjectIn(root, name) { '.hgcheck', ]; console.log(); - let conflicts = fs.readdirSync(root).map((file, index) => { - if (!validFiles.indexOf(file) >= 0) { - return file; - } - }); - if (conflicts.length > 0) { - console.log( - `The directory ${chalk.green( - name - )} already exists and contains files that could cause conflicts:` - ); - console.log(); - console.log(JSON.stringify(conflicts, null, ' ')); - console.log(); + const conflicts = fs + .readdirSync(root) + .filter(file => !validFiles.includes(file)); + if (conflicts.length < 1) { + return true; + } - console.log( - 'Either try using a new directory name, or remove the files listed above.' - ); - return false; + 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 true; + return false; } function checkIfOnline(useYarn) { From 7a9439efd337fdbee03a3c38093af0be078cea26 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Thu, 13 Jul 2017 23:18:52 -0400 Subject: [PATCH 3/3] Update createReactApp.js --- packages/create-react-app/createReactApp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index a1e3aa7d9bb..07b083a5f62 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -591,7 +591,7 @@ function isSafeToCreateProjectIn(root, name) { } console.log( - `The directory ${chalk.green(name)} contains files that could conflict.` + `The directory ${chalk.green(name)} contains files that could conflict:` ); console.log(); for (const file of conflicts) {