electron-vite/scripts/verifyCommit.js

23 lines
858 B
JavaScript
Raw Normal View History

2022-03-17 09:21:02 +01:00
// Invoked on the commit-msg git hook by simple-git-hooks.
2023-12-08 15:03:47 +01:00
import colors from 'picocolors'
import fs from 'node:fs'
2022-03-17 09:21:02 +01:00
const msgPath = process.argv[2]
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(
2022-05-26 17:04:36 +02:00
` ${colors.bgRed(colors.white(' ERROR '))} ${colors.red(`invalid commit message format.`)}\n\n` +
2022-03-17 09:21:02 +01:00
colors.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
` ${colors.green(`feat: add 'comments' option`)}\n` +
` ${colors.green(`fix: handle events on blur (close #28)`)}\n\n` +
colors.red(` See .github/commit-convention.md for more details.\n`)
)
process.exit(1)
}