diff --git a/gulp/utils/pagesHelpers.js b/gulp/utils/pagesHelpers.js index 4496ff1..3be9ea2 100644 --- a/gulp/utils/pagesHelpers.js +++ b/gulp/utils/pagesHelpers.js @@ -2,6 +2,7 @@ var yamljs = require('yamljs'); var _ = require('lodash'); var markdown = require('marked'); +var chalk = require('chalk'); module.exports = function (config) { var srcDir = config.basePaths.src; @@ -15,6 +16,25 @@ module.exports = function (config) { return value !== null && value !== undefined; } + function generateExtraOptionsError (extraOptions) { + throw new Error( + 'Option' + (extraOptions.length > 1 ? 's ' : ' ') + + '\'' + chalk.blue(extraOptions.join('\', \'')) + '\' ' + + (extraOptions.length > 1 ? 'aren\'t' : 'isn\'t') + ' defined.' + ); + } + + function validatesOptionsKeysPresentOnSchema(options, optionsSchema) { + var optionsKeys = Object.keys(options || {}); + var optionsSchemaKeys = Object.keys(optionsSchema || {}); + + var extraKeys = _.difference(optionsKeys, optionsSchemaKeys); + + if (extraKeys.length > 0) { + generateExtraOptionsError(extraKeys); + } + } + /** * Merges a simple component option with its default * @@ -89,6 +109,16 @@ module.exports = function (config) { options = options || {}; schema = yamljs.load(srcDir + path + '/definition.yml'); optionsSchema = schema.options; + + try { + validatesOptionsKeysPresentOnSchema(options, optionsSchema); + } catch (e) { + console.warn( + chalk.yellow('Error while instanciating ') + chalk.blue(path) + + chalk.yellow('. ' + e.message) + ); + } + return _.mapValues(optionsSchema, function(o, oKey) { // Handle simple option (options that are just an array) if (Array.isArray(o)) { diff --git a/package.json b/package.json index 83cdfc3..d8abd83 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "devDependencies": { "bower": "^1.3.12", "browser-sync": "^2.6.5", + "chalk": "^1.1.0", "del": "^1.1.1", "gulp": "^3.8.11", "gulp-autoprefixer": "^2.2.0",