verifyCommit.js 904 B

12345678910111213141516171819202122232425262728
  1. // @ts-check
  2. import chalk from 'chalk'
  3. import { readFileSync } from 'fs'
  4. import path from 'path'
  5. const msgPath = path.resolve('.git/COMMIT_EDITMSG')
  6. const msg = readFileSync(msgPath, 'utf-8').trim()
  7. const commitRE =
  8. /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
  9. if (!commitRE.test(msg)) {
  10. console.log()
  11. console.error(
  12. ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
  13. `invalid commit message format.`
  14. )}\n\n` +
  15. chalk.red(
  16. ` Proper commit message format is required for automated changelog generation. Examples:\n\n`
  17. ) +
  18. ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
  19. ` ${chalk.green(
  20. `fix(v-model): handle events on blur (close #28)`
  21. )}\n\n` +
  22. chalk.red(` See .github/commit-convention.md for more details.\n`)
  23. )
  24. process.exit(1)
  25. }