commitlint.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const fs = require('fs');
  2. const path = require('path');
  3. const { execSync } = require('child_process');
  4. const scopes = fs
  5. .readdirSync(path.resolve(__dirname, 'src'), { withFileTypes: true })
  6. .filter((dirent) => dirent.isDirectory())
  7. .map((dirent) => dirent.name.replace(/s$/, ''));
  8. // precomputed scope
  9. const scopeComplete = execSync('git status --porcelain || true')
  10. .toString()
  11. .trim()
  12. .split('\n')
  13. .find((r) => ~r.indexOf('M src'))
  14. ?.replace(/(\/)/g, '%%')
  15. ?.match(/src%%((\w|-)*)/)?.[1]
  16. ?.replace(/s$/, '');
  17. /** @type {import('cz-git').UserConfig} */
  18. module.exports = {
  19. ignores: [(commit) => commit.includes('init')],
  20. extends: ['@commitlint/config-conventional'],
  21. rules: {
  22. 'body-leading-blank': [2, 'always'],
  23. 'footer-leading-blank': [1, 'always'],
  24. 'header-max-length': [2, 'always', 108],
  25. 'subject-empty': [2, 'never'],
  26. 'type-empty': [2, 'never'],
  27. 'subject-case': [0],
  28. 'type-enum': [
  29. 2,
  30. 'always',
  31. [
  32. 'feat',
  33. 'fix',
  34. 'perf',
  35. 'style',
  36. 'docs',
  37. 'test',
  38. 'refactor',
  39. 'build',
  40. 'ci',
  41. 'chore',
  42. 'revert',
  43. 'wip',
  44. 'workflow',
  45. 'types',
  46. 'release',
  47. ],
  48. ],
  49. },
  50. prompt: {
  51. /** @use `yarn commit :f` */
  52. alias: {
  53. f: 'docs: fix typos',
  54. r: 'docs: update README',
  55. s: 'style: update code format',
  56. b: 'build: bump dependencies',
  57. c: 'chore: update config',
  58. },
  59. customScopesAlign: !scopeComplete ? 'top' : 'bottom',
  60. defaultScope: scopeComplete,
  61. scopes: [...scopes, 'mock'],
  62. allowEmptyIssuePrefixs: false,
  63. allowCustomIssuePrefixs: false,
  64. // English
  65. typesAppend: [
  66. { value: 'wip', name: 'wip: work in process' },
  67. { value: 'workflow', name: 'workflow: workflow improvements' },
  68. { value: 'types', name: 'types: type definition file changes' },
  69. ],
  70. // 中英文对照版
  71. // messages: {
  72. // type: '选择你要提交的类型 :',
  73. // scope: '选择一个提交范围 (可选):',
  74. // customScope: '请输入自定义的提交范围 :',
  75. // subject: '填写简短精炼的变更描述 :\n',
  76. // body: '填写更加详细的变更描述 (可选)。使用 "|" 换行 :\n',
  77. // breaking: '列举非兼容性重大的变更 (可选)。使用 "|" 换行 :\n',
  78. // footerPrefixsSelect: '选择关联issue前缀 (可选):',
  79. // customFooterPrefixs: '输入自定义issue前缀 :',
  80. // footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
  81. // confirmCommit: '是否提交或修改commit ?',
  82. // },
  83. // types: [
  84. // { value: 'feat', name: 'feat: 新增功能' },
  85. // { value: 'fix', name: 'fix: 修复缺陷' },
  86. // { value: 'docs', name: 'docs: 文档变更' },
  87. // { value: 'style', name: 'style: 代码格式' },
  88. // { value: 'refactor', name: 'refactor: 代码重构' },
  89. // { value: 'perf', name: 'perf: 性能优化' },
  90. // { value: 'test', name: 'test: 添加疏漏测试或已有测试改动' },
  91. // { value: 'build', name: 'build: 构建流程、外部依赖变更 (如升级 npm 包、修改打包配置等)' },
  92. // { value: 'ci', name: 'ci: 修改 CI 配置、脚本' },
  93. // { value: 'revert', name: 'revert: 回滚 commit' },
  94. // { value: 'chore', name: 'chore: 对构建过程或辅助工具和库的更改 (不影响源文件、测试用例)' },
  95. // { value: 'wip', name: 'wip: 正在开发中' },
  96. // { value: 'workflow', name: 'workflow: 工作流程改进' },
  97. // { value: 'types', name: 'types: 类型定义文件修改' },
  98. // ],
  99. // emptyScopesAlias: 'empty: 不填写',
  100. // customScopesAlias: 'custom: 自定义',
  101. },
  102. };