.commitlintrc.cjs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. module.exports = {
  18. ignores: [(commit) => commit.includes('init')],
  19. extends: ['@commitlint/config-conventional'],
  20. rules: {
  21. 'body-leading-blank': [2, 'always'],
  22. 'footer-leading-blank': [1, 'always'],
  23. 'header-max-length': [2, 'always', 108],
  24. 'subject-empty': [2, 'never'],
  25. 'type-empty': [2, 'never'],
  26. 'subject-case': [0],
  27. // 'type-enum': [
  28. // 2,
  29. // 'always',
  30. // [
  31. // 'feat',
  32. // 'fix',
  33. // 'perf',
  34. // 'style',
  35. // 'docs',
  36. // 'test',
  37. // 'refactor',
  38. // 'build',
  39. // 'ci',
  40. // 'chore',
  41. // 'revert',
  42. // 'wip',
  43. // 'workflow',
  44. // 'types',
  45. // 'release',
  46. // ],
  47. // ],
  48. },
  49. prompt: {
  50. /** @use `pnpm commit :f` */
  51. alias: {
  52. f: 'docs: fix typos',
  53. r: 'docs: update README',
  54. s: 'style: update code format',
  55. b: 'build: bump dependencies',
  56. c: 'chore: update config',
  57. },
  58. customScopesAlign: !scopeComplete ? 'top' : 'bottom',
  59. defaultScope: scopeComplete,
  60. scopes: [...scopes, 'mock'],
  61. allowEmptyIssuePrefixs: false,
  62. allowCustomIssuePrefixs: false,
  63. // English
  64. typesAppend: [
  65. { value: 'wip', name: 'wip: work in process' },
  66. { value: 'workflow', name: 'workflow: workflow improvements' },
  67. { value: 'types', name: 'types: type definition file changes' },
  68. ],
  69. // 中英文对照版
  70. messages: {
  71. type: "选择你要提交的类型 | Select the type of change that you're committing:",
  72. scope: '选择一个提交范围(可选) | Denote the SCOPE of this change (optional):',
  73. customScope: '请输入自定义的提交范围 | Denote the SCOPE of this change:',
  74. subject:
  75. '填写简短精炼的变更描述 | Write a SHORT, IMPERATIVE tense description of the change:\n',
  76. body: '填写更加详细的变更描述(可选)。使用 \'|\' 换行 | Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
  77. breaking:
  78. '列举非兼容性重大的变更(可选)。使用 \'|\' 换行 | List any BREAKING CHANGES (optional). Use "|" to break new line:\n',
  79. footerPrefixesSelect:
  80. '选择关联issue前缀(可选) | Select the ISSUES type of changeList by this change (optional):',
  81. customFooterPrefix: '输入自定义issue前缀 | Input ISSUES prefix:',
  82. footer:
  83. '列举关联issue (可选) 例如: #31, #I3244 | List any ISSUES by this change. E.g.: #31, #34:\n',
  84. generatingByAI: 'Generating your AI commit subject...',
  85. generatedSelectByAI: 'Select suitable subject by AI generated:',
  86. confirmCommit:
  87. '是否提交或修改commit? | Are you sure you want to proceed with the commit above?',
  88. },
  89. types: [
  90. { value: 'feat', name: 'feat: 新增功能 | A new feature', emoji: ':sparkles:' },
  91. { value: 'fix', name: 'fix: 修复缺陷 | A bug fix', emoji: ':bug:' },
  92. { value: 'docs', name: 'docs: 文档更新 | Documentation only changes', emoji: ':memo:' },
  93. {
  94. value: 'style',
  95. name: 'style: 代码格式 | Changes that do not affect the meaning of the code',
  96. emoji: ':lipstick:',
  97. },
  98. {
  99. value: 'refactor',
  100. name: 'refactor: 代码重构 | A code change that neither fixes a bug nor adds a feature',
  101. emoji: ':recycle:',
  102. },
  103. {
  104. value: 'perf',
  105. name: 'perf: 性能提升 | A code change that improves performance',
  106. emoji: ':zap:',
  107. },
  108. {
  109. value: 'test',
  110. name: 'test: 测试相关 | Adding missing tests or correcting existing tests',
  111. emoji: ':white_check_mark:',
  112. },
  113. {
  114. value: 'build',
  115. name: 'build: 构建相关 | Changes that affect the build system or external dependencies',
  116. emoji: ':package:',
  117. },
  118. {
  119. value: 'ci',
  120. name: 'ci: 持续集成 | Changes to our CI configuration files and scripts',
  121. emoji: ':ferris_wheel:',
  122. },
  123. {
  124. value: 'chore',
  125. name: 'chore: 其他修改 | Other changes that do not modify src or test files',
  126. emoji: ':hammer:',
  127. },
  128. { value: 'revert', name: 'revert: 回退代码 | Revert to a commit', emoji: ':rewind:' },
  129. ],
  130. // emptyScopesAlias: 'empty: 不填写',
  131. // customScopesAlias: 'custom: 自定义',
  132. },
  133. }