Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 33817a8

Browse files
authored
feat: add commitlint as linting tools option (#592)
* feat: add commitlint as linting tools option * fix: correct lint issue * fix: update snapshots
1 parent 4d404ff commit 33817a8

File tree

8 files changed

+134
-3
lines changed

8 files changed

+134
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ yarn create nuxt-app <my-project>
5959
- [Prettier](https://github.com/prettier/prettier)
6060
- [Lint staged files](https://github.com/okonet/lint-staged)
6161
- [StyleLint](https://github.com/stylelint/stylelint)
62+
- [Commitlint](https://github.com/conventional-changelog/commitlint)
6263
1. Testing framework:
6364
- None
6465
- [Jest](https://github.com/facebook/jest)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ["@commitlint/config-conventional"],
3+
};

packages/cna-template/template/nuxt/package.js

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
const lintStaged = eslint && linter.includes('lintStaged')
1717
const stylelint = linter.includes('stylelint')
1818
const prettier = linter.includes('prettier')
19+
const commitlint = linter.includes('commitlint')
1920
const lintScripts = {
2021
eslint: '<%= pmRun %> lint:js',
2122
stylelint: '<%= pmRun %> lint:style'
@@ -51,6 +52,11 @@ module.exports = {
5152
delete pkg.devDependencies['stylelint-config-prettier']
5253
delete pkg.devDependencies.prettier
5354
}
55+
if (!commitlint) {
56+
lintStaged && delete pkg.husky.hooks['commit-msg']
57+
delete pkg.devDependencies['@commitlint/config-conventional']
58+
delete pkg.devDependencies['@commitlint/cli']
59+
}
5460

5561
const lintScript = Object.values(lintScripts).join(' && ')
5662
if (lintScript) {

packages/cna-template/template/nuxt/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"husky": {
1515
"hooks": {
16+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
1617
"pre-commit": "lint-staged"
1718
}
1819
},
@@ -25,6 +26,8 @@
2526
"nuxt": "^2.14.0"
2627
},
2728
"devDependencies": {
29+
"@commitlint/config-conventional": "^9.1.2",
30+
"@commitlint/cli": "^9.1.2",
2831
"@nuxt/types": "^2.14.0",
2932
"@nuxt/typescript-build": "^2.0.3",
3033
"@nuxtjs/eslint-config": "^3.1.0",

packages/create-nuxt-app/lib/prompts.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ module.exports = [
6767
{ name: 'ESLint', value: 'eslint' },
6868
{ name: 'Prettier', value: 'prettier' },
6969
{ name: 'Lint staged files', value: 'lintStaged' },
70-
{ name: 'StyleLint', value: 'stylelint' }
70+
{ name: 'StyleLint', value: 'stylelint' },
71+
{ name: 'Commitlint', value: 'commitlint' }
7172
],
7273
default: []
7374
},

packages/create-nuxt-app/lib/saofile.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
const prettier = this.answers.linter.includes('prettier')
1717
const lintStaged = eslint && this.answers.linter.includes('lintStaged')
1818
const stylelint = this.answers.linter.includes('stylelint')
19+
const commitlint = this.answers.linter.includes('commitlint')
1920
const axios = this.answers.features.includes('axios')
2021
const content = this.answers.features.includes('content')
2122
const pm = this.answers.pm === 'yarn' ? 'yarn' : 'npm'
@@ -31,6 +32,7 @@ module.exports = {
3132
prettier,
3233
lintStaged,
3334
stylelint,
35+
commitlint,
3436
axios,
3537
edge,
3638
pm,
@@ -83,7 +85,8 @@ module.exports = {
8385
'_jsconfig.json': 'devTools.includes("jsconfig.json")',
8486
'tsconfig.json': 'language.includes("ts")',
8587
'semantic.yml': 'devTools.includes("semantic-pull-requests")',
86-
'_stylelint.config.js': 'linter.includes("stylelint")'
88+
'_stylelint.config.js': 'linter.includes("stylelint")',
89+
'_commitlint.config.js': 'linter.includes("commitlint")'
8790
},
8891
templateDir
8992
})
@@ -97,6 +100,7 @@ module.exports = {
97100
'_.eslintrc.js': '.eslintrc.js',
98101
'_jsconfig.json': 'jsconfig.json',
99102
'_stylelint.config.js': 'stylelint.config.js',
103+
'_commitlint.config.js': 'commitlint.config.js',
100104
'semantic.yml': '.github/semantic.yml'
101105
}
102106
})

packages/create-nuxt-app/test/snapshots/index.test.js.md

+114-1
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,115 @@ Generated by [AVA](https://avajs.dev).
11041104
}␊
11051105
`
11061106

1107+
## verify linter: Commitlint
1108+
1109+
> Generated files
1110+
1111+
[
1112+
'.editorconfig',
1113+
'.gitignore',
1114+
'README.md',
1115+
'assets/README.md',
1116+
'commitlint.config.js',
1117+
'components/Logo.vue',
1118+
'components/README.md',
1119+
'layouts/README.md',
1120+
'layouts/default.vue',
1121+
'middleware/README.md',
1122+
'nuxt.config.js',
1123+
'package.json',
1124+
'pages/README.md',
1125+
'pages/index.vue',
1126+
'plugins/README.md',
1127+
'static/README.md',
1128+
'static/favicon.ico',
1129+
'store/README.md',
1130+
]
1131+
1132+
> package.json
1133+
1134+
{
1135+
dependencies: {
1136+
'core-js': '^3.6.5',
1137+
nuxt: '^2.14.0',
1138+
},
1139+
devDependencies: {
1140+
'@commitlint/cli': '^9.1.2',
1141+
'@commitlint/config-conventional': '^9.1.2',
1142+
},
1143+
private: true,
1144+
scripts: {
1145+
build: 'nuxt build',
1146+
dev: 'nuxt',
1147+
generate: 'nuxt generate',
1148+
start: 'nuxt start',
1149+
},
1150+
}
1151+
1152+
> Generated nuxt.config.js
1153+
1154+
`␊
1155+
export default {␊
1156+
/*␊
1157+
** Nuxt rendering mode␊
1158+
** See https://nuxtjs.org/api/configuration-mode␊
1159+
*/␊
1160+
mode: 'universal',␊
1161+
/*␊
1162+
** Nuxt target␊
1163+
** See https://nuxtjs.org/api/configuration-target␊
1164+
*/␊
1165+
target: 'server',␊
1166+
/*␊
1167+
** Headers of the page␊
1168+
** See https://nuxtjs.org/api/configuration-head␊
1169+
*/␊
1170+
head: {␊
1171+
title: process.env.npm_package_name || '',␊
1172+
meta: [␊
1173+
{ charset: 'utf-8' },␊
1174+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
1175+
{ hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊
1176+
],␊
1177+
link: [␊
1178+
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
1179+
]␊
1180+
},␊
1181+
/*␊
1182+
** Global CSS␊
1183+
*/␊
1184+
css: [␊
1185+
],␊
1186+
/*␊
1187+
** Plugins to load before mounting the App␊
1188+
** https://nuxtjs.org/guide/plugins␊
1189+
*/␊
1190+
plugins: [␊
1191+
],␊
1192+
/*␊
1193+
** Auto import components␊
1194+
** See https://nuxtjs.org/api/configuration-components␊
1195+
*/␊
1196+
components: true,␊
1197+
/*␊
1198+
** Nuxt.js dev-modules␊
1199+
*/␊
1200+
buildModules: [␊
1201+
],␊
1202+
/*␊
1203+
** Nuxt.js modules␊
1204+
*/␊
1205+
modules: [␊
1206+
],␊
1207+
/*␊
1208+
** Build configuration␊
1209+
** See https://nuxtjs.org/api/configuration-build/␊
1210+
*/␊
1211+
build: {␊
1212+
}␊
1213+
}␊
1214+
`
1215+
11071216
## verify linter: ESLint
11081217

11091218
> Generated files
@@ -1220,7 +1329,7 @@ Generated by [AVA](https://avajs.dev).
12201329
}␊
12211330
`
12221331

1223-
## verify linter: ESLint, Prettier, Lint staged files, StyleLint
1332+
## verify linter: ESLint, Prettier, Lint staged files, StyleLint, Commitlint
12241333

12251334
> Generated files
12261335
@@ -1231,6 +1340,7 @@ Generated by [AVA](https://avajs.dev).
12311340
'.prettierrc',
12321341
'README.md',
12331342
'assets/README.md',
1343+
'commitlint.config.js',
12341344
'components/Logo.vue',
12351345
'components/README.md',
12361346
'layouts/README.md',
@@ -1255,6 +1365,8 @@ Generated by [AVA](https://avajs.dev).
12551365
nuxt: '^2.14.0',
12561366
},
12571367
devDependencies: {
1368+
'@commitlint/cli': '^9.1.2',
1369+
'@commitlint/config-conventional': '^9.1.2',
12581370
'@nuxtjs/eslint-config': '^3.1.0',
12591371
'@nuxtjs/eslint-module': '^2.0.0',
12601372
'@nuxtjs/stylelint-module': '^4.0.0',
@@ -1272,6 +1384,7 @@ Generated by [AVA](https://avajs.dev).
12721384
},
12731385
husky: {
12741386
hooks: {
1387+
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
12751388
'pre-commit': 'lint-staged',
12761389
},
12771390
},
Binary file not shown.

0 commit comments

Comments
 (0)