chore: add verify commit script

This commit is contained in:
程沛权 2021-06-16 11:28:37 +08:00
parent 708a418598
commit 6e29068e95
3 changed files with 30 additions and 19 deletions

View File

@ -1,17 +0,0 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
['upd', 'feat', 'fix', 'refactor', 'docs', 'chore', 'style', 'revert'],
],
'type-case': [0],
'type-empty': [0],
'scope-empty': [0],
'scope-case': [0],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never'],
'header-max-length': [0, 'always', 72],
},
}

View File

@ -42,6 +42,7 @@
"@types/babel__core": "^7.1.9",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"chalk": "^4.1.1",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
@ -57,8 +58,8 @@
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E $HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
"pre-commit": "lint-staged",
"commit-msg": "node scripts/verifyCommit.js"
}
},
"lint-staged": {

27
scripts/verifyCommit.js Normal file
View File

@ -0,0 +1,27 @@
// Invoked on the commit-msg git hook by yorkie.
const fs = require('fs')
const chalk = require('chalk')
const msgPath = process.env.HUSKY_GIT_PARAMS
const msg = fs.readFileSync(msgPath, 'utf-8').trim()
const commitRE =
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
if (!commitRE.test(msg)) {
console.log()
console.error(
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
`invalid commit message format.`
)}\n\n` +
chalk.red(
` Proper commit message format is required for automated changelog generation. Examples:\n\n`
) +
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
` ${chalk.green(
`fix(v-model): handle events on blur (close #28)`
)}\n\n` +
chalk.red(` See .github/commit-convention.md for more details.\n`)
)
process.exit(1)
}