FredKSchott / create-snowpack-app

The all-in-one app template for Snowpack. [moved]
https://www.snowpack.dev
Other
727 stars 96 forks source link

Support create-snowpack-app in existing directory? #41

Closed cherniavskii closed 4 years ago

cherniavskii commented 4 years ago

Hi! 👋

I wanted to check out create-snowpack-app - it looks very promising!

So I've created a new repo on GitHub and checked it out locally. Unfortunately, create-snowpack-app doesn't allow to create app in existing directory, which is a little annoying.

Would you accept a PR, which will allow to create project in existing directory? I'll be happy to contribute :)

Cheers!

cherniavskii commented 4 years ago

As I can see in commit history, directory check was introduced in https://github.com/pikapkg/create-snowpack-app/commit/88c82e8e9623971be36c79e2f3d0de23ca5af61b#diff-d078d18348475d97c2577eed65b1e07cR37 Curious what's the background for it

FredKSchott commented 4 years ago

if it weren't for that check, you could do:

npx create-snowpack-app . --template @snowpack/app-template-react-blank

that check was just a quick implementation to make sure that you weren't clobbering files. If you can replace it with a check that folder doesn't exist OR folder exists but is empty, I'd love a PR

cherniavskii commented 4 years ago

See, when there already is initiated repo, checking if directory is empty won't help much, since it has at least .git, and maybe .gitignore or README.md.

What do you think about adding a flag to force install in existing directory? Something like:

$ npx create-snowpack-app . --template @snowpack/app-template-react-blank
. already exists. Use `--force` flag to overwrite files.
FredKSchott commented 4 years ago

oh... yea this i'm much more nervous about. A --force flag would help a bit with the risk, but I'd rather tackle this post v2.0 release. fwiw Create React App doesn't support this today, I'd also want to see if they ever discussed it in their repo and what their pros/cons were.

cherniavskii commented 4 years ago

Create React App doesn't support this today

Actually it does. Looks like it has a blacklist of files/dirs it checks before installing. For example:

$ ls -a
./            ../           .git/         .gitignore    README.md     node_modules/

$ npx create-react-app .
npx: installed 98 in 5.23s
The directory . contains files that could conflict:

  node_modules/

Either try using a new directory name, or remove the files listed above

$ rm -rf node_modules/

$ npx create-react-app .

# now installs without errors
cherniavskii commented 4 years ago

See https://github.com/facebook/create-react-app/blob/1f81469894f24c25e90e9be116c79a4a3b6d02e9/packages/create-react-app/createReactApp.js#L973

I like their solution, but it seems a little overkill to me TBH

FredKSchott commented 4 years ago

Nice! Okay, this makes me feel a bit better about it. any interest in creating a PR to add?

cherniavskii commented 4 years ago

Yeah, I'll submit a PR later!

FredKSchott commented 4 years ago

Great!