Skip to content

Commit

Permalink
build: custom implementation of commitlint scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Aug 26, 2024
1 parent 2097cf2 commit aa8b28f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import scopes from "@commitlint/config-lerna-scopes";
import fs from "node:fs/promises";
import path from "node:path";
import { glob } from "glob";
const pkg = await fs.readFile("./package.json", { encoding: 'utf8'}).then((data) => JSON.parse(data));

const packages = await glob(
pkg.workspaces.packages.map((pattern) => `${pattern}/package.json`)
).then((files) =>
Promise.all(
files.map((file) =>
fs.readFile(file, { encoding: "utf8" }).then((data) => JSON.parse(data)).then( pkg => pkg.name)
)
)
);

export default {
extends: [
"@commitlint/config-conventional",
"@commitlint/config-lerna-scopes",
],
rules: {
"scope-enum": async (ctx) => [
2,
"always",
[
...(await scopes.utils.getPackages(ctx)),
...packages,
// Custom scopes
"release",
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"devDependencies": {
"@commitlint/cli": "^19.4.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/config-lerna-scopes": "^19.0.0",
"cz-conventional-changelog": "^3.3.0",
"glob": "^11.0.0",
"husky": "^9.1.5",
"lerna": "^8.1.8"
},
Expand Down

0 comments on commit aa8b28f

Please sign in to comment.