-
Notifications
You must be signed in to change notification settings - Fork 908
/
index.js
36 lines (33 loc) · 1.01 KB
/
index.js
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
import {RuleConfigSeverity} from '@commitlint/types';
import {getProjects as getNXProjects} from 'nx/src/generators/utils/project-configuration.js';
import {FsTree} from 'nx/src/generators/tree.js';
export default {
utils: {getProjects},
rules: {
'scope-enum': (ctx) =>
Promise.resolve([RuleConfigSeverity.Error, 'always', getProjects(ctx)]),
},
};
/**
* @param {(params: Pick<Nx.ProjectConfiguration, 'name' | 'projectType' | 'tags'>) => boolean} selector
*/
function getProjects(context, selector = () => true) {
const ctx = context || {};
const cwd = ctx.cwd || process.cwd();
const projects = getNXProjects(new FsTree(cwd, false));
return Array.from(projects.entries())
.map(([name, project]) => ({
name,
...project,
}))
.filter((project) =>
selector({
name: project.name,
projectType: project.projectType,
tags: project.tags,
})
)
.filter((project) => project.targets)
.map((project) => project.name)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
}