diff --git a/lib/verify-config.js b/lib/verify-config.js index 27977d95..ca84de77 100644 --- a/lib/verify-config.js +++ b/lib/verify-config.js @@ -1,19 +1,22 @@ const {isString, isUndefined, isBoolean} = require('lodash'); const getError = require('./get-error'); -module.exports = ({npmPublish, tarballDir, pkgRoot}) => { - const errors = []; - if (!isUndefined(npmPublish) && !isBoolean(npmPublish)) { - errors.push(getError('EINVALIDNPMPUBLISH', {npmPublish})); - } +const isNonEmptyString = value => isString(value) && value.trim(); - if (!isUndefined(tarballDir) && !isString(tarballDir)) { - errors.push(getError('EINVALIDTARBALLDIR', {tarballDir})); - } +const VALIDATORS = { + npmPublish: isBoolean, + tarballDir: isNonEmptyString, + pkgRoot: isNonEmptyString, +}; - if (!isUndefined(pkgRoot) && !isString(pkgRoot)) { - errors.push(getError('EINVALIDPKGROOT', {pkgRoot})); - } +module.exports = options => { + const errors = Object.entries(options).reduce( + (errors, [option, value]) => + !isUndefined(value) && value !== false && !VALIDATORS[option](value) + ? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})] + : errors, + [] + ); return errors; };