verify-commit.js 913 B

12345678910111213141516171819202122232425
  1. // eslint-disable-next-line @typescript-eslint/no-var-requires
  2. const chalk = require("chalk");
  3. const msgPath = process.env.HUSKY_GIT_PARAMS;
  4. // eslint-disable-next-line @typescript-eslint/no-var-requires
  5. const msg = require("fs").readFileSync(msgPath, "utf-8").trim();
  6. const commitRE =
  7. /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/;
  8. if (!commitRE.test(msg)) {
  9. console.error(
  10. ` ${chalk.bgRed.white(" ERROR ")} ${chalk.red(
  11. "不合法的 commit 消息格式"
  12. )}\n\n` +
  13. chalk.red(" 请使用正确的提交格式:\n\n") +
  14. ` ${chalk.green("feat: add 'comments' option")}\n` +
  15. ` ${chalk.green("fix: handle events on blur (close #28)")}\n\n` +
  16. chalk.red(
  17. " 请查看 git commit 提交规范:https://github.com/vuejs/vue/blob/dev/.github/COMMIT_CONVENTION.md \n"
  18. )
  19. );
  20. process.exit(1);
  21. }