Repository: nuxt/create-nuxt-app
Pull request #592 (2020-08-25 16:31:38)

feat: add commitlint as linting tools option
This PR adds [commitlint](https://github.com/conventional-changelog/commitlint) as linting tools option ✔️


Patch:
diff --git a/README.md b/README.md
index 404a830..40423aa 100644
--- a/README.md
+++ b/README.md
@@ -59,6 +59,7 @@ yarn create nuxt-app <my-project>
     - [Prettier](https://github.com/prettier/prettier)
     - [Lint staged files](https://github.com/okonet/lint-staged)
     - [StyleLint](https://github.com/stylelint/stylelint)
+    - [Commitlint](https://github.com/conventional-changelog/commitlint)
 1. Testing framework:
     - None
     - [Jest](https://github.com/facebook/jest)
diff --git a/packages/cna-template/template/_commitlint.config.js b/packages/cna-template/template/_commitlint.config.js
new file mode 100644
index 0000000..69b4242
--- /dev/null
+++ b/packages/cna-template/template/_commitlint.config.js
@@ -0,0 +1,3 @@
+module.exports = {
+  extends: ["@commitlint/config-conventional"],
+};
diff --git a/packages/cna-template/template/nuxt/package.js b/packages/cna-template/template/nuxt/package.js
index e7d8bab..235e650 100644
--- a/packages/cna-template/template/nuxt/package.js
+++ b/packages/cna-template/template/nuxt/package.js
@@ -16,6 +16,7 @@ module.exports = {
     const lintStaged = eslint && linter.includes('lintStaged')
     const stylelint = linter.includes('stylelint')
     const prettier = linter.includes('prettier')
+    const commitlint = linter.includes('commitlint')
     const lintScripts = {
       eslint: '<%= pmRun %> lint:js',
       stylelint: '<%= pmRun %> lint:style'
@@ -51,6 +52,11 @@ module.exports = {
       delete pkg.devDependencies['stylelint-config-prettier']
       delete pkg.devDependencies.prettier
     }
+    if (!commitlint) {
+      lintStaged && delete pkg.husky.hooks['commit-msg']
+      delete pkg.devDependencies['@commitlint/config-conventional']
+      delete pkg.devDependencies['@commitlint/cli']
+    }
 
     const lintScript = Object.values(lintScripts).join(' && ')
     if (lintScript) {
diff --git a/packages/cna-template/template/nuxt/package.json b/packages/cna-template/template/nuxt/package.json
index 67159e1..8545041 100644
--- a/packages/cna-template/template/nuxt/package.json
+++ b/packages/cna-template/template/nuxt/package.json
@@ -13,6 +13,7 @@
   },
   "husky": {
     "hooks": {
+      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
       "pre-commit": "lint-staged"
     }
   },
@@ -25,6 +26,8 @@
     "nuxt": "^2.14.0"
   },
   "devDependencies": {
+    "@commitlint/config-conventional": "^9.1.2",
+    "@commitlint/cli": "^9.1.2",
     "@nuxt/types": "^2.14.0",
     "@nuxt/typescript-build": "^2.0.3",
     "@nuxtjs/eslint-config": "^3.1.0",
diff --git a/packages/create-nuxt-app/lib/prompts.js b/packages/create-nuxt-app/lib/prompts.js
index a7c4829..aad7632 100644
--- a/packages/create-nuxt-app/lib/prompts.js
+++ b/packages/create-nuxt-app/lib/prompts.js
@@ -67,7 +67,8 @@ module.exports = [
       { name: 'ESLint', value: 'eslint' },
       { name: 'Prettier', value: 'prettier' },
       { name: 'Lint staged files', value: 'lintStaged' },
-      { name: 'StyleLint', value: 'stylelint' }
+      { name: 'StyleLint', value: 'stylelint' },
+      { name: 'Commitlint', value: 'commitlint' }
     ],
     default: []
   },
diff --git a/packages/create-nuxt-app/lib/saofile.js b/packages/create-nuxt-app/lib/saofile.js
index 61406cc..7776db4 100644
--- a/packages/create-nuxt-app/lib/saofile.js
+++ b/packages/create-nuxt-app/lib/saofile.js
@@ -16,6 +16,7 @@ module.exports = {
     const prettier = this.answers.linter.includes('prettier')
     const lintStaged = eslint && this.answers.linter.includes('lintStaged')
     const stylelint = this.answers.linter.includes('stylelint')
+    const commitlint = this.answers.linter.includes('commitlint')
     const axios = this.answers.features.includes('axios')
     const content = this.answers.features.includes('content')
     const pm = this.answers.pm === 'yarn' ? 'yarn' : 'npm'
@@ -31,6 +32,7 @@ module.exports = {
       prettier,
       lintStaged,
       stylelint,
+      commitlint,
       axios,
       edge,
       pm,
@@ -83,7 +85,8 @@ module.exports = {
         '_jsconfig.json': 'devTools.includes("jsconfig.json")',
         'tsconfig.json': 'language.includes("ts")',
         'semantic.yml': 'devTools.includes("semantic-pull-requests")',
-        '_stylelint.config.js': 'linter.includes("stylelint")'
+        '_stylelint.config.js': 'linter.includes("stylelint")',
+        '_commitlint.config.js': 'linter.includes("commitlint")'
       },
       templateDir
     })
@@ -97,6 +100,7 @@ module.exports = {
         '_.eslintrc.js': '.eslintrc.js',
         '_jsconfig.json': 'jsconfig.json',
         '_stylelint.config.js': 'stylelint.config.js',
+        '_commitlint.config.js': 'commitlint.config.js',
         'semantic.yml': '.github/semantic.yml'
       }
     })


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 4f2f1d8..f53d4f9 100644
--- a/packages/create-nuxt-app/test/snapshots/index.test.js.md
+++ b/packages/create-nuxt-app/test/snapshots/index.test.js.md
@@ -1104,6 +1104,115 @@ Generated by [AVA](https://avajs.dev).
     }␊
     `
 
+## verify linter: Commitlint
+
+> Generated files
+
+    [
+      '.editorconfig',
+      '.gitignore',
+      'README.md',
+      'assets/README.md',
+      'commitlint.config.js',
+      '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: {
+        'core-js': '^3.6.5',
+        nuxt: '^2.14.0',
+      },
+      devDependencies: {
+        '@commitlint/cli': '^9.1.2',
+        '@commitlint/config-conventional': '^9.1.2',
+      },
+      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 linter: ESLint
 
 > Generated files
@@ -1220,7 +1329,7 @@ Generated by [AVA](https://avajs.dev).
     }␊
     `
 
-## verify linter: ESLint, Prettier, Lint staged files, StyleLint
+## verify linter: ESLint, Prettier, Lint staged files, StyleLint, Commitlint
 
 > Generated files
 
@@ -1231,6 +1340,7 @@ Generated by [AVA](https://avajs.dev).
       '.prettierrc',
       'README.md',
       'assets/README.md',
+      'commitlint.config.js',
       'components/Logo.vue',
       'components/README.md',
       'layouts/README.md',
@@ -1255,6 +1365,8 @@ Generated by [AVA](https://avajs.dev).
         nuxt: '^2.14.0',
       },
       devDependencies: {
+        '@commitlint/cli': '^9.1.2',
+        '@commitlint/config-conventional': '^9.1.2',
         '@nuxtjs/eslint-config': '^3.1.0',
         '@nuxtjs/eslint-module': '^2.0.0',
         '@nuxtjs/stylelint-module': '^4.0.0',
@@ -1272,6 +1384,7 @@ Generated by [AVA](https://avajs.dev).
       },
       husky: {
         hooks: {
+          'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
           'pre-commit': 'lint-staged',
         },
       },