forked from hunghg255/verify-commit-msg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
24 lines (21 loc) · 902 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env node
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const msgPath = path.resolve('.git/COMMIT_EDITMSG');
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)(\(.+\))?(\:|\!\:) .{1,50}/;
if (!commitRE.test(msg)) {
console.log();
console.error(
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` +
chalk.yellow(
` Proper commit message format is required for automated changelog generation. Examples:\n\n`,
) +
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
` ${chalk.green(`fix(modal): handle events on blur (close #28)`)}\n\n` +
chalk.yellow(` See .github/commit-convention.md for more details.\n`),
);
process.exit(1);
}