forked from conventional-changelog/commitlint
/
index.js
33 lines (29 loc) 路 839 Bytes
/
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
const Path = require('path');
const util = require('util');
const fs = require('fs');
const jsonc = require('jsonc');
const readFilePromisifed = util.promisify(fs.readFile);
module.exports = {
utils: {getPackages},
rules: {
'scope-enum': (ctx) =>
getPackages(ctx).then((packages) => [2, 'always', packages]),
},
};
function getPackages(context) {
return Promise.resolve()
.then(() => {
const ctx = context || {};
const cwd = ctx.cwd || process.cwd();
return readFilePromisifed(Path.join(cwd, 'rush.json'), {encoding: 'utf8'})
.then((content) => jsonc.parse(content))
.then(({projects}) => projects)
.catch(() => []);
})
.then((packages) => {
return packages
.map((pkg) => pkg.packageName)
.filter(Boolean)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
});
}