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

gh-1269: Enabling nested folder paths for project name #1270

Merged
merged 3 commits into from
Dec 18, 2016
Merged
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion packages/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function createApp(name, verbose, version) {
checkAppName(appName);

if (!pathExists.sync(name)) {
fs.mkdirSync(root);
createFolderPath(name);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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 and fs.extra would just include mkdirp 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.

Copy link
Contributor

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 in react-scripts, but not not in create-react-app.

Copy link
Contributor Author

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.

} else if (!isSafeToCreateProjectIn(root)) {
console.log('The directory ' + chalk.green(name) + ' contains files that could conflict.');
console.log('Try using a new directory name.');
Expand Down Expand Up @@ -136,6 +136,16 @@ function createApp(name, verbose, version) {
run(root, appName, version, verbose, originalDirectory);
}

function createFolderPath(path) {
var projectPath = (path + "/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to work on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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'});
Expand Down