Create-react-app: Creating a new app in the current directory

Created on 2 Aug 2016  路  20Comments  路  Source: facebook/create-react-app

$ mkdir app
$ cd app
$ git init .
$ create-react-app .
> The directory `.` already exists. Aborting.

It would be nice if this worked

Most helpful comment

Currently the behavior is that you can only run create-react-app in a _nonexistent_ directory. It doesn't let you run in an already-existing directory because you don't want to accidentally splat these files into somewhere like ~.

But, if we let you run create-react-app in an _empty_ directory, I think that would be ok. I think it would also be OK if there was a readme / readme.md and dotfiles like .gitignore in the directory. That makes things work with a workflow where you first create a new repo on github, you clone it to your local machine, and then you run create-react-app. It's hard for me to imagine a case where that causes you much pain.

All 20 comments

@gaearon I can take this one.

@torifat 馃憤

@gaearon @thejameskyle in my opinion, allowing it in empty directory is a better choice. But, in case you guys prefer it in a non-empty directory. What would be the strategy for conflict?

Currently the behavior is that you can only run create-react-app in a _nonexistent_ directory. It doesn't let you run in an already-existing directory because you don't want to accidentally splat these files into somewhere like ~.

But, if we let you run create-react-app in an _empty_ directory, I think that would be ok. I think it would also be OK if there was a readme / readme.md and dotfiles like .gitignore in the directory. That makes things work with a workflow where you first create a new repo on github, you clone it to your local machine, and then you run create-react-app. It's hard for me to imagine a case where that causes you much pain.

@lacker yeah, I thought about ignoring hidden files/directories. But, since we have a .gitignore and it might conflict with an existing .gitignore file.

If it's an empty directory except for a .gitignore file and a README, then how useful can that old .gitignore file be? I bet in that case it is basically always the github autogenerated one for new projects & it is fine to just replace it.

Checking for .gitignore, README, README.md, LICENSE, LICENSE.md, CONTRIBUTING.md, etc didn't seemed like a good idea to me. That's why I was asking for opinion.

If we're in the game of guessing things that would not conflict, I would only check if there's a package.json file. If that's the case, then it's probably unsafe, otherwise should be good to go.

@torifat you do this? if not, I am willing to do it~

@stephenkingsley yes, I'm working on it. I will knock you if I couldn't manage any extra time in next 2 days.

@torifat 馃挭 馃憤

@gaearon we are using deprecated NodeJS APIs. Should I update them too?

screenshot 2016-08-05 04 46 46

Ideally yes. It doesn't make sense to rewrite this as callback-heavy code though (this is a console utility after all). So maybe worth looking if fs-extra already has a helper for this.

Sindre is here to help

npm install path-exists

@gaearon BTW, is there any way to do it without modifying the globel-cli index file?

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   /!\ DO NOT MODIFY THIS FILE /!\
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Replacing fs.existsSync() with pathExists.sync() isn't really a breaking change. I don't know if you need to make any other changes than that

@thejameskyle I have already done that.

status on this @torifat? did it ever get merged?

@KevinMind Gave this a go in an empty directory (that also happened to be a repo). Worked fine with create-react-app .

Works for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ap13p picture ap13p  路  3Comments

DaveLindberg picture DaveLindberg  路  3Comments

alleroux picture alleroux  路  3Comments

JimmyLv picture JimmyLv  路  3Comments

onelson picture onelson  路  3Comments