Skip to content

Commit

Permalink
feat: add ability to filter Nx projects in @commitlint/config-nx-scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytavares committed May 11, 2022
1 parent 66a9c99 commit 92e3326
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion @commitlint/config-nx-scopes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
};

function getProjects(context) {
function getProjects(context, filterFunc) {
return Promise.resolve()
.then(() => {
const ctx = context || {};
Expand All @@ -24,6 +24,15 @@ function getProjects(context) {
})
.then((projects) => {
return projects
.filter((project) =>
filterFunc
? filterFunc({
name: project.name,
type: project.projectType,
tags: project.tags,
})
: true
)
.filter((project) => project.targets)
.map((project) => project.name)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
Expand Down
22 changes: 22 additions & 0 deletions @commitlint/config-nx-scopes/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ npm install --save-dev @commitlint/config-nx-scopes @commitlint/cli
echo "module.exports = {extends: ['@commitlint/config-nx-scopes']};" > commitlint.config.js
```

## Filtering projects by type

You can filter projects by type by specifying the project type parameter.

In your .commitlintrc.js file:

```javascript
const {
utils: {getProjects},
} = require('@commitlint/config-nx-scopes');

module.exports = {
rules: {
'scope-enum': async (ctx) => [
2,
'always',
[...(await getProjects(ctx, 'application'))], // ⬅ or 'library'
],
},
};
```

## Examples

```
Expand Down

0 comments on commit 92e3326

Please sign in to comment.