commitlint.config.js 3.5 KB

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