Repository: nuxt/create-nuxt-app
Pull request #596 (2020-08-30 12:13:06)

feat: prompt for git
# Feat - Prompt for Git

Issue #587 - Creating a project within an existing repository causes a fatal git error

## Description

This pull request will prompt the user to choose a version control system.

![image](https://user-images.githubusercontent.com/41923457/91658614-8e95ef80-eac1-11ea-85ab-94806486c42d.png)

There's two main reasons for this:

1. Using `npx create-nuxt-app` in an existing repository fails, as two `.git` directories exist. This is especially prevalent in our projects where we have a Django backend and Nuxt frontend in the same repo.
2. Several types of VCS exist (e.g. SVN), and users shouldn't be forced to delete unwanted directories in order to implement their preference. 

This feature has been designed to easily allow another VCS to be added to the list.

## Changes

The `prompt.js` asks for a VCS preference in the form of a list.

![image](https://user-images.githubusercontent.com/41923457/91658682-4925f200-eac2-11ea-8e1d-8501d6d70951.png)

The `saofile.js` will now only run `gitInit()` if the respective choice is selected.

![image](https://user-images.githubusercontent.com/41923457/91658687-5d69ef00-eac2-11ea-82f5-fe210363fa3d.png)


LloydTao: Tests pass on my machine 😣 

![image](https://user-images.githubusercontent.com/41923457/91659204-75dc0880-eac6-11ea-9bc2-c5d7c5f0a6d4.png)

LloydTao: Re-linting directly before pushing did the trick. Life of a Windows dev 😁
LloydTao: I'm now realising that these tests are auto-generated 😂 
LloydTao: All good to review now 😜 

Patch:
diff --git a/packages/create-nuxt-app/lib/prompts.js b/packages/create-nuxt-app/lib/prompts.js
index 4232455..a7c4829 100644
--- a/packages/create-nuxt-app/lib/prompts.js
+++ b/packages/create-nuxt-app/lib/prompts.js
@@ -112,5 +112,15 @@ module.exports = [
       { name: 'Semantic Pull Requests', value: 'semantic-pull-requests' }
     ],
     default: []
+  },
+  {
+    name: 'vcs',
+    message: 'Version control system:',
+    type: 'list',
+    choices: [
+      { name: 'Git', value: 'git' },
+      { name: 'None', value: 'none' }
+    ],
+    default: 'git'
   }
 ]
diff --git a/packages/create-nuxt-app/lib/saofile.js b/packages/create-nuxt-app/lib/saofile.js
index c899c0d..61406cc 100644
--- a/packages/create-nuxt-app/lib/saofile.js
+++ b/packages/create-nuxt-app/lib/saofile.js
@@ -125,7 +125,9 @@ module.exports = {
     return actions
   },
   async completed () {
-    this.gitInit()
+    if (this.answers.vcs === 'git') {
+      this.gitInit()
+    }
 
     await this.npmInstall({ npmClient: this.answers.pm })
 


Test patch:
diff --git a/packages/create-nuxt-app/test/snapshots/index.test.js.md b/packages/create-nuxt-app/test/snapshots/index.test.js.md
index 6792b39..71bfd98 100644
--- a/packages/create-nuxt-app/test/snapshots/index.test.js.md
+++ b/packages/create-nuxt-app/test/snapshots/index.test.js.md
@@ -4202,3 +4202,211 @@ Generated by [AVA](https://avajs.dev).
       }␊
     }␊
     `
+
+## verify vcs: Git
+
+> Generated files
+
+    [
+      '.editorconfig',
+      '.gitignore',
+      'README.md',
+      'assets/README.md',
+      'components/Logo.vue',
+      'components/README.md',
+      'layouts/README.md',
+      'layouts/default.vue',
+      'middleware/README.md',
+      'nuxt.config.js',
+      'package.json',
+      'pages/README.md',
+      'pages/index.vue',
+      'plugins/README.md',
+      'static/README.md',
+      'static/favicon.ico',
+      'store/README.md',
+    ]
+
+> package.json
+
+    {
+      dependencies: {
+        nuxt: '^2.14.0',
+      },
+      devDependencies: {},
+      private: true,
+      scripts: {
+        build: 'nuxt build',
+        dev: 'nuxt',
+        generate: 'nuxt generate',
+        start: 'nuxt start',
+      },
+    }
+
+> Generated nuxt.config.js
+
+    `␊
+    export default {␊
+      /*␊
+      ** Nuxt rendering mode␊
+      ** See https://nuxtjs.org/api/configuration-mode␊
+      */␊
+      mode: 'universal',␊
+      /*␊
+      ** Nuxt target␊
+      ** See https://nuxtjs.org/api/configuration-target␊
+      */␊
+      target: 'server',␊
+      /*␊
+      ** Headers of the page␊
+      ** See https://nuxtjs.org/api/configuration-head␊
+      */␊
+      head: {␊
+        title: process.env.npm_package_name || '',␊
+        meta: [␊
+          { charset: 'utf-8' },␊
+          { name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
+          { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊
+        ],␊
+        link: [␊
+          { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
+        ]␊
+      },␊
+      /*␊
+      ** Global CSS␊
+      */␊
+      css: [␊
+      ],␊
+      /*␊
+      ** Plugins to load before mounting the App␊
+      ** https://nuxtjs.org/guide/plugins␊
+      */␊
+      plugins: [␊
+      ],␊
+      /*␊
+      ** Auto import components␊
+      ** See https://nuxtjs.org/api/configuration-components␊
+      */␊
+      components: true,␊
+      /*␊
+      ** Nuxt.js dev-modules␊
+      */␊
+      buildModules: [␊
+      ],␊
+      /*␊
+      ** Nuxt.js modules␊
+      */␊
+      modules: [␊
+      ],␊
+      /*␊
+      ** Build configuration␊
+      ** See https://nuxtjs.org/api/configuration-build/␊
+      */␊
+      build: {␊
+      }␊
+    }␊
+    `
+
+## verify vcs: None
+
+> Generated files
+
+    [
+      '.editorconfig',
+      '.gitignore',
+      'README.md',
+      'assets/README.md',
+      'components/Logo.vue',
+      'components/README.md',
+      'layouts/README.md',
+      'layouts/default.vue',
+      'middleware/README.md',
+      'nuxt.config.js',
+      'package.json',
+      'pages/README.md',
+      'pages/index.vue',
+      'plugins/README.md',
+      'static/README.md',
+      'static/favicon.ico',
+      'store/README.md',
+    ]
+
+> package.json
+
+    {
+      dependencies: {
+        nuxt: '^2.14.0',
+      },
+      devDependencies: {},
+      private: true,
+      scripts: {
+        build: 'nuxt build',
+        dev: 'nuxt',
+        generate: 'nuxt generate',
+        start: 'nuxt start',
+      },
+    }
+
+> Generated nuxt.config.js
+
+    `␊
+    export default {␊
+      /*␊
+      ** Nuxt rendering mode␊
+      ** See https://nuxtjs.org/api/configuration-mode␊
+      */␊
+      mode: 'universal',␊
+      /*␊
+      ** Nuxt target␊
+      ** See https://nuxtjs.org/api/configuration-target␊
+      */␊
+      target: 'server',␊
+      /*␊
+      ** Headers of the page␊
+      ** See https://nuxtjs.org/api/configuration-head␊
+      */␊
+      head: {␊
+        title: process.env.npm_package_name || '',␊
+        meta: [␊
+          { charset: 'utf-8' },␊
+          { name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
+          { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊
+        ],␊
+        link: [␊
+          { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
+        ]␊
+      },␊
+      /*␊
+      ** Global CSS␊
+      */␊
+      css: [␊
+      ],␊
+      /*␊
+      ** Plugins to load before mounting the App␊
+      ** https://nuxtjs.org/guide/plugins␊
+      */␊
+      plugins: [␊
+      ],␊
+      /*␊
+      ** Auto import components␊
+      ** See https://nuxtjs.org/api/configuration-components␊
+      */␊
+      components: true,␊
+      /*␊
+      ** Nuxt.js dev-modules␊
+      */␊
+      buildModules: [␊
+      ],␊
+      /*␊
+      ** Nuxt.js modules␊
+      */␊
+      modules: [␊
+      ],␊
+      /*␊
+      ** Build configuration␊
+      ** See https://nuxtjs.org/api/configuration-build/␊
+      */␊
+      build: {␊
+      }␊
+    }␊
+    `