vue3-core/scripts/verify-commit.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
922 B
JavaScript
Raw Normal View History

// @ts-check
2023-10-20 10:23:18 +08:00
import pico from 'picocolors'
import { readFileSync } from 'node:fs'
import path from 'node:path'
2018-09-19 23:35:38 +08:00
const msgPath = path.resolve('.git/COMMIT_EDITMSG')
const msg = readFileSync(msgPath, 'utf-8').trim()
2018-09-19 23:35:38 +08:00
const commitRE =
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
2018-09-19 23:35:38 +08:00
if (!commitRE.test(msg)) {
console.log()
console.error(
2023-10-20 10:23:18 +08:00
` ${pico.white(pico.bgRed(' ERROR '))} ${pico.red(
2018-09-19 23:35:38 +08:00
`invalid commit message format.`,
)}\n\n` +
2023-10-20 10:23:18 +08:00
pico.red(
2018-09-19 23:35:38 +08:00
` Proper commit message format is required for automated changelog generation. Examples:\n\n`,
) +
2023-10-20 10:23:18 +08:00
` ${pico.green(`feat(compiler): add 'comments' option`)}\n` +
` ${pico.green(
2018-09-19 23:35:38 +08:00
`fix(v-model): handle events on blur (close #28)`,
)}\n\n` +
2023-10-20 10:23:18 +08:00
pico.red(` See .github/commit-convention.md for more details.\n`),
2018-09-19 23:35:38 +08:00
)
process.exit(1)
}