commitlint-config-spellbookx 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +19 -7
- package/.turbo/turbo-test.log +59 -0
- package/README.md +211 -30
- package/__tests__/index.test.ts +47 -0
- package/__tests__/lint.test.ts +65 -0
- package/__tests__/scopes.test.ts +55 -0
- package/__tests__/workspaces.test.ts +76 -0
- package/dist/constants/commit-types.d.ts +13 -0
- package/dist/constants/commit-types.d.ts.map +1 -0
- package/dist/constants/commit-types.js +24 -0
- package/dist/get-scopes-D9bIfVqN.js +5698 -0
- package/dist/get-workspaces-raw-path-Cg196xaD.js +2043 -0
- package/dist/helpers.d.ts +8 -17
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +21 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7878
- package/dist/lib/find-git-root.d.ts +16 -0
- package/dist/lib/find-git-root.d.ts.map +1 -0
- package/dist/lib/find-git-root.js +30 -0
- package/dist/lib/get-scope-description.d.ts +21 -0
- package/dist/lib/get-scope-description.d.ts.map +1 -0
- package/dist/lib/get-scope-description.js +35 -0
- package/dist/lib/get-scopes.d.ts +16 -0
- package/dist/lib/get-scopes.d.ts.map +1 -0
- package/dist/lib/get-scopes.js +4 -0
- package/dist/lib/get-workspaces-raw-path.d.ts +19 -0
- package/dist/lib/get-workspaces-raw-path.d.ts.map +1 -0
- package/dist/lib/get-workspaces-raw-path.js +3 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/package-json.d.ts +14 -0
- package/dist/lib/package-json.d.ts.map +1 -0
- package/dist/lib/package-json.js +16 -0
- package/dist/prompt.d.ts +10 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +99 -0
- package/dist/rules.d.ts +10 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +45 -0
- package/dist/scopes.d.ts +23 -0
- package/dist/scopes.d.ts.map +1 -0
- package/dist/scopes.js +38 -0
- package/package.json +43 -9
- package/rolldown.config.ts +13 -1
- package/src/constants/commit-types.ts +26 -0
- package/src/index.ts +26 -153
- package/src/lib/find-git-root.ts +31 -0
- package/src/lib/get-scope-description.ts +38 -0
- package/src/lib/get-scopes.ts +89 -0
- package/src/lib/get-workspaces-raw-path.ts +53 -0
- package/src/lib/index.ts +10 -0
- package/src/lib/package-json.ts +22 -0
- package/src/prompt.ts +99 -0
- package/src/rules.ts +22 -0
- package/src/scopes.ts +40 -0
- package/tsconfig.json +1 -0
- package/src/helpers.ts +0 -123
package/src/index.ts
CHANGED
|
@@ -1,160 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const SCOPE_RELEASE = 'release';
|
|
7
|
-
|
|
8
|
-
const scopesArray = [SCOPE_WORKSPACE, SCOPE_RELEASE, ...getScopes()];
|
|
9
|
-
|
|
10
|
-
const scopesEnum: Record<string, { description: string }> = {};
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* Main entry point for commitlint-config-spellbookx.
|
|
4
|
+
* Exports conventional commit configuration, rules, prompt settings, and scope definitions.
|
|
5
|
+
*/
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
for (const scope of scopesArray) {
|
|
14
|
-
let description;
|
|
15
|
-
|
|
16
|
-
switch (scope) {
|
|
17
|
-
case SCOPE_WORKSPACE: {
|
|
18
|
-
description =
|
|
19
|
-
'workspace scope - root files such as config files, root package.json, etc';
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
case SCOPE_RELEASE: {
|
|
24
|
-
description = 'Special scope for release commits';
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
default: {
|
|
29
|
-
description = `${scope} scope`;
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Object.defineProperty(scopesEnum, scope, {
|
|
35
|
-
value: { description },
|
|
36
|
-
enumerable: true,
|
|
37
|
-
writable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
7
|
+
import type { UserConfig } from '@commitlint/types';
|
|
41
8
|
|
|
42
|
-
|
|
9
|
+
import { prompt } from './prompt.js';
|
|
10
|
+
import { rules } from './rules.js';
|
|
11
|
+
|
|
12
|
+
export { COMMIT_TYPES, type CommitType } from './constants/commit-types.js';
|
|
13
|
+
export * from './lib/index.js';
|
|
14
|
+
export { prompt } from './prompt.js';
|
|
15
|
+
export { rules } from './rules.js';
|
|
16
|
+
export {
|
|
17
|
+
SCOPE_RELEASE,
|
|
18
|
+
SCOPE_WORKSPACE,
|
|
19
|
+
scopesArray,
|
|
20
|
+
scopesEnum,
|
|
21
|
+
} from './scopes.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Shareable Commitlint configuration preset enforcing conventional commits.
|
|
25
|
+
*/
|
|
26
|
+
export const config: UserConfig = {
|
|
43
27
|
extends: ['@commitlint/config-conventional'],
|
|
44
28
|
parserPreset: 'conventional-changelog-conventionalcommits',
|
|
45
|
-
rules
|
|
46
|
-
|
|
47
|
-
2,
|
|
48
|
-
'always',
|
|
49
|
-
[
|
|
50
|
-
'feat',
|
|
51
|
-
'fix',
|
|
52
|
-
'docs',
|
|
53
|
-
'style',
|
|
54
|
-
'refactor',
|
|
55
|
-
'perf',
|
|
56
|
-
'test',
|
|
57
|
-
'chore',
|
|
58
|
-
'ci',
|
|
59
|
-
'build',
|
|
60
|
-
'revert',
|
|
61
|
-
],
|
|
62
|
-
],
|
|
63
|
-
'scope-enum': [2, 'always', scopesArray],
|
|
64
|
-
'subject-empty': [2, 'never'],
|
|
65
|
-
'subject-full-stop': [2, 'never', '.'],
|
|
66
|
-
'header-max-length': [2, 'always', 72],
|
|
67
|
-
'body-max-line-length': [2, 'always', 100],
|
|
68
|
-
'footer-max-line-length': [2, 'always', 100],
|
|
69
|
-
},
|
|
70
|
-
prompt: {
|
|
71
|
-
settings: {
|
|
72
|
-
enableMultipleScopes: true,
|
|
73
|
-
scopeEnumSeparator: ',',
|
|
74
|
-
},
|
|
75
|
-
messages: {
|
|
76
|
-
skip: ':skip',
|
|
77
|
-
max: 'upper %d chars',
|
|
78
|
-
min: '%d chars at least',
|
|
79
|
-
emptyWarning: 'can not be empty',
|
|
80
|
-
upperLimitWarning: 'over limit',
|
|
81
|
-
lowerLimitWarning: 'below limit',
|
|
82
|
-
},
|
|
83
|
-
questions: {
|
|
84
|
-
type: {
|
|
85
|
-
description: "Select the type of change that you're committing:",
|
|
86
|
-
enum: {
|
|
87
|
-
feat: {
|
|
88
|
-
description: 'A new feature',
|
|
89
|
-
title: 'Features',
|
|
90
|
-
emoji: '✨',
|
|
91
|
-
},
|
|
92
|
-
fix: { description: 'A bug fix', title: 'Bug Fixes', emoji: '🐛' },
|
|
93
|
-
docs: {
|
|
94
|
-
description: 'Documentation only changes',
|
|
95
|
-
title: 'Documentation',
|
|
96
|
-
emoji: '📚',
|
|
97
|
-
},
|
|
98
|
-
style: {
|
|
99
|
-
description: 'Changes that do not affect meaning of the code',
|
|
100
|
-
title: 'Styles',
|
|
101
|
-
emoji: '💎',
|
|
102
|
-
},
|
|
103
|
-
refactor: {
|
|
104
|
-
description: 'Code refactoring',
|
|
105
|
-
title: 'Code Refactoring',
|
|
106
|
-
emoji: '📦',
|
|
107
|
-
},
|
|
108
|
-
perf: {
|
|
109
|
-
description: 'Performance improvements',
|
|
110
|
-
title: 'Performance Improvements',
|
|
111
|
-
emoji: '🚀',
|
|
112
|
-
},
|
|
113
|
-
test: {
|
|
114
|
-
description: 'Adding or fixing tests',
|
|
115
|
-
title: 'Tests',
|
|
116
|
-
emoji: '🚨',
|
|
117
|
-
},
|
|
118
|
-
build: {
|
|
119
|
-
description: 'Changes that affect build system',
|
|
120
|
-
title: 'Builds',
|
|
121
|
-
emoji: '🛠',
|
|
122
|
-
},
|
|
123
|
-
ci: {
|
|
124
|
-
description: 'Changes to CI config',
|
|
125
|
-
title: 'Continuous Integrations',
|
|
126
|
-
emoji: '⚙️',
|
|
127
|
-
},
|
|
128
|
-
chore: { description: 'Other changes', title: 'Chores', emoji: '♻️' },
|
|
129
|
-
revert: {
|
|
130
|
-
description: 'Reverts a previous commit',
|
|
131
|
-
title: 'Reverts',
|
|
132
|
-
emoji: '🗑',
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
scope: {
|
|
137
|
-
description:
|
|
138
|
-
'Select the scope(s) of the change (use arrow keys or space to select multiple)',
|
|
139
|
-
enum: scopesEnum,
|
|
140
|
-
},
|
|
141
|
-
subject: {
|
|
142
|
-
description:
|
|
143
|
-
'Write a short, imperative tense description of the change',
|
|
144
|
-
},
|
|
145
|
-
body: { description: 'Provide a longer description of the change' },
|
|
146
|
-
isBreaking: { description: 'Are there any breaking changes?' },
|
|
147
|
-
breakingBody: { description: 'Describe the breaking changes with body' },
|
|
148
|
-
breaking: { description: 'Describe the breaking changes' },
|
|
149
|
-
isIssueAffected: {
|
|
150
|
-
description: 'Does this change affect any open issues?',
|
|
151
|
-
},
|
|
152
|
-
issuesBody: {
|
|
153
|
-
description: 'If issues are closed, enter longer description',
|
|
154
|
-
},
|
|
155
|
-
issues: { description: 'Add issue references (e.g., "fix #123")' },
|
|
156
|
-
},
|
|
157
|
-
},
|
|
29
|
+
rules,
|
|
30
|
+
prompt,
|
|
158
31
|
};
|
|
159
32
|
|
|
160
33
|
export default config;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file find-git-root.ts
|
|
3
|
+
* Utility to locate the root directory of a git repository.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Finds the git root directory by traversing upwards from startDir.
|
|
11
|
+
*
|
|
12
|
+
* @param startDir - Directory to start searching from (defaults to process.cwd()).
|
|
13
|
+
* @returns Path to git root directory, or null if not within a git repository.
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const root = findGitRoot();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function findGitRoot(startDir: string = process.cwd()): string | null {
|
|
20
|
+
let current = path.resolve(startDir);
|
|
21
|
+
while (true) {
|
|
22
|
+
if (existsSync(path.join(current, '.git'))) {
|
|
23
|
+
return current;
|
|
24
|
+
}
|
|
25
|
+
const parent = path.dirname(current);
|
|
26
|
+
if (parent === current) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
current = parent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file get-scope-description.ts
|
|
3
|
+
* Formats user-facing description strings for commit scopes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Scope identifier for workspace-level changes.
|
|
8
|
+
*/
|
|
9
|
+
const SCOPE_WORKSPACE = 'workspace';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Scope identifier for release commits.
|
|
13
|
+
*/
|
|
14
|
+
const SCOPE_RELEASE = 'release';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns a human-readable description for a given commit scope.
|
|
18
|
+
*
|
|
19
|
+
* @param scope - The scope identifier.
|
|
20
|
+
* @returns The description string for the scope.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* getScopeDescription('workspace');
|
|
24
|
+
* // 'workspace scope - root files such as config files, root package.json, etc'
|
|
25
|
+
* getScopeDescription('release');
|
|
26
|
+
* // 'Special scope for release commits'
|
|
27
|
+
* getScopeDescription('my-package');
|
|
28
|
+
* // 'my-package scope'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function getScopeDescription(scope: string): string {
|
|
32
|
+
if (scope === SCOPE_WORKSPACE) {
|
|
33
|
+
return 'workspace scope - root files such as config files, root package.json, etc';
|
|
34
|
+
}
|
|
35
|
+
return scope === SCOPE_RELEASE
|
|
36
|
+
? 'Special scope for release commits'
|
|
37
|
+
: `${scope} scope`;
|
|
38
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file get-scopes.ts
|
|
3
|
+
* Discovers and gathers workspace package scopes in a monorepo or standard repository.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
import fg from 'fast-glob';
|
|
10
|
+
|
|
11
|
+
import { findGitRoot } from './find-git-root.js';
|
|
12
|
+
import { getWorkspacesRawPath } from './get-workspaces-raw-path.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves a list of package scope names from monorepo configuration files (npm, pnpm, lerna).
|
|
16
|
+
*
|
|
17
|
+
* @param cwd - Working directory to start git root discovery from (defaults to process.cwd()).
|
|
18
|
+
* @returns An array of package scope names found in the repository.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const scopes = getScopes();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function getScopes(cwd: string = process.cwd()): string[] {
|
|
25
|
+
const root = findGitRoot(cwd);
|
|
26
|
+
|
|
27
|
+
if (!root) {
|
|
28
|
+
throw new Error('[FATAL] Not a repository.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const rawWorkspaces: string[] = [];
|
|
32
|
+
|
|
33
|
+
const packageJsonPath = path.join(root, 'package.json');
|
|
34
|
+
rawWorkspaces.push(
|
|
35
|
+
...getWorkspacesRawPath(packageJsonPath, 'json', 'workspaces')
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const pnpmWorkspaceYamlPath = path.join(root, 'pnpm-workspace.yaml');
|
|
39
|
+
rawWorkspaces.push(
|
|
40
|
+
...getWorkspacesRawPath(pnpmWorkspaceYamlPath, 'yaml', 'packages')
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const pnpmWorkspaceYmlPath = path.join(root, 'pnpm-workspace.yml');
|
|
44
|
+
rawWorkspaces.push(
|
|
45
|
+
...getWorkspacesRawPath(pnpmWorkspaceYmlPath, 'yaml', 'packages')
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const lernaJsonPath = path.join(root, 'lerna.json');
|
|
49
|
+
rawWorkspaces.push(
|
|
50
|
+
...getWorkspacesRawPath(lernaJsonPath, 'json', 'packages')
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const workspaces = new Set<string>();
|
|
54
|
+
|
|
55
|
+
const rootPackageJsonPath = path.join(root, 'package.json');
|
|
56
|
+
if (existsSync(rootPackageJsonPath) && !rawWorkspaces.includes('.')) {
|
|
57
|
+
rawWorkspaces.push('.');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const pattern of rawWorkspaces) {
|
|
61
|
+
const entries = fg.sync(pattern, {
|
|
62
|
+
cwd: root,
|
|
63
|
+
onlyDirectories: true,
|
|
64
|
+
absolute: true,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
for (const dirPath of entries) {
|
|
68
|
+
const packageJsonPath = path.join(dirPath, 'package.json');
|
|
69
|
+
|
|
70
|
+
if (existsSync(packageJsonPath)) {
|
|
71
|
+
try {
|
|
72
|
+
const package_ = JSON.parse(
|
|
73
|
+
readFileSync(packageJsonPath, 'utf8')
|
|
74
|
+
) as {
|
|
75
|
+
name?: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (package_.name) {
|
|
79
|
+
workspaces.add(package_.name);
|
|
80
|
+
}
|
|
81
|
+
} catch {
|
|
82
|
+
// ignore invalid package.json files
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [...workspaces];
|
|
89
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file get-workspaces-raw-path.ts
|
|
3
|
+
* Parser for extracting workspace path globs from JSON and YAML configuration files.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
+
|
|
8
|
+
import { load } from 'js-yaml';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Reads workspace paths from configuration files (JSON or YAML).
|
|
12
|
+
*
|
|
13
|
+
* @param configPath - The path to the config file (e.g., package.json, pnpm-workspace.yaml).
|
|
14
|
+
* @param parser - The parser type to use for reading the file ('json' or 'yaml').
|
|
15
|
+
* @param property - The property name in the config containing workspace paths (defaults to 'workspaces').
|
|
16
|
+
* @returns Array of raw workspace path patterns.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* getWorkspacesRawPath('package.json', 'json', 'workspaces');
|
|
20
|
+
* getWorkspacesRawPath('pnpm-workspace.yaml', 'yaml', 'packages');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function getWorkspacesRawPath(
|
|
24
|
+
configPath: string,
|
|
25
|
+
parser: 'json' | 'yaml',
|
|
26
|
+
property: string = 'workspaces'
|
|
27
|
+
): string[] {
|
|
28
|
+
const rawWorkspacesPaths: string[] = [];
|
|
29
|
+
|
|
30
|
+
if (existsSync(configPath)) {
|
|
31
|
+
const asString = readFileSync(configPath, 'utf8');
|
|
32
|
+
|
|
33
|
+
let parsed: Record<string, unknown>;
|
|
34
|
+
|
|
35
|
+
if (parser === 'json') {
|
|
36
|
+
parsed = JSON.parse(asString);
|
|
37
|
+
} else if (parser === 'yaml') {
|
|
38
|
+
parsed = load(asString) as Record<string, unknown>;
|
|
39
|
+
} else {
|
|
40
|
+
throw new Error(`Unsupported parser type: ${parser}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const workspaces = parsed[property];
|
|
44
|
+
|
|
45
|
+
if (Array.isArray(workspaces)) {
|
|
46
|
+
for (const project of workspaces) {
|
|
47
|
+
rawWorkspacesPaths.push(project);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return rawWorkspacesPaths;
|
|
53
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* Barrel export for atomic utility functions in commitlint-config-spellbookx.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { findGitRoot } from './find-git-root.js';
|
|
7
|
+
export { getScopeDescription } from './get-scope-description.js';
|
|
8
|
+
export { getScopes } from './get-scopes.js';
|
|
9
|
+
export { getWorkspacesRawPath } from './get-workspaces-raw-path.js';
|
|
10
|
+
export { packageJson } from './package-json.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file package-json.ts
|
|
3
|
+
* Reads package metadata for commitlint-config-spellbookx.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { fileURLToPath, URL } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const packagePath = fileURLToPath(
|
|
10
|
+
new URL('../../package.json', import.meta.url)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parsed `package.json` metadata for `commitlint-config-spellbookx`.
|
|
15
|
+
*/
|
|
16
|
+
export const packageJson = JSON.parse(readFileSync(packagePath, 'utf8')) as {
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
peerDependencies: Record<string, string>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default packageJson;
|
package/src/prompt.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file prompt.ts
|
|
3
|
+
* Commitizen prompt questions and settings for interactive commits with cz-git.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { UserConfig } from '@commitlint/types';
|
|
7
|
+
|
|
8
|
+
import { scopesEnum } from './scopes.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Commitizen and cz-git interactive prompt configuration.
|
|
12
|
+
*/
|
|
13
|
+
export const prompt: UserConfig['prompt'] = {
|
|
14
|
+
settings: {
|
|
15
|
+
enableMultipleScopes: true,
|
|
16
|
+
scopeEnumSeparator: ',',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
skip: ':skip',
|
|
20
|
+
max: 'upper %d chars',
|
|
21
|
+
min: '%d chars at least',
|
|
22
|
+
emptyWarning: 'can not be empty',
|
|
23
|
+
upperLimitWarning: 'over limit',
|
|
24
|
+
lowerLimitWarning: 'below limit',
|
|
25
|
+
},
|
|
26
|
+
questions: {
|
|
27
|
+
type: {
|
|
28
|
+
description: "Select the type of change that you're committing:",
|
|
29
|
+
enum: {
|
|
30
|
+
feat: {
|
|
31
|
+
description: 'A new feature',
|
|
32
|
+
title: 'Features',
|
|
33
|
+
emoji: '✨',
|
|
34
|
+
},
|
|
35
|
+
fix: { description: 'A bug fix', title: 'Bug Fixes', emoji: '🐛' },
|
|
36
|
+
docs: {
|
|
37
|
+
description: 'Documentation only changes',
|
|
38
|
+
title: 'Documentation',
|
|
39
|
+
emoji: '📚',
|
|
40
|
+
},
|
|
41
|
+
style: {
|
|
42
|
+
description: 'Changes that do not affect meaning of the code',
|
|
43
|
+
title: 'Styles',
|
|
44
|
+
emoji: '💎',
|
|
45
|
+
},
|
|
46
|
+
refactor: {
|
|
47
|
+
description: 'Code refactoring',
|
|
48
|
+
title: 'Code Refactoring',
|
|
49
|
+
emoji: '📦',
|
|
50
|
+
},
|
|
51
|
+
perf: {
|
|
52
|
+
description: 'Performance improvements',
|
|
53
|
+
title: 'Performance Improvements',
|
|
54
|
+
emoji: '🚀',
|
|
55
|
+
},
|
|
56
|
+
test: {
|
|
57
|
+
description: 'Adding or fixing tests',
|
|
58
|
+
title: 'Tests',
|
|
59
|
+
emoji: '🚨',
|
|
60
|
+
},
|
|
61
|
+
build: {
|
|
62
|
+
description: 'Changes that affect build system',
|
|
63
|
+
title: 'Builds',
|
|
64
|
+
emoji: '🛠',
|
|
65
|
+
},
|
|
66
|
+
ci: {
|
|
67
|
+
description: 'Changes to CI config',
|
|
68
|
+
title: 'Continuous Integrations',
|
|
69
|
+
emoji: '⚙️',
|
|
70
|
+
},
|
|
71
|
+
chore: { description: 'Other changes', title: 'Chores', emoji: '♻️' },
|
|
72
|
+
revert: {
|
|
73
|
+
description: 'Reverts a previous commit',
|
|
74
|
+
title: 'Reverts',
|
|
75
|
+
emoji: '🗑',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
scope: {
|
|
80
|
+
description:
|
|
81
|
+
'Select the scope(s) of the change (use arrow keys or space to select multiple)',
|
|
82
|
+
enum: scopesEnum,
|
|
83
|
+
},
|
|
84
|
+
subject: {
|
|
85
|
+
description: 'Write a short, imperative tense description of the change',
|
|
86
|
+
},
|
|
87
|
+
body: { description: 'Provide a longer description of the change' },
|
|
88
|
+
isBreaking: { description: 'Are there any breaking changes?' },
|
|
89
|
+
breakingBody: { description: 'Describe the breaking changes with body' },
|
|
90
|
+
breaking: { description: 'Describe the breaking changes' },
|
|
91
|
+
isIssueAffected: {
|
|
92
|
+
description: 'Does this change affect any open issues?',
|
|
93
|
+
},
|
|
94
|
+
issuesBody: {
|
|
95
|
+
description: 'If issues are closed, enter longer description',
|
|
96
|
+
},
|
|
97
|
+
issues: { description: 'Add issue references (e.g., "fix #123")' },
|
|
98
|
+
},
|
|
99
|
+
};
|
package/src/rules.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rules.ts
|
|
3
|
+
* Commitlint rule definitions for enforcing conventional commits.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { QualifiedRules } from '@commitlint/types';
|
|
7
|
+
|
|
8
|
+
import { COMMIT_TYPES } from './constants/commit-types.js';
|
|
9
|
+
import { scopesArray } from './scopes.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Standard commitlint rules configuration.
|
|
13
|
+
*/
|
|
14
|
+
export const rules: QualifiedRules = {
|
|
15
|
+
'type-enum': [2, 'always', [...COMMIT_TYPES]],
|
|
16
|
+
'scope-enum': [2, 'always', scopesArray],
|
|
17
|
+
'subject-empty': [2, 'never'],
|
|
18
|
+
'subject-full-stop': [2, 'never', '.'],
|
|
19
|
+
'header-max-length': [2, 'always', 72],
|
|
20
|
+
'body-max-line-length': [2, 'always', 100],
|
|
21
|
+
'footer-max-line-length': [2, 'always', 100],
|
|
22
|
+
};
|
package/src/scopes.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file scopes.ts
|
|
3
|
+
* Scopes constants and scope enumeration generator for commitlint and commitizen.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { getScopeDescription } from './lib/get-scope-description.js';
|
|
7
|
+
import { getScopes } from './lib/get-scopes.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Scope identifier for repository-wide or workspace-level changes.
|
|
11
|
+
*/
|
|
12
|
+
export const SCOPE_WORKSPACE = 'workspace';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Scope identifier for release and versioning commits.
|
|
16
|
+
*/
|
|
17
|
+
export const SCOPE_RELEASE = 'release';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Array of all valid commit scopes, including workspace, release, and discovered monorepo packages.
|
|
21
|
+
*/
|
|
22
|
+
export const scopesArray: string[] = [
|
|
23
|
+
SCOPE_WORKSPACE,
|
|
24
|
+
SCOPE_RELEASE,
|
|
25
|
+
...getScopes(),
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Record of scopes mapped to their human-readable descriptions for Commitizen interactive prompt.
|
|
30
|
+
*/
|
|
31
|
+
export const scopesEnum: Record<string, { description: string }> = {};
|
|
32
|
+
|
|
33
|
+
for (const scope of scopesArray) {
|
|
34
|
+
Object.defineProperty(scopesEnum, scope, {
|
|
35
|
+
value: { description: getScopeDescription(scope) },
|
|
36
|
+
enumerable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
});
|
|
40
|
+
}
|