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 Apr 29, 2022
1 parent c879bde commit 7fe44ec
Show file tree
Hide file tree
Showing 3 changed files with 8,668 additions and 8,037 deletions.
5 changes: 4 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, projectType) {
return Promise.resolve()
.then(() => {
const ctx = context || {};
Expand All @@ -24,6 +24,9 @@ function getProjects(context) {
})
.then((projects) => {
return projects
.filter((project) =>
projectType ? project.projectType === projectType : 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
Loading

0 comments on commit 7fe44ec

Please sign in to comment.