forked from bnb-chain/example-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.commitlintrc.js
More file actions
36 lines (31 loc) · 978 Bytes
/
.commitlintrc.js
File metadata and controls
36 lines (31 loc) · 978 Bytes
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
const fs = require("fs");
const path = require("path");
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"subject-case": [2, "always", ["sentence-case"]],
"scope-enum": async () => {
const scopes = await getScopesFromGit();
return [2, "always", scopes];
},
"scope-case": [2, "always", "kebab-case"],
"scope-empty": async () => {
const scopes = await getScopesFromGit();
if (scopes.length === 0) return [0];
return [2, "never", scopes];
},
},
};
async function getScopesFromGit() {
const { execSync } = require("child_process");
const changedFiles = execSync("git diff --cached --name-only")
.toString()
.split("\n");
const scopes = new Set();
changedFiles.forEach((file) => {
const match = file.match(/^packages\/([^\/]+)/);
if (match && fs.lstatSync(path.join("packages", match[1])).isDirectory())
scopes.add(match[1]);
});
return Array.from(scopes);
}