1 | const {isString, isNil} = require('lodash');
|
2 | const AggregateError = require('aggregate-error');
|
3 | const getError = require('./get-error');
|
4 | const resolveConfig = require('./resolve-config');
|
5 |
|
6 | const isNonEmptyString = value => isString(value) && value.trim();
|
7 |
|
8 | const VALIDATORS = {
|
9 | changelogFile: isNonEmptyString,
|
10 | changelogTitle: isNonEmptyString,
|
11 | };
|
12 |
|
13 | module.exports = pluginConfig => {
|
14 | const options = resolveConfig(pluginConfig);
|
15 |
|
16 | const errors = Object.entries(options).reduce(
|
17 | (errors, [option, value]) =>
|
18 | !isNil(value) && !VALIDATORS[option](value)
|
19 | ? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})]
|
20 | : errors,
|
21 | []
|
22 | );
|
23 |
|
24 | if (errors.length > 0) {
|
25 | throw new AggregateError(errors);
|
26 | }
|
27 | };
|