-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommitlint.config.ts
More file actions
50 lines (43 loc) · 1.21 KB
/
commitlint.config.ts
File metadata and controls
50 lines (43 loc) · 1.21 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
45
46
47
48
49
50
import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
interface ReleaseRule {
type: string;
release: string;
}
interface PackageJson {
release?: {
plugins?: ([string, { releaseRules?: ReleaseRule[] }] | string)[];
};
}
// Read package.json to extract release types
const pkgPath = resolve(__dirname, "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as PackageJson;
// Extract types from commit-analyzer releaseRules
const commitAnalyzerPlugin = pkg.release?.plugins?.find(
(plugin): plugin is [string, { releaseRules?: ReleaseRule[] }] =>
Array.isArray(plugin) && plugin[0] === "@semantic-release/commit-analyzer",
);
const releaseRules = commitAnalyzerPlugin?.[1]?.releaseRules;
const types = releaseRules?.map((rule: ReleaseRule) => rule.type) ?? [
"feat",
"fix",
"docs",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
"chore",
"revert",
];
export default {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [2, "always", types],
"subject-case": [2, "always", "lower-case"],
"header-max-length": [2, "always", 100],
},
};