Skip to content

Commit f57dca9

Browse files
committed
feat: add ability to filter Nx projects in @commitlint/config-nx-scopes
Solves: conventional-changelog#3152
1 parent 20122e8 commit f57dca9

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: @commitlint/config-nx-scopes/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
},
99
};
1010

11-
function getProjects(context) {
11+
function getProjects(context, projectType) {
1212
return Promise.resolve()
1313
.then(() => {
1414
const ctx = context || {};
@@ -24,6 +24,9 @@ function getProjects(context) {
2424
})
2525
.then((projects) => {
2626
return projects
27+
.filter((project) =>
28+
projectType ? project.projectType === projectType : true
29+
)
2730
.filter((project) => project.targets)
2831
.map((project) => project.name)
2932
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));

Diff for: @commitlint/config-nx-scopes/readme.md

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ npm install --save-dev @commitlint/config-nx-scopes @commitlint/cli
1212
echo "module.exports = {extends: ['@commitlint/config-nx-scopes']};" > commitlint.config.js
1313
```
1414

15+
## Filtering projects by type
16+
17+
You can filter projects by type by specifying the project type parameter.
18+
19+
In your .commitlintrc.js file:
20+
21+
```javascript
22+
const {
23+
utils: {getProjects},
24+
} = require('@commitlint/config-nx-scopes');
25+
26+
module.exports = {
27+
rules: {
28+
'scope-enum': async (ctx) => [
29+
2,
30+
'always',
31+
[...(await getProjects(ctx, 'application'))], // ⬅ or 'library'
32+
],
33+
},
34+
};
35+
```
36+
1537
## Examples
1638

1739
```

0 commit comments

Comments
 (0)