.commitlintrc.cjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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: '选择你要提交的类型 :',
  72. // scope: '选择一个提交范围 (可选):',
  73. // customScope: '请输入自定义的提交范围 :',
  74. // subject: '填写简短精炼的变更描述 :\n',
  75. // body: '填写更加详细的变更描述 (可选)。使用 "|" 换行 :\n',
  76. // breaking: '列举非兼容性重大的变更 (可选)。使用 "|" 换行 :\n',
  77. // footerPrefixsSelect: '选择关联issue前缀 (可选):',
  78. // customFooterPrefixs: '输入自定义issue前缀 :',
  79. // footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
  80. // confirmCommit: '是否提交或修改commit ?',
  81. // },
  82. // types: [
  83. // { value: 'feat', name: 'feat: 新增功能' },
  84. // { value: 'fix', name: 'fix: 修复缺陷' },
  85. // { value: 'docs', name: 'docs: 文档变更' },
  86. // { value: 'style', name: 'style: 代码格式' },
  87. // { value: 'refactor', name: 'refactor: 代码重构' },
  88. // { value: 'perf', name: 'perf: 性能优化' },
  89. // { value: 'test', name: 'test: 添加疏漏测试或已有测试改动' },
  90. // { value: 'build', name: 'build: 构建流程、外部依赖变更 (如升级 npm 包、修改打包配置等)' },
  91. // { value: 'ci', name: 'ci: 修改 CI 配置、脚本' },
  92. // { value: 'revert', name: 'revert: 回滚 commit' },
  93. // { value: 'chore', name: 'chore: 对构建过程或辅助工具和库的更改 (不影响源文件、测试用例)' },
  94. // { value: 'wip', name: 'wip: 正在开发中' },
  95. // { value: 'workflow', name: 'workflow: 工作流程改进' },
  96. // { value: 'types', name: 'types: 类型定义文件修改' },
  97. // ],
  98. // emptyScopesAlias: 'empty: 不填写',
  99. // customScopesAlias: 'custom: 自定义',
  100. },
  101. }