Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions gulp/utils/pagesHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*
Expand Down Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down