-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-types.js
52 lines (40 loc) · 1.09 KB
/
get-types.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
50
51
52
const commitTypes = require('commit-types-peakfijn');
const { getRule, ruleIsEnabled } = require('./commitlint-utils');
function getTypeSummary(type) {
const info = commitTypes[type];
if (info && info.summary) {
return info.summary;
}
return '';
}
function sortTypeEnums(types) {
const peakfijnTypes = Object.keys(commitTypes);
return types.sort((a, b) => {
const aIndex = peakfijnTypes.indexOf(a);
const bIndex = peakfijnTypes.indexOf(b);
if (aIndex >= 0 && bIndex >= 0) {
return aIndex - bIndex;
}
if (aIndex >= 0 && bIndex < 0) {
return -1;
}
if (aIndex < 0 && bIndex >= 0) {
return 1;
}
return 0;
});
}
module.exports = (commitlint = {}) => {
const typeRule = getRule(commitlint, 'type-enum');
const typeEnums = sortTypeEnums(typeRule.value || []);
const maxLength = typeEnums.reduce((carry, type) => type.length > carry ? type.length : carry, 0);
return {
maxLength,
enabled: ruleIsEnabled(typeRule),
choices: typeEnums.map(type => ({
value: type,
short: type,
name: `${type.padEnd(maxLength)} ${getTypeSummary(type)}`.trim(),
})),
};
};