UNPKG

read-conf

Version:
54 lines (51 loc) 1.66 kB
var validate; validate = require("./validate"); module.exports = ({run, position}) => { run.hookIn(position.before - 1, (base, o) => { var ignore, obj, schema; if ((schema = o.schema) != null) { if (o.util.isString(schema)) { schema = require(schema); } if (o._schema == null) { o._schema = []; } return obj = o._schema[base._readConfigIndex] = { schema: schema, add: validate.getAdder(schema), ignore: ignore = [], validate: (conf) => { conf = base[o.prop || "config"]; return validate(conf, schema, { isNormalized: true, ignore: ignore }).then(() => { return validate.setDefaults(conf, schema, { concat: o.concatArrays, ignore: ignore }); }).catch((problems) => { if (problems instanceof Error) { throw problems; } else { console.error(chalk.red.bold("\n\nInvalid configuration\n")); console.error(chalk.red("File: ") + chalk.underline(`${confPath}\n`)); console.error(chalk.red("Problems:")); console.error(chalk.dim(" - " + problems.join("\n - ") + "\n\n")); if (!o.watch) { process.exit(1); } throw "Invalid configuration"; } }); } }; } }); return run.hookIn(position.after + 1, (base, o) => { var ref, schema; if ((schema = (ref = o._schema) != null ? ref[base._readConfigIndex] : void 0) != null) { return schema.validate(); } }); };