-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
.commitlintrc.ts
56 lines (45 loc) · 1.57 KB
/
.commitlintrc.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { getWorkspacePackageNames } from './scripts/utils'
// ------------------------------------------------------------------
// -- CUSTOM COMMITLINT CONFIGURATION --
// This configuration is used to enforce the scope-enum rule.
// The scope-enum rule requires that the scope of a commit message
// must be one of the defined values.
// The defined values are the package names of the workspace.
// The package names are extracted from the package.json files.
//
// This was previously achieved using @commitlint/config-pnpm-scopes
// which provides a custom commitlint configuration.
// ------------------------------------------------------------------
interface Context {
cwd?: string
}
// ------------------------------------------------------------------
/**
* Function to get all projects in the workspace
* @param context The context object
* @returns An array of all projects in the workspace
*/
function getProjects(context?: Context): string[] {
const ctx = context ?? {}
const cwd = ctx.cwd ?? process.cwd()
return getWorkspacePackageNames(cwd)
.reduce((projects: string[], name) => {
if (name.startsWith('@')) {
const project = name.split('/')[1]
if (typeof project === 'string') {
projects.push(project)
}
projects.push(name)
}
return projects
}, [])
.sort()
}
// We are exporting a custom commitlint configuration
export default {
extends: ['@commitlint/config-conventional'],
utils: { getProjects },
rules: {
'scope-enum': (ctx: Context) => [2, 'always', getProjects(ctx)],
},
}