diff --git a/.cz-config.js b/.cz-config.js index 43509db..1e093c9 100644 --- a/.cz-config.js +++ b/.cz-config.js @@ -1,34 +1,31 @@ module.exports = { - //可选类型 - types: [ - { value: 'feat', name: 'feat: 新功能' }, - { value: 'fix', name: 'fix: 修复' }, - { value: 'docs', name: 'docs: 文档变更' }, - { value: 'style', name: 'style: 代码格式(不影响代码运行的变动)' }, - { - value: 'refactor', - name: 'refactor:重构(既不是增加feature),也不是修复bug' - }, - { value: 'perf', name: 'perf: 性能优化' }, - { value: 'test', name: 'test: 增加测试' }, - { value: 'chore', name: 'chore: 构建过程或辅助功能的变动' }, - { value: 'revert', name: 'revert: 回退' }, - { value: 'build', name: 'build: 打包' }, - { value: 'revert', name: 'revert: 回退' } - ], - //消息步骤 - messages: { - type: '请选择提交类型', - customScope: '请输入修改范围(可选)', - subject: '请简要描述提交(必填)', - body: '请输入详细描述(可选)', - footer: '请输入要关闭的issue(可选)', - confirmCommit: '确认以上信息提交?(y/n)' + // 可选类型 + types: [ + { value: 'feat', name: 'feat: 新功能' }, + { value: 'fix', name: 'fix: 修复' }, + { value: 'docs', name: 'docs: 文档变更' }, + { value: 'style', name: 'style: 代码格式(不影响代码运行的变动)' }, + { + value: 'refactor', + name: 'refactor: 重构(既不是增加feature,也不是修复bug)' }, - //跳过问题 - skipQuestion: ['body', 'footer'], - //subject文字长度默认是 - subjectLimit: 72 - } - - \ No newline at end of file + { value: 'perf', name: 'perf: 性能优化' }, + { value: 'test', name: 'test: 增加测试' }, + { value: 'chore', name: 'chore: 构建过程或辅助工具的变动' }, + { value: 'revert', name: 'revert: 回退' }, + { value: 'build', name: 'build: 打包' } + ], + // 消息步骤 + messages: { + type: '请选择提交类型:', + customScope: '请输入修改范围(可选):', + subject: '请简要描述提交(必填):', + body: '请输入详细描述(可选):', + footer: '请输入要关闭的issue(可选):', + confirmCommit: '确认使用以上信息提交?(y/n/e/h)' + }, + // 跳过问题 + skipQuestions: ['body', 'footer'], + // subject文字长度默认是72 + subjectLimit: 72 +} diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 0000000..7cd8dd9 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx --no-install commitlint --edit diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..a3e6680 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,26 @@ +module.exports = { + // 继承的规则 + extends: ['@commitlint/config-conventional'], + // 定义规则类型 + rules: { + // type 类型定义,表示 git 提交的 type 必须在以下类型范围内 + 'type-enum': [ + 2, + 'always', + [ + 'feat', // 新功能 feature + 'fix', // 修复 bug + 'docs', // 文档注释 + 'style', // 代码格式(不影响代码运行的变动) + 'refactor', // 重构(既不增加新功能,也不是修复bug) + 'perf', // 性能优化 + 'test', // 增加测试 + 'chore', // 构建过程或辅助工具的变动 + 'revert', // 回退 + 'build' // 打包 + ] + ], + // subject 大小写不做校验 + 'subject-case': [0] + } +} diff --git a/package.json b/package.json index 55aaad9..a778df8 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", - "lint": "vue-cli-service lint" + "lint": "vue-cli-service lint", + "prepare": "husky install" }, "dependencies": { "axios": "^0.27.2", @@ -17,6 +18,8 @@ "devDependencies": { "@babel/core": "^7.12.16", "@babel/eslint-parser": "^7.12.16", + "@commitlint/cli": "^12.1.4", + "@commitlint/config-conventional": "^12.1.4", "@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-eslint": "~5.0.0", "@vue/cli-plugin-router": "~5.0.0", @@ -29,6 +32,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", "eslint-plugin-vue": "^8.0.3", + "husky": "^7.0.1", "sass": "^1.32.7", "sass-loader": "^12.0.0" },