1 | const importFrom = require('import-from');
|
2 | const RELEASE_TYPES = require('./default-release-types');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | module.exports = ({releaseRules}, {cwd}) => {
|
18 | let loadedReleaseRules;
|
19 |
|
20 | if (releaseRules) {
|
21 | loadedReleaseRules =
|
22 | typeof releaseRules === 'string'
|
23 | ? importFrom.silent(__dirname, releaseRules) || importFrom(cwd, releaseRules)
|
24 | : releaseRules;
|
25 |
|
26 | if (!Array.isArray(loadedReleaseRules)) {
|
27 | throw new TypeError('Error in commit-analyzer configuration: "releaseRules" must be an array of rules');
|
28 | }
|
29 |
|
30 | loadedReleaseRules.forEach(rule => {
|
31 | if (!rule || !rule.release) {
|
32 | throw new Error('Error in commit-analyzer configuration: rules must be an object with a "release" property');
|
33 | } else if (RELEASE_TYPES.indexOf(rule.release) === -1) {
|
34 | throw new Error(
|
35 | `Error in commit-analyzer configuration: "${
|
36 | rule.release
|
37 | }" is not a valid release type. Valid values are: ${JSON.stringify(RELEASE_TYPES)}`
|
38 | );
|
39 | }
|
40 | });
|
41 | }
|
42 | return loadedReleaseRules;
|
43 | };
|