.commitlintrc.cjs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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': [0],
  25. 'type-empty': [0],
  26. 'subject-case': [0],
  27. 'type-enum': [
  28. 2,
  29. 'always',
  30. [
  31. '🎉 init',
  32. '✨ feat',
  33. '🐞 fix',
  34. '🎈 perf',
  35. '🌈 style',
  36. '📃 docs',
  37. '🧪 test',
  38. '🦄 refactor',
  39. '🔧 build',
  40. '🐎 ci',
  41. '🐳 chore',
  42. ],
  43. ],
  44. },
  45. prompt: {
  46. /** @use `pnpm commit :f` */
  47. alias: {
  48. f: 'docs: fix typos',
  49. r: 'docs: update README',
  50. s: 'style: update code format',
  51. b: 'build: bump dependencies',
  52. c: 'chore: update config',
  53. },
  54. customScopesAlign: !scopeComplete ? 'top' : 'bottom',
  55. defaultScope: scopeComplete,
  56. scopes: [...scopes, 'mock'],
  57. allowEmptyIssuePrefixs: false,
  58. allowCustomIssuePrefixs: false,
  59. // 中英文对照版
  60. // messages: {
  61. // type: '选择你要提交的类型 :',
  62. // scope: '选择一个提交范围 (可选):',
  63. // customScope: '请输入自定义的提交范围 :',
  64. // subject: '填写简短精炼的变更描述 :\n',
  65. // body: '填写更加详细的变更描述 (可选)。使用 "|" 换行 :\n',
  66. // breaking: '列举非兼容性重大的变更 (可选)。使用 "|" 换行 :\n',
  67. // footerPrefixsSelect: '选择关联issue前缀 (可选):',
  68. // customFooterPrefixs: '输入自定义issue前缀 :',
  69. // footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
  70. // confirmCommit: '是否提交或修改commit ?',
  71. // },
  72. // types: [
  73. // { value: 'feat', name: 'feat: 新增功能' },
  74. // { value: 'fix', name: 'fix: 修复缺陷' },
  75. // { value: 'docs', name: 'docs: 文档变更' },
  76. // { value: 'style', name: 'style: 代码格式' },
  77. // { value: 'refactor', name: 'refactor: 代码重构' },
  78. // { value: 'perf', name: 'perf: 性能优化' },
  79. // { value: 'test', name: 'test: 添加疏漏测试或已有测试改动' },
  80. // { value: 'build', name: 'build: 构建流程、外部依赖变更 (如升级 npm 包、修改打包配置等)' },
  81. // { value: 'ci', name: 'ci: 修改 CI 配置、脚本' },
  82. // { value: 'revert', name: 'revert: 回滚 commit' },
  83. // { value: 'chore', name: 'chore: 对构建过程或辅助工具和库的更改 (不影响源文件、测试用例)' },
  84. // { value: 'wip', name: 'wip: 正在开发中' },
  85. // { value: 'workflow', name: 'workflow: 工作流程改进' },
  86. // { value: 'types', name: 'types: 类型定义文件修改' },
  87. // ],
  88. // emptyScopesAlias: 'empty: 不填写',
  89. // customScopesAlias: 'custom: 自定义',
  90. },
  91. }