gengojs-core-modules
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -7,2 +7,3 @@ var gulp = require("gulp"); | ||
var jshint = require('gulp-jshint'); | ||
var changelog = require('gulp-changelog'); | ||
@@ -31,4 +32,10 @@ gulp.task("lib:entry", function () { | ||
gulp.task("default", ['lib:entry','watch']); | ||
gulp.task('changelog', function(cb){ | ||
changelog(require('./package.json')).then(function(stream){ | ||
stream.pipe(gulp.dest('./')).on('end', cb); | ||
}); | ||
}); | ||
gulp.task('build', ['lib:entry', 'test']); | ||
gulp.task("default", ['lib:entry','changelog','watch']); | ||
gulp.task('build', ['lib:entry','changelog','test']); |
@@ -9,55 +9,12 @@ /** | ||
debug('core', 'debug', `class: ${Plugify.name}`, `process: constructor`); | ||
// Type stack to keep track which type has been plugged in | ||
this.types = ['api', 'backend', 'parser', 'header', 'localize', 'router']; | ||
// Initialize the plugin | ||
this.plugins = this.init(); | ||
var plugs = this.plugs(plugins); | ||
// Register and then restrict the | ||
// plugins to one plugin per type | ||
// and add defaults if none exist | ||
_.forEach(plugs, function(plugin) { | ||
// Assert | ||
this.assert(plugin); | ||
var type = this.normalize(plugin.package.type); | ||
// If the default plugin already exists | ||
// then remove the default and replace it with | ||
// the user defined plugin | ||
if (this.plugins[type].length === 1) { | ||
if(!_.isUndefined(defaults)) | ||
this.plugins[type].pop(); | ||
// Set the plugin attributes | ||
this.setAttributes(plugin, options); | ||
// If there are multiple plugins of the same type | ||
// restrict it to one plugin | ||
} else if (this.plugins[type].length > 1) { | ||
var length = this.plugins[type].length - 1; | ||
while (length !== 0) { | ||
if(!_.isUndefined(defaults)) | ||
this.plugins[type].pop(); | ||
length--; | ||
} | ||
// Since no there are no default plugins, | ||
// just add the plugin to the stack | ||
}else{ | ||
this.setAttributes(plugin, options); | ||
} | ||
}, this); | ||
// Remove the plugin from array | ||
// and set it as the root | ||
// e.g. this.plugins.backend => array | ||
// becomes this.plugins.backend => object | ||
plugs = this.plugins; | ||
for (var key in plugs) { | ||
if (plugs.hasOwnProperty(key)) { | ||
var element = plugs[key]; | ||
if(element[0]){ | ||
var {type} = element[0].package; | ||
this.plugins[type] = element[0]; | ||
} | ||
} | ||
} | ||
_.forEach(this.plugins,(value, key)=>{ | ||
debug('core', 'info', | ||
this.register(plugins, options, defaults); | ||
this.bundle(); | ||
_.forEach(this.plugins, (value, key) => { | ||
debug('core', 'info', | ||
`class: ${Plugify.name}`, `plugins: ${key}`); | ||
}); | ||
}); | ||
} | ||
@@ -106,30 +63,30 @@ | ||
*/ | ||
plugs (plugins){ | ||
plugs(plugins) { | ||
debug('core', 'debug', `class: ${Plugify.name}`, `process: plugs`); | ||
var plugs = []; | ||
// 'plugins' is a plain object | ||
if (_.isPlainObject(plugins)){ | ||
// A single ship exists | ||
if (_.has(plugins, 'main')) plugs.push(plugins); | ||
else _.forOwn(plugins, (ship)=>{ | ||
try { | ||
// Assert that ship is a function | ||
if (!_.isFunction(ship)) throw new Error | ||
('Uh oh! The ship must be a function!'); | ||
if (!_.isPlainObject(ship())) throw new Error | ||
('Woops! Did the ship forget to return a plain object?'); | ||
} catch (error) { | ||
debug('core', 'error', `class: ${Plugify.name}`, | ||
`error: ${error.stack || error.toString()}`); | ||
} | ||
plugs.push(ship()); | ||
}); | ||
} | ||
if (_.isArray(plugins)) plugs = plugins; | ||
if (_.isFunction(plugins)) { | ||
if (!_.isPlainObject(plugins())) throw new Error | ||
('Woops! Did the ship forget to return a plain object?'); | ||
plugs.push(plugins()); | ||
} | ||
return plugs; | ||
// 'plugins' is a plain object | ||
if (_.isPlainObject(plugins)) { | ||
// A single ship exists | ||
if (_.has(plugins, 'main')) plugs.push(plugins); | ||
else _.forOwn(plugins, (ship) => { | ||
try { | ||
// Assert that ship is a function | ||
if (!_.isFunction(ship)) throw new Error | ||
('Uh oh! The ship must be a function!'); | ||
if (!_.isPlainObject(ship())) throw new Error | ||
('Woops! Did the ship forget to return a plain object?'); | ||
} catch (error) { | ||
debug('core', 'error', `class: ${Plugify.name}`, | ||
`error: ${error.stack || error.toString() }`); | ||
} | ||
plugs.push(ship()); | ||
}); | ||
} | ||
if (_.isArray(plugins)) plugs = plugins; | ||
if (_.isFunction(plugins)) { | ||
if (!_.isPlainObject(plugins())) throw new Error | ||
('Woops! Did the ship forget to return a plain object?'); | ||
plugs.push(plugins()); | ||
} | ||
return plugs; | ||
} | ||
@@ -156,7 +113,81 @@ /** | ||
('Woops! Did you forget to add the "defaults"?'); | ||
} catch (error) { | ||
debug('core', 'error', `class: ${Plugify.name}`, | ||
`error: ${error.stack || error.toString()}`); | ||
} catch (error) { | ||
debug('core', 'error', `class: ${Plugify.name}`, | ||
`error: ${error.stack || error.toString() }`); | ||
} | ||
} | ||
/** | ||
* @private | ||
* 'register' registers the plugins and sets the attributes. | ||
*/ | ||
register(plugins, options, defaults) { | ||
var plugs = this.plugs(plugins); | ||
// Register and then restrict the | ||
// plugins to one plugin per type | ||
// and add defaults if none exist | ||
_.forEach(plugs, function (plugin) { | ||
// Assert | ||
this.assert(plugin); | ||
var type = this.normalize(plugin.package.type); | ||
// If the default plugin already exists | ||
// then remove the default and replace it with | ||
// the user defined plugin | ||
if (this.plugins[type].length === 1) { | ||
if (!_.isUndefined(defaults)) | ||
this.plugins[type].pop(); | ||
// Set the plugin attributes | ||
this.setAttributes(plugin, options); | ||
// If there are multiple plugins of the same type | ||
// restrict it to one plugin | ||
} else if (this.plugins[type].length > 1) { | ||
var length = this.plugins[type].length - 1; | ||
while (length !== 0) { | ||
if (!_.isUndefined(defaults)) | ||
this.plugins[type].pop(); | ||
length--; | ||
} | ||
// Since no there are no default plugins, | ||
// just add the plugin to the stack | ||
} else { | ||
this.setAttributes(plugin, options); | ||
} | ||
}, this); | ||
} | ||
/** | ||
* @private | ||
* 'bundle' bundles the plugins and transforms the plugin | ||
* stack from an array to an object. It also makes sure | ||
* that the stack has a fn placeholder to prevent an undefined | ||
* object from being used as a function | ||
*/ | ||
bundle() { | ||
// Remove the plugin from array | ||
// and set it as the root | ||
// e.g. this.plugins.backend => array | ||
// becomes this.plugins.backend => object | ||
var plugs = this.plugins; | ||
for (var key in plugs) { | ||
if (plugs.hasOwnProperty(key)) { | ||
var element = plugs[key]; | ||
if (element[0]) { | ||
// Get the type | ||
var {type} = element[0].package; | ||
// Get the index of the type from the types stack | ||
var index = this.types.indexOf(this.normalize(type)); | ||
// Remove the type from the stack since it is registered | ||
if (index > -1) this.types.splice(index, 1); | ||
// Register the plugin | ||
this.plugins[this.normalize(type)] = element[0]; | ||
} else { | ||
if (!_.isEmpty(this.types)) { | ||
// Get a random type from the stack and | ||
// set a placeholder plugin in case it doesn't exist | ||
this.plugins[this.normalize(this.types[0])] = () => { }; | ||
// Remove the type from the stack | ||
this.types.pop(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -163,0 +194,0 @@ |
@@ -29,50 +29,8 @@ /** | ||
(0, _gengojsDebug2['default'])('core', 'debug', 'class: ' + Plugify.name, 'process: constructor'); | ||
// Type stack to keep track which type has been plugged in | ||
this.types = ['api', 'backend', 'parser', 'header', 'localize', 'router']; | ||
// Initialize the plugin | ||
this.plugins = this.init(); | ||
var plugs = this.plugs(plugins); | ||
// Register and then restrict the | ||
// plugins to one plugin per type | ||
// and add defaults if none exist | ||
_lodash2['default'].forEach(plugs, function (plugin) { | ||
// Assert | ||
this.assert(plugin); | ||
var type = this.normalize(plugin['package'].type); | ||
// If the default plugin already exists | ||
// then remove the default and replace it with | ||
// the user defined plugin | ||
if (this.plugins[type].length === 1) { | ||
if (!_lodash2['default'].isUndefined(defaults)) this.plugins[type].pop(); | ||
// Set the plugin attributes | ||
this.setAttributes(plugin, options); | ||
// If there are multiple plugins of the same type | ||
// restrict it to one plugin | ||
} else if (this.plugins[type].length > 1) { | ||
var length = this.plugins[type].length - 1; | ||
while (length !== 0) { | ||
if (!_lodash2['default'].isUndefined(defaults)) this.plugins[type].pop(); | ||
length--; | ||
} | ||
// Since no there are no default plugins, | ||
// just add the plugin to the stack | ||
} else { | ||
this.setAttributes(plugin, options); | ||
} | ||
}, this); | ||
// Remove the plugin from array | ||
// and set it as the root | ||
// e.g. this.plugins.backend => array | ||
// becomes this.plugins.backend => object | ||
plugs = this.plugins; | ||
for (var key in plugs) { | ||
if (plugs.hasOwnProperty(key)) { | ||
var element = plugs[key]; | ||
if (element[0]) { | ||
var type = element[0]['package'].type; | ||
this.plugins[type] = element[0]; | ||
} | ||
} | ||
} | ||
this.register(plugins, options, defaults); | ||
this.bundle(); | ||
_lodash2['default'].forEach(this.plugins, function (value, key) { | ||
@@ -180,2 +138,81 @@ (0, _gengojsDebug2['default'])('core', 'info', 'class: ' + Plugify.name, 'plugins: ' + key); | ||
} | ||
/** | ||
* @private | ||
* 'register' registers the plugins and sets the attributes. | ||
*/ | ||
}, { | ||
key: 'register', | ||
value: function register(plugins, options, defaults) { | ||
var plugs = this.plugs(plugins); | ||
// Register and then restrict the | ||
// plugins to one plugin per type | ||
// and add defaults if none exist | ||
_lodash2['default'].forEach(plugs, function (plugin) { | ||
// Assert | ||
this.assert(plugin); | ||
var type = this.normalize(plugin['package'].type); | ||
// If the default plugin already exists | ||
// then remove the default and replace it with | ||
// the user defined plugin | ||
if (this.plugins[type].length === 1) { | ||
if (!_lodash2['default'].isUndefined(defaults)) this.plugins[type].pop(); | ||
// Set the plugin attributes | ||
this.setAttributes(plugin, options); | ||
// If there are multiple plugins of the same type | ||
// restrict it to one plugin | ||
} else if (this.plugins[type].length > 1) { | ||
var length = this.plugins[type].length - 1; | ||
while (length !== 0) { | ||
if (!_lodash2['default'].isUndefined(defaults)) this.plugins[type].pop(); | ||
length--; | ||
} | ||
// Since no there are no default plugins, | ||
// just add the plugin to the stack | ||
} else { | ||
this.setAttributes(plugin, options); | ||
} | ||
}, this); | ||
} | ||
/** | ||
* @private | ||
* 'bundle' bundles the plugins and transforms the plugin | ||
* stack from an array to an object. It also makes sure | ||
* that the stack has a fn placeholder to prevent an undefined | ||
* object from being used as a function | ||
*/ | ||
}, { | ||
key: 'bundle', | ||
value: function bundle() { | ||
// Remove the plugin from array | ||
// and set it as the root | ||
// e.g. this.plugins.backend => array | ||
// becomes this.plugins.backend => object | ||
var plugs = this.plugins; | ||
for (var key in plugs) { | ||
if (plugs.hasOwnProperty(key)) { | ||
var element = plugs[key]; | ||
if (element[0]) { | ||
// Get the type | ||
var type = element[0]['package'].type; | ||
// Get the index of the type from the types stack | ||
var index = this.types.indexOf(this.normalize(type)); | ||
// Remove the type from the stack since it is registered | ||
if (index > -1) this.types.splice(index, 1); | ||
// Register the plugin | ||
this.plugins[this.normalize(type)] = element[0]; | ||
} else { | ||
if (!_lodash2['default'].isEmpty(this.types)) { | ||
// Get a random type from the stack and | ||
// set a placeholder plugin in case it doesn't exist | ||
this.plugins[this.normalize(this.types[0])] = function () {}; | ||
// Remove the type from the stack | ||
this.types.pop(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}]); | ||
@@ -182,0 +219,0 @@ |
{ | ||
"name": "gengojs-core-modules", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "gengo.js core modules is a set of modules that helps the core to function properly.", | ||
@@ -28,2 +28,3 @@ "main": "./modules/index.js", | ||
"gulp-babel": "^5.2.1", | ||
"gulp-changelog": "^1.0.0", | ||
"gulp-dest": "^0.2.2", | ||
@@ -30,0 +31,0 @@ "gulp-jshint": "^1.11.2", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112316
35
1175
10