UNPKG

915 BJavaScriptView Raw
1const chalk = require('chalk')
2const msgPath = process.env.GIT_PARAMS
3const msg = require('fs').readFileSync(msgPath, 'utf-8').trim()
4
5const commitRE = /^(revert: )?(init|feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build)(\(.+\))?: .{1,50}/
6
7if (!commitRE.test(msg)) {
8 console.log()
9 console.error(
10 ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
11 chalk.red(` Proper commit message format is required for automated changelog generation. Examples:\n\n`) +
12 ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
13 ` ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` +
14 chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`) +
15 chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
16 )
17 process.exit(1)
18}