cli icon indicating copy to clipboard operation
cli copied to clipboard

allow initialising new nuxt app in a non-empty root directory

Open jerryjappinen opened this issue 3 years ago • 1 comments

Environment

Nuxt CLI v3.0.0-rc.4

------------------------------
- Operating System: `Linux`
- Node Version:     `v16.15.0`
- Nuxt Version:     `0.0.0`
- Package Manager:  `unknown`
- Builder:          `webpack`
- User Config:      `-`
- Runtime Modules:  `-`
- Build Modules:    `-`
------------------------------

Reproduction

  1. Create new, empty folder
  2. Run git init
  3. Run npx nuxi init ./
  4. Get error: Directory is not empty. Please pick another name or remove it first. Aborting.

Describe the bug

From the end-user perspective, this directory is empty. It of course has a .git folder, but as a user I don't see why this should mean I cannot initialise a new app here.

When setting up a project, I might often initialise a git repo or clone a blank repo before initialising an app. The current behavior prevents initialising a Nuxt app in the current folder in this case.

Additional context

I came across this when attempting to initialise a Nuxt app on a CodeSandbox Projects. I can see this being a platform on more high-level platforms or IDEs in the future, as they might provide a git-based workflow where the git project has already been created.

User can work around this by creating the project in a sub folder and then manually moving all generated files to the root level.

https://user-images.githubusercontent.com/1101002/175813422-1cafa111-118c-4b72-81d9-058a7df78626.mp4

Logs

Logs to show difference between empty folder, and folder after git init:

Development/ mkdir _demo1
_demo1

Development/ cd _demo1/

_demo1/ ls -la
total 0
drwxr-xr-x   2 jerryjappinen  staff    64 Jun 26 13:59 .
drwxr-xr-x  35 jerryjappinen  staff  1120 Jun 26 13:59 ..

_demo1/ npx nuxi init ./
Need to install the following packages:
  nuxi
Ok to proceed? (y) 
Nuxt CLI v3.0.0-27444434.856c01a                                                13:59:42
ℹ cloned nuxt/starter#v3 to /Users/jerryjappinen/Development/_demo1             13:59:42
                                                                                13:59:42
 🎉  Another kryptonian Nuxt project just made! Next steps:

     📁  `cd `

     💿  Install dependencies with `npm install` or `yarn install`

     🚀  Start development server with `npm run dev` or `yarn dev`

     

_demo1/ cd ..

Development/ mkdir _demo2
_demo2

Development/ cd _demo2

_demo2/ git init
Initialized empty Git repository in /Users/jerryjappinen/Development/_demo2/.git/

_demo2/ npx nuxi init ./
Need to install the following packages:
  nuxi
Ok to proceed? (y) 
Nuxt CLI v3.0.0-27444434.856c01a                                                14:00:09

 ERROR  Directory /Users/jerryjappinen/Development/_demo2 is not empty. Please pick another name or remove it first. Aborting.

jerryjappinen avatar Jun 26 '22 12:06 jerryjappinen

It's possible to install into the current folder using the --force flag (which I think makes sense), but note there is currently a different bug that's fixed by https://github.com/nuxt/cli/pull/272.

jits avatar Nov 01 '23 14:11 jits