-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommitlint.config.ts
More file actions
44 lines (34 loc) · 1.04 KB
/
Copy pathcommitlint.config.ts
File metadata and controls
44 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { existsSync, readdirSync } from "node:fs";
import { join } from "node:path";
const META_SCOPES: string[] = ["deps", "repo", "release"];
const WORKSPACE_ROOTS: string[] = ["apps", "packages", "tools", "distribution"];
function workspaceScopes(cwd: string): string[] {
const scopes: string[] = [];
for (const root of WORKSPACE_ROOTS) {
const dir = join(cwd, root);
if (!existsSync(dir)) {
continue;
}
for (const entry of readdirSync(dir, { withFileTypes: true })) {
if (!entry.isDirectory()) {
continue;
}
if (existsSync(join(dir, entry.name, "package.json"))) {
scopes.push(entry.name);
}
}
}
return scopes;
}
function scopeEnum(): [2, "always", string[]] {
return [2, "always", [...workspaceScopes(process.cwd()), ...META_SCOPES]];
}
const scopeCase: [2, "always", "kebab-case"] = [2, "always", "kebab-case"];
const config = {
extends: ["@commitlint/config-conventional"],
rules: {
"scope-enum": scopeEnum,
"scope-case": scopeCase,
},
};
export default config;