123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import { execSync } from 'node:child_process';
- import { getPackagesSync } from '@vben/node-utils';
- const { packages } = getPackagesSync();
- const allowedScopes = [
- ...packages.map((pkg) => pkg.packageJson.name),
- 'project',
- 'style',
- 'lint',
- 'ci',
- 'dev',
- 'deploy',
- 'other',
- ];
- const scopeComplete = execSync('git status --porcelain || true')
- .toString()
- .trim()
- .split('\n')
- .find((r) => ~r.indexOf('M src'))
- ?.replace(/(\/)/g, '%%')
- ?.match(/src%%((\w|-)*)/)?.[1]
- ?.replace(/s$/, '');
- const userConfig = {
- extends: ['@commitlint/config-conventional'],
- plugins: ['commitlint-plugin-function-rules'],
- prompt: {
-
- alias: {
- b: 'build: bump dependencies',
- c: 'chore: update config',
- f: 'docs: fix typos',
- r: 'docs: update README',
- s: 'style: update code format',
- },
- allowCustomIssuePrefixs: false,
-
- allowEmptyIssuePrefixs: false,
- customScopesAlign: scopeComplete ? 'bottom' : 'top',
- defaultScope: scopeComplete,
-
- typesAppend: [
- { name: 'workflow: workflow improvements', value: 'workflow' },
- { name: 'types: type definition file changes', value: 'types' },
- ],
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- rules: {
-
- 'body-leading-blank': [2, 'always'],
-
- 'footer-leading-blank': [1, 'always'],
-
- 'function-rules/scope-enum': [
- 2,
- 'always',
- (parsed) => {
- if (!parsed.scope || allowedScopes.includes(parsed.scope)) {
- return [true];
- }
- return [false, `scope must be one of ${allowedScopes.join(', ')}`];
- },
- ],
-
- 'header-max-length': [2, 'always', 108],
- 'scope-enum': [0],
- 'subject-case': [0],
- 'subject-empty': [2, 'never'],
- 'type-empty': [2, 'never'],
-
- 'type-enum': [
- 2,
- 'always',
- [
- 'feat',
- 'fix',
- 'perf',
- 'style',
- 'docs',
- 'test',
- 'refactor',
- 'build',
- 'ci',
- 'chore',
- 'revert',
- 'types',
- 'release',
- ],
- ],
- },
- };
- export default userConfig;
|