UNPKG

757 BJavaScriptView Raw
1const {isString, isNil} = require('lodash');
2const AggregateError = require('aggregate-error');
3const getError = require('./get-error');
4const resolveConfig = require('./resolve-config');
5
6const isNonEmptyString = value => isString(value) && value.trim();
7
8const VALIDATORS = {
9 changelogFile: isNonEmptyString,
10 changelogTitle: isNonEmptyString,
11};
12
13module.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};