From cfaf633a2198dc091af422ac1ebf4821f2b03fa2 Mon Sep 17 00:00:00 2001 From: Dinuka De Silva Date: Wed, 14 Dec 2016 16:50:26 +0530 Subject: [PATCH 1/3] gh-1269: Enabling nested folder paths for project name --- packages/create-react-app/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index 7c9394ea371..f1765861ce5 100644 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -105,7 +105,7 @@ function createApp(name, verbose, version) { checkAppName(appName); if (!pathExists.sync(name)) { - fs.mkdirSync(root); + createFolderPath(name); } else if (!isSafeToCreateProjectIn(root)) { console.log('The directory ' + chalk.green(name) + ' contains files that could conflict.'); console.log('Try using a new directory name.'); @@ -136,6 +136,16 @@ function createApp(name, verbose, version) { run(root, appName, version, verbose, originalDirectory); } +function createFolderPath(path) { + var projectPath = (path + "/"); + projectPath.replace(/(\w+)\//ig, function(i, dirName, index){ + var dirPath = path.substr(0, index + 1 + dirName.length); + if (!pathExists.sync(dirPath)) { + fs.mkdirSync(dirPath); + } + }); +} + function shouldUseYarn() { try { execSync('yarn --version', {stdio: 'ignore'}); From 396d7b546673defbc07e41d54e7a0c4529554591 Mon Sep 17 00:00:00 2001 From: dinukadesilva Date: Sat, 17 Dec 2016 19:27:01 +0530 Subject: [PATCH 2/3] gh-1269: Added "fs-extra" and removed "path-exists" --- packages/create-react-app/index.js | 19 +++---------------- packages/create-react-app/package.json | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index f1765861ce5..ab356d4d795 100644 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -52,12 +52,11 @@ if (currentNodeVersion.split('.')[0] < 4) { process.exit(1); } -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); var execSync = require('child_process').execSync; var spawn = require('cross-spawn'); var semver = require('semver'); -var pathExists = require('path-exists'); var projectName; @@ -103,10 +102,8 @@ function createApp(name, verbose, version) { var appName = path.basename(root); checkAppName(appName); - - if (!pathExists.sync(name)) { - createFolderPath(name); - } else if (!isSafeToCreateProjectIn(root)) { + 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.'); process.exit(1); @@ -136,16 +133,6 @@ function createApp(name, verbose, version) { run(root, appName, version, verbose, originalDirectory); } -function createFolderPath(path) { - var projectPath = (path + "/"); - projectPath.replace(/(\w+)\//ig, function(i, dirName, index){ - var dirPath = path.substr(0, index + 1 + dirName.length); - if (!pathExists.sync(dirPath)) { - fs.mkdirSync(dirPath); - } - }); -} - function shouldUseYarn() { try { execSync('yarn --version', {stdio: 'ignore'}); diff --git a/packages/create-react-app/package.json b/packages/create-react-app/package.json index 1c466c7f876..94525c3e812 100644 --- a/packages/create-react-app/package.json +++ b/packages/create-react-app/package.json @@ -23,7 +23,7 @@ "chalk": "^1.1.1", "commander": "^2.9.0", "cross-spawn": "^4.0.0", - "path-exists": "^2.1.0", + "fs-extra": "^1.0.0", "semver": "^5.0.3" } } From 1a8121c112e7575e41b61f4f4d212c3f429683d7 Mon Sep 17 00:00:00 2001 From: dinukadesilva Date: Sat, 17 Dec 2016 20:12:53 +0530 Subject: [PATCH 3/3] gh-1269: Added e2e test cases to verify nested folder names --- tasks/e2e.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tasks/e2e.sh b/tasks/e2e.sh index 5a2ecdf31ef..27cd0ae45f6 100755 --- a/tasks/e2e.sh +++ b/tasks/e2e.sh @@ -230,5 +230,31 @@ cd test-app-fork # Check corresponding scripts version is installed. test -e node_modules/react-scripts-fork +# ****************************************************************************** +# Test nested folder path as the project name +# ****************************************************************************** + +#Testing a path that exists +cd $temp_app_path +mkdir test-app-nested-paths-t1 +cd test-app-nested-paths-t1 +mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd +create_react_app test-app-nested-paths-t1/aa/bb/cc/dd +cd test-app-nested-paths-t1/aa/bb/cc/dd +npm start -- --smoke-test + +#Testing a path that does not exist +cd $temp_app_path +create_react_app test-app-nested-paths-t2/aa/bb/cc/dd +cd test-app-nested-paths-t2/aa/bb/cc/dd +npm start -- --smoke-test + +#Testing a path that is half exists +cd $temp_app_path +mkdir -p test-app-nested-paths-t3/aa +create_react_app test-app-nested-paths-t3/aa/bb/cc/dd +cd test-app-nested-paths-t3/aa/bb/cc/dd +npm start -- --smoke-test + # Cleanup cleanup