commitlint.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { execSync } from 'child_process'
  2. import fg from 'fast-glob'
  3. const getPackages = (packagePath) =>
  4. fg.sync('*', { cwd: packagePath, onlyDirectories: true })
  5. const scopes = [
  6. ...getPackages('packages'),
  7. ...getPackages('internal'),
  8. 'docs',
  9. 'play',
  10. 'project',
  11. 'core',
  12. 'style',
  13. 'ci',
  14. 'dev',
  15. 'deploy',
  16. 'other',
  17. 'typography',
  18. 'color',
  19. 'border',
  20. 'var',
  21. 'ssr',
  22. ]
  23. const gitStatus = execSync('git status --porcelain || true')
  24. .toString()
  25. .trim()
  26. .split('\n')
  27. const scopeComplete = gitStatus
  28. .find((r) => ~r.indexOf('M packages'))
  29. ?.replace(/\//g, '%%')
  30. ?.match(/packages%%((\w|-)*)/)?.[1]
  31. const subjectComplete = gitStatus
  32. .find((r) => ~r.indexOf('M packages/components'))
  33. ?.replace(/\//g, '%%')
  34. ?.match(/packages%%components%%((\w|-)*)/)?.[1]
  35. export default {
  36. rules: {
  37. /**
  38. * type[scope]: [function] description
  39. * ^^^^^
  40. */
  41. 'scope-enum': [2, 'always', scopes],
  42. /**
  43. * type[scope]: [function] description
  44. *
  45. * ^^^^^^^^^^^^^^ empty line.
  46. * - Something here
  47. */
  48. 'body-leading-blank': [1, 'always'],
  49. /**
  50. * type[scope]: [function] description
  51. *
  52. * - something here
  53. *
  54. * ^^^^^^^^^^^^^^
  55. */
  56. 'footer-leading-blank': [1, 'always'],
  57. /**
  58. * type[scope]: [function] description [No more than 72 characters]
  59. * ^^^^^
  60. */
  61. 'header-max-length': [2, 'always', 72],
  62. 'scope-case': [2, 'always', 'lower-case'],
  63. 'subject-case': [
  64. 1,
  65. 'never',
  66. ['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
  67. ],
  68. 'subject-empty': [2, 'never'],
  69. 'subject-full-stop': [2, 'never', '.'],
  70. 'type-case': [2, 'always', 'lower-case'],
  71. 'type-empty': [2, 'never'],
  72. /**
  73. * type[scope]: [function] description
  74. * ^^^^
  75. */
  76. 'type-enum': [
  77. 2,
  78. 'always',
  79. [
  80. 'build',
  81. 'chore',
  82. 'ci',
  83. 'docs',
  84. 'feat',
  85. 'fix',
  86. 'perf',
  87. 'refactor',
  88. 'revert',
  89. 'release',
  90. 'style',
  91. 'test',
  92. 'improvement',
  93. ],
  94. ],
  95. },
  96. prompt: {
  97. defaultScope: scopeComplete,
  98. customScopesAlign: !scopeComplete ? 'top' : 'bottom',
  99. defaultSubject: subjectComplete && `[${subjectComplete}] `,
  100. allowCustomIssuePrefixs: false,
  101. allowEmptyIssuePrefixs: false,
  102. },
  103. }