-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
gh-1269: Enabling nested folder paths for project name #1270
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 + "/"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to work on Windows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm in windows. with the slash it's working fine. Are you talking about the backslash? |
||
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'}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use
mkdirpSync
instead? I think that's what it would do.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh yes........ i'l update that.......
Thanks a lot i could learn something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon For that, we need to add https://www.npmjs.com/package/fs.extra as a dependency. Actually, I found few libraries for the same purpose (maybe this too). But, I thought of not adding since it's an additional dependency.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just use the
mkdirp
package, because we only need this one thing, it's small andfs.extra
would just includemkdirp
as a dependency.We'll be able to get rid of
pathExists
so the total number of dependencies is still the same :) Checking if a folder/file exists before creating it is an anti-pattern, so trying to create the directory and just checking if it existed is also better in that sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I thought we were already using
fs-extra
. Turns out we do inreact-scripts
, but not not increate-react-app
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, does that make sence to add fs-extra.
Even i think it would be better since there'll be more use cases where it's helpful.