From cfaf633a2198dc091af422ac1ebf4821f2b03fa2 Mon Sep 17 00:00:00 2001 From: Dinuka De Silva Date: Wed, 14 Dec 2016 16:50:26 +0530 Subject: [PATCH] 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'});