.commitlintrc.cjs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. useEmoji: false,
  52. emojiAlign: 'center',
  53. useAI: false,
  54. aiNumber: 1,
  55. themeColorCode: '',
  56. scopes: [],
  57. allowCustomScopes: true,
  58. allowEmptyScopes: true,
  59. customScopesAlign: 'bottom',
  60. customScopesAlias: 'custom',
  61. emptyScopesAlias: 'empty',
  62. upperCaseSubject: false,
  63. markBreakingChangeMode: false,
  64. allowBreakingChanges: ['feat', 'fix'],
  65. breaklineNumber: 100,
  66. breaklineChar: '|',
  67. skipQuestions: [],
  68. issuePrefixes: [{ value: 'closed', name: 'closed: ISSUES has been processed' }],
  69. customIssuePrefixAlign: 'top',
  70. emptyIssuePrefixAlias: 'skip',
  71. customIssuePrefixAlias: 'custom',
  72. allowCustomIssuePrefix: true,
  73. allowEmptyIssuePrefix: true,
  74. confirmColorize: true,
  75. minSubjectLength: 0,
  76. defaultBody: '',
  77. defaultIssues: '',
  78. defaultScope: '',
  79. defaultSubject: '',
  80. // 中英文对照版
  81. messages: {
  82. type: "选择你要提交的类型 | Select the type of change that you're committing:",
  83. scope: '选择一个提交范围(可选) | Denote the SCOPE of this change (optional):',
  84. customScope: '请输入自定义的提交范围 | Denote the SCOPE of this change:',
  85. subject:
  86. '填写简短精炼的变更描述 | Write a SHORT, IMPERATIVE tense description of the change:\n',
  87. body: '填写更加详细的变更描述(可选)。使用 \'|\' 换行 | Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
  88. breaking:
  89. '列举非兼容性重大的变更(可选)。使用 \'|\' 换行 | List any BREAKING CHANGES (optional). Use "|" to break new line:\n',
  90. footerPrefixesSelect:
  91. '选择关联issue前缀(可选) | Select the ISSUES type of changeList by this change (optional):',
  92. customFooterPrefix: '输入自定义issue前缀 | Input ISSUES prefix:',
  93. footer:
  94. '列举关联issue (可选) 例如: #31, #I3244 | List any ISSUES by this change. E.g.: #31, #34:\n',
  95. generatingByAI: 'Generating your AI commit subject...',
  96. generatedSelectByAI: 'Select suitable subject by AI generated:',
  97. confirmCommit:
  98. '是否提交或修改commit? | Are you sure you want to proceed with the commit above?',
  99. },
  100. types: [
  101. { value: 'feat', name: 'feat: 新增功能 | A new feature', emoji: ':sparkles:' },
  102. { value: 'fix', name: 'fix: 修复缺陷 | A bug fix', emoji: ':bug:' },
  103. { value: 'docs', name: 'docs: 文档更新 | Documentation only changes', emoji: ':memo:' },
  104. {
  105. value: 'style',
  106. name: 'style: 代码格式 | Changes that do not affect the meaning of the code',
  107. emoji: ':lipstick:',
  108. },
  109. {
  110. value: 'refactor',
  111. name: 'refactor: 代码重构 | A code change that neither fixes a bug nor adds a feature',
  112. emoji: ':recycle:',
  113. },
  114. {
  115. value: 'perf',
  116. name: 'perf: 性能提升 | A code change that improves performance',
  117. emoji: ':zap:',
  118. },
  119. {
  120. value: 'test',
  121. name: 'test: 测试相关 | Adding missing tests or correcting existing tests',
  122. emoji: ':white_check_mark:',
  123. },
  124. {
  125. value: 'build',
  126. name: 'build: 构建相关 | Changes that affect the build system or external dependencies',
  127. emoji: ':package:',
  128. },
  129. {
  130. value: 'ci',
  131. name: 'ci: 持续集成 | Changes to our CI configuration files and scripts',
  132. emoji: ':ferris_wheel:',
  133. },
  134. {
  135. value: 'chore',
  136. name: 'chore: 其他修改 | Other changes that do not modify src or test files',
  137. emoji: ':hammer:',
  138. },
  139. { value: 'revert', name: 'revert: 回退代码 | Revert to a commit', emoji: ':rewind:' },
  140. ],
  141. // emptyScopesAlias: 'empty: 不填写',
  142. // customScopesAlias: 'custom: 自定义',
  143. },
  144. }