-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.commitlintrc.js
More file actions
57 lines (51 loc) · 1.54 KB
/
.commitlintrc.js
File metadata and controls
57 lines (51 loc) · 1.54 KB
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
57
const Path = require('path')
const importFrom = require('import-from')
const resolvePkg = require('resolve-pkg')
const semver = require('semver')
module.exports = {
utils: { getPackages },
extends: [
'@commitlint/config-conventional',
'@commitlint/config-lerna-scopes',
],
rules: {
'body-max-length': [0],
'footer-max-length': [0],
'header-max-length': [0],
'scope-enum': ctx =>
getPackages(ctx).then(packages => [
2,
'always',
packages.concat(['deps', 'deps-dev', 'ci', 'devops', 'release']),
]),
},
}
function getPackages(context) {
return Promise.resolve()
.then(() => {
const ctx = context || {}
const cwd = ctx.cwd || process.cwd()
const lernaVersion = getLernaVersion(cwd)
if (semver.lt(lernaVersion, '3.0.0')) {
const Repository = importFrom(cwd, 'lerna/lib/Repository')
const PackageUtilities = importFrom(cwd, 'lerna/lib/PackageUtilities')
const repository = new Repository(cwd)
return PackageUtilities.getPackages({
packageConfigs: repository.packageConfigs,
rootPath: cwd,
})
}
const Project = importFrom(cwd, '@lerna/project')
const project = new Project(cwd)
return project.getPackages()
})
.then(packages => {
return packages
.map(pkg => pkg.name)
.map(name => (name.charAt(0) === '@' ? name.split('/')[1] : name))
})
}
function getLernaVersion(cwd) {
return require(Path.join(resolvePkg('lerna', { cwd }), 'package.json'))
.version
}