diff --git a/lib/template.js b/lib/template.js index f1e1f63..e002d28 100644 --- a/lib/template.js +++ b/lib/template.js @@ -298,8 +298,21 @@ function loadConfigFile () { throw new Error('neither init.coffee nor init.js exist') } - this.sprout.emit('msg', `requiring ${initPath}`) - this.init = require(initPath) + this.sprout.emit('msg', `requiring and validating ${initPath}`) + + const schema = Joi.object().keys({ + before: Joi.func(), + configure: Joi.array().items(Joi.object()), + beforeRender: Joi.func(), + after: Joi.func(), + ignore: Joi.array().single(), + defaults: Joi.object() + }) + + const result = Joi.validate(require(initPath), schema) + if (result.error) { throw result.error } + + this.init = result.value } function runBeforeHook (utils) { @@ -333,8 +346,7 @@ function mergeConfig (opts) { // If questionnaire function exists, run it to get answers. // Omitting keys already set in config return answers merged with config values. function runPrompts (opts) { - // TODO remove type check here after further joi additions - if (opts.questionnaire && lodash.isArray(this.init.configure)) { + if (opts.questionnaire && this.init.configure) { this.sprout.emit('msg', 'running questionnaire function') return opts.questionnaire(this.init.configure, lodash.keys(this.config)) .then((answers) => { return lodash.assign(this.config, answers) })