Skip to content

Commit

Permalink
feat: add commitlint as linting tools option (#592)
Browse files Browse the repository at this point in the history
* feat: add commitlint as linting tools option

* fix: correct lint issue

* fix: update snapshots
  • Loading branch information
jaeheonji committed Sep 8, 2020
1 parent 4d404ff commit 33817a8
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions packages/cna-template/template/_commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
};
6 changes: 6 additions & 0 deletions packages/cna-template/template/nuxt/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions packages/cna-template/template/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
},
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/create-nuxt-app/lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
},
Expand Down
6 changes: 5 additions & 1 deletion packages/create-nuxt-app/lib/saofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,6 +32,7 @@ module.exports = {
prettier,
lintStaged,
stylelint,
commitlint,
axios,
edge,
pm,
Expand Down Expand Up @@ -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
})
Expand All @@ -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'
}
})
Expand Down
115 changes: 114 additions & 1 deletion packages/create-nuxt-app/test/snapshots/index.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -1272,6 +1384,7 @@ Generated by [AVA](https://avajs.dev).
},
husky: {
hooks: {
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
'pre-commit': 'lint-staged',
},
},
Expand Down
Binary file modified packages/create-nuxt-app/test/snapshots/index.test.js.snap
Binary file not shown.

0 comments on commit 33817a8

Please sign in to comment.