|
1 |
| -// Invoked on the commit-msg git hook by yorkie. |
| 1 | +// @ts-check |
| 2 | +import { readFileSync } from 'node:fs' |
| 3 | +import path from 'node:path' |
2 | 4 |
|
3 |
| -import chalk from 'chalk' |
4 |
| -const msgPath = process.env.GIT_PARAMS |
5 |
| -import { readFile } from 'fs/promises' |
| 5 | +// Define raw escape codes for colors |
| 6 | +const reset = '\x1b[0m' |
| 7 | +const red = '\x1b[31m' |
| 8 | +const green = '\x1b[32m' |
| 9 | +const bgRedWhite = '\x1b[41m\x1b[37m' |
6 | 10 |
|
7 |
| -async function main() { |
8 |
| - const msg = (await readFile(msgPath, 'utf-8')).trim() |
| 11 | +const msgPath = path.resolve('.git/COMMIT_EDITMSG') |
| 12 | +const msg = readFileSync(msgPath, 'utf-8').trim() |
9 | 13 |
|
10 |
| - const commitRE = |
11 |
| - /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ |
| 14 | +const commitRE = |
| 15 | + /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ |
12 | 16 |
|
13 |
| - if (!commitRE.test(msg)) { |
14 |
| - console.log() |
15 |
| - console.error( |
16 |
| - ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red( |
17 |
| - `invalid commit message format.` |
18 |
| - )}\n\n` + |
19 |
| - chalk.red( |
20 |
| - ` Proper commit message format is required for automated changelog generation. Examples:\n\n` |
21 |
| - ) + |
22 |
| - ` ${chalk.green( |
23 |
| - `fix(view): handle keep-alive with aborted navigations` |
24 |
| - )}\n` + |
25 |
| - ` ${chalk.green( |
26 |
| - `fix(view): handle keep-alive with aborted navigations (close #28)` |
27 |
| - )}\n\n` + |
28 |
| - chalk.red(` See .github/commit-convention.md for more details.\n`) |
29 |
| - ) |
30 |
| - process.exit(1) |
31 |
| - } |
| 17 | +if (!commitRE.test(msg)) { |
| 18 | + console.log() |
| 19 | + console.error( |
| 20 | + ` ${bgRedWhite} ERROR ${reset} ${red}invalid commit message format.${reset}\n\n` + |
| 21 | + `${red} Proper commit message format is required for automated changelog generation. Examples:\n\n` + |
| 22 | + ` ${green}feat: add disableRoot option${reset}\n` + |
| 23 | + ` ${green}fix(view): handle keep-alive with aborted navigations (close #28)${reset}\n\n` + |
| 24 | + `${red} See .github/commit-convention.md for more details.${reset}\n` |
| 25 | + ) |
| 26 | + process.exit(1) |
32 | 27 | }
|
33 |
| - |
34 |
| -main() |
0 commit comments