index.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import type { UserConfig } from 'cz-git';
  2. import { execSync } from 'node:child_process';
  3. import { getPackagesSync } from '@vben/node-utils';
  4. const { packages } = getPackagesSync();
  5. const pkgs = packages.map((pkg) => {
  6. return pkg.packageJson.name?.replace('@vben-core/', '');
  7. });
  8. const scopes = [
  9. ...pkgs,
  10. 'project',
  11. 'style',
  12. 'lint',
  13. 'ci',
  14. 'dev',
  15. 'deploy',
  16. 'other',
  17. ];
  18. // precomputed scope
  19. const scopeComplete = execSync('git status --porcelain || true')
  20. .toString()
  21. .trim()
  22. .split('\n')
  23. .find((r) => ~r.indexOf('M src'))
  24. ?.replace(/(\/)/g, '%%')
  25. ?.match(/src%%((\w|-)*)/)?.[1]
  26. ?.replace(/s$/, '');
  27. const userConfig: UserConfig = {
  28. extends: ['@commitlint/config-conventional'],
  29. prompt: {
  30. /** @use `pnpm commit :f` */
  31. alias: {
  32. b: 'build: bump dependencies',
  33. c: 'chore: update config',
  34. f: 'docs: fix typos',
  35. r: 'docs: update README',
  36. s: 'style: update code format',
  37. },
  38. allowCustomIssuePrefixs: false,
  39. // scopes: [...scopes, 'mock'],
  40. allowEmptyIssuePrefixs: false,
  41. customScopesAlign: scopeComplete ? 'bottom' : 'top',
  42. defaultScope: scopeComplete,
  43. // English
  44. typesAppend: [
  45. { name: 'wip: work in process', value: 'wip' },
  46. { name: 'workflow: workflow improvements', value: 'workflow' },
  47. { name: 'types: type definition file changes', value: 'types' },
  48. ],
  49. // 中英文对照版
  50. // messages: {
  51. // type: '选择你要提交的类型 :',
  52. // scope: '选择一个提交范围 (可选):',
  53. // customScope: '请输入自定义的提交范围 :',
  54. // subject: '填写简短精炼的变更描述 :\n',
  55. // body: '填写更加详细的变更描述 (可选)。使用 "|" 换行 :\n',
  56. // breaking: '列举非兼容性重大的变更 (可选)。使用 "|" 换行 :\n',
  57. // footerPrefixsSelect: '选择关联issue前缀 (可选):',
  58. // customFooterPrefixs: '输入自定义issue前缀 :',
  59. // footer: '列举关联issue (可选) 例如: #31, #I3244 :\n',
  60. // confirmCommit: '是否提交或修改commit ?',
  61. // },
  62. // types: [
  63. // { value: 'feat', name: 'feat: 新增功能' },
  64. // { value: 'fix', name: 'fix: 修复缺陷' },
  65. // { value: 'docs', name: 'docs: 文档变更' },
  66. // { value: 'style', name: 'style: 代码格式' },
  67. // { value: 'refactor', name: 'refactor: 代码重构' },
  68. // { value: 'perf', name: 'perf: 性能优化' },
  69. // { value: 'test', name: 'test: 添加疏漏测试或已有测试改动' },
  70. // { value: 'build', name: 'build: 构建流程、外部依赖变更 (如升级 npm 包、修改打包配置等)' },
  71. // { value: 'ci', name: 'ci: 修改 CI 配置、脚本' },
  72. // { value: 'revert', name: 'revert: 回滚 commit' },
  73. // { value: 'chore', name: 'chore: 对构建过程或辅助工具和库的更改 (不影响源文件、测试用例)' },
  74. // { value: 'wip', name: 'wip: 正在开发中' },
  75. // { value: 'workflow', name: 'workflow: 工作流程改进' },
  76. // { value: 'types', name: 'types: 类型定义文件修改' },
  77. // ],
  78. // emptyScopesAlias: 'empty: 不填写',
  79. // customScopesAlias: 'custom: 自定义',
  80. },
  81. rules: {
  82. /**
  83. * type[scope]: [function] description
  84. *
  85. * ^^^^^^^^^^^^^^ empty line.
  86. * - Something here
  87. */
  88. 'body-leading-blank': [2, 'always'],
  89. /**
  90. * type[scope]: [function] description
  91. *
  92. * - something here
  93. *
  94. * ^^^^^^^^^^^^^^
  95. */
  96. 'footer-leading-blank': [1, 'always'],
  97. /**
  98. * type[scope]: [function] description [No more than 108 characters]
  99. * ^^^^^
  100. */
  101. 'header-max-length': [2, 'always', 108],
  102. /**
  103. * type[scope]: [function] description
  104. * ^^^^^
  105. */
  106. 'scope-enum': [2, 'always', scopes],
  107. 'subject-case': [0],
  108. 'subject-empty': [2, 'never'],
  109. 'type-empty': [2, 'never'],
  110. /**
  111. * type[scope]: [function] description
  112. * ^^^^
  113. */
  114. 'type-enum': [
  115. 2,
  116. 'always',
  117. [
  118. 'feat',
  119. 'fix',
  120. 'perf',
  121. 'style',
  122. 'docs',
  123. 'test',
  124. 'refactor',
  125. 'build',
  126. 'ci',
  127. 'chore',
  128. 'revert',
  129. 'types',
  130. 'release',
  131. 'improvement',
  132. ],
  133. ],
  134. },
  135. };
  136. export default userConfig;