commitlint.config.cjs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // commitlint.config.js
  2. const fs = require('node:fs')
  3. const path = require('node:path')
  4. const { execSync } = require('node:child_process')
  5. const scopes = fs
  6. .readdirSync(path.resolve(__dirname, 'src'), { withFileTypes: true })
  7. .filter(dirent => dirent.isDirectory())
  8. .map(dirent => dirent.name.replace(/s$/, ''))
  9. // precomputed scope
  10. const scopeComplete = execSync('git status --porcelain || true')
  11. .toString()
  12. .trim()
  13. .split('\n')
  14. .find(r => ~r.indexOf('M src'))
  15. ?.replace(/(\/)/g, '%%')
  16. ?.match(/src%%((\w|-)*)/)?.[1]
  17. ?.replace(/s$/, '')
  18. /** @type {import('cz-git').UserConfig} */
  19. module.exports = {
  20. ignores: [commit => commit.includes('init')],
  21. extends: ['@commitlint/config-conventional'],
  22. rules: {
  23. 'body-leading-blank': [2, 'always'],
  24. 'footer-leading-blank': [1, 'always'],
  25. 'header-max-length': [2, 'always', 108],
  26. 'subject-empty': [2, 'never'],
  27. 'type-empty': [2, 'never'],
  28. 'subject-case': [0],
  29. 'type-enum': [
  30. 2,
  31. 'always',
  32. [
  33. 'feat',
  34. 'fix',
  35. 'perf',
  36. 'style',
  37. 'docs',
  38. 'test',
  39. 'refactor',
  40. 'build',
  41. 'ci',
  42. 'chore',
  43. 'revert',
  44. 'wip',
  45. 'workflow',
  46. 'types',
  47. 'release',
  48. ],
  49. ],
  50. },
  51. prompt: {
  52. /** @use `yarn commit :f` */
  53. alias: {
  54. f: 'docs: fix typos',
  55. r: 'docs: update README',
  56. s: 'style: update code format',
  57. b: 'build: bump dependencies',
  58. c: 'chore: update config',
  59. },
  60. customScopesAlign: !scopeComplete ? 'top' : 'bottom',
  61. defaultScope: scopeComplete,
  62. scopes: [...scopes, 'mock'],
  63. allowEmptyIssuePrefixs: true,
  64. allowCustomIssuePrefixs: true,
  65. messages: {
  66. type: '选择你要提交的类型 :',
  67. scope: '选择一个提交范围(可选):',
  68. customScope: '请输入自定义的提交范围 :',
  69. subject: '填写简短精炼的变更描述 :\n',
  70. body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
  71. breaking: '列举非兼容性重大的变更(可选)。使用 "|" 换行 :\n',
  72. footerPrefixsSelect: '选择关联issue前缀(可选):',
  73. customFooterPrefixs: '输入自定义issue前缀 :',
  74. footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
  75. confirmCommit: '是否提交或修改commit ?',
  76. },
  77. types: [
  78. { value: 'feat', name: 'feat: ✨ 新增功能 | A new feature', emoji: ':sparkles:' },
  79. { value: 'fix', name: 'fix: 🐛 修复缺陷 | A bug fix', emoji: ':bug:' },
  80. {
  81. value: 'docs',
  82. name: 'docs: 📝 文档更新 | Documentation only changes',
  83. emoji: ':memo:',
  84. },
  85. {
  86. value: 'style',
  87. name: 'style: 💄 代码格式 | Changes that do not affect the meaning of the code',
  88. emoji: ':lipstick:',
  89. },
  90. {
  91. value: 'refactor',
  92. name: 'refactor: ♻️ 代码重构 | A code change that neither fixes a bug nor adds a feature',
  93. emoji: ':recycle:',
  94. },
  95. {
  96. value: 'perf',
  97. name: 'perf: ⚡️ 性能提升 | A code change that improves performance',
  98. emoji: ':zap:',
  99. },
  100. {
  101. value: 'test',
  102. name: 'test: ✅ 测试相关 | Adding missing tests or correcting existing tests',
  103. emoji: ':white_check_mark:',
  104. },
  105. {
  106. value: 'build',
  107. name: 'build: 📦️ 构建相关 | Changes that affect the build system or external dependencies',
  108. emoji: ':package:',
  109. },
  110. {
  111. value: 'ci',
  112. name: 'ci: 🎡 持续集成 | Changes to our CI configuration files and scripts',
  113. emoji: ':ferris_wheel:',
  114. },
  115. { value: 'revert', name: 'revert: 🔨 回退代码 | Revert to a commit', emoji: ':hammer:' },
  116. {
  117. value: 'chore',
  118. name: 'chore: ⏪️ 其他修改 | Other changes that do not modify src or test files',
  119. emoji: ':rewind:',
  120. },
  121. ],
  122. useEmoji: true,
  123. emojiAlign: 'center',
  124. themeColorCode: '',
  125. allowCustomScopes: true,
  126. allowEmptyScopes: true,
  127. customScopesAlias: 'custom',
  128. emptyScopesAlias: 'empty',
  129. upperCaseSubject: false,
  130. markBreakingChangeMode: false,
  131. allowBreakingChanges: ['feat', 'fix'],
  132. breaklineNumber: 100,
  133. breaklineChar: '|',
  134. skipQuestions: [],
  135. issuePrefixs: [
  136. // 如果使用 gitee 作为开发管理
  137. { value: 'link', name: 'link: 链接 ISSUES 进行中' },
  138. { value: 'closed', name: 'closed: 标记 ISSUES 已完成' },
  139. ],
  140. customIssuePrefixsAlign: 'top',
  141. emptyIssuePrefixsAlias: 'skip',
  142. customIssuePrefixsAlias: 'custom',
  143. confirmColorize: true,
  144. maxHeaderLength: Number.POSITIVE_INFINITY,
  145. maxSubjectLength: Number.POSITIVE_INFINITY,
  146. minSubjectLength: 0,
  147. scopeOverrides: undefined,
  148. defaultBody: '',
  149. defaultIssues: '',
  150. defaultSubject: '',
  151. },
  152. }