-
Notifications
You must be signed in to change notification settings - Fork 142
/
commitlint.config.js
49 lines (44 loc) · 1.21 KB
/
commitlint.config.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
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict'
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const getScopes = (name, prefix) =>
fs
.readdirSync(path.resolve(__dirname, `packages/${name}`), { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => prefix + dirent.name)
const scopes = [
'cdk:*',
'comp:*',
'pro:*',
...getScopes('cdk', 'cdk:'),
...getScopes('components', 'comp:'),
...getScopes('pro', 'pro:'),
'scripts',
'packaging',
'release',
'changelog',
'docs',
]
// precomputed scope
const scopeMatch = execSync('git status --porcelain || true')
.toString()
.trim()
.split('\n')
.find(r => ~r.indexOf('M packages'))
?.replace(/(\/)/g, '%%')
?.match(/(cdk|components|pro)%%((\w|-)*)/)
const scopeComplete = scopeMatch?.[2] && `${scopeMatch[1].replace('components', 'comp')}:${scopeMatch[2]}`
/** @type {import('cz-git').UserConfig} */
module.exports = {
extends: ['@commitlint/config-angular'],
rules: {
'scope-enum': [2, 'always', scopes],
},
prompt: {
defaultScope: scopeComplete,
customScopesAlign: !scopeComplete ? 'top' : 'bottom',
allowEmptyIssuePrefixs: false,
allowCustomIssuePrefixs: false,
},
}