widget-loader
Advanced tools
Comparing version 1.0.0 to 1.0.1
"use strict"; | ||
const _ = require('lodash'); | ||
const sequence = require('when/sequence'); | ||
const path = require('path'); | ||
@@ -9,2 +11,4 @@ const fs = require('fs'); | ||
module.exports = function (App, opts) { | ||
@@ -30,3 +34,3 @@ | ||
// Check for an actual class, catch just use whatever was returned | ||
if (typeof AppClass === 'function') { | ||
if (_.isFunction(AppClass)) { | ||
app = new AppClass(); | ||
@@ -112,5 +116,5 @@ } else { | ||
function sortWidgets (widgetCollection) { | ||
let widgetPositions = Object.keys(widgetCollection); | ||
let widgetPositions = _.keys(widgetCollection); | ||
widgetPositions.forEach(function (key) { | ||
_.each(widgetPositions, function (key) { | ||
widgetCollection[key].sort(function (obj1, obj2) { | ||
@@ -138,3 +142,3 @@ return obj1.config.order - obj2.config.order; | ||
// filter and get widgets for only this specific page | ||
filteredWidgets = WidgetCollection.filter(function (widget) { | ||
filteredWidgets = _.filter(WidgetCollection, function (widget) { | ||
return widget.config.active && matchRoute(widget.config.routes, req.path); | ||
@@ -144,3 +148,3 @@ }); | ||
// execute widget request and extract return data | ||
widgetOps = filteredWidgets.map(function (widget) { | ||
widgetOps = _.map(filteredWidgets, function (widget) { | ||
return function () { | ||
@@ -161,3 +165,3 @@ return widget.exec(App) | ||
if (!Array.isArray(CurrentWidgetCollection[position])) { | ||
if (!_.isArray(CurrentWidgetCollection[position])) { | ||
CurrentWidgetCollection[position] = []; | ||
@@ -173,2 +177,3 @@ } | ||
next(error); | ||
//req.flash('error', { msg: errory.message }); | ||
}); | ||
@@ -179,3 +184,3 @@ }; | ||
// when widgets are loaded, continue | ||
Promise.all(widgetOps) | ||
sequence(widgetOps) | ||
.then(function () { | ||
@@ -182,0 +187,0 @@ //console.timeEnd('middlware'); |
{ | ||
"name": "widget-loader", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Widget loader for WidGet CMS", | ||
@@ -28,3 +28,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"ghost-sandbox": "^1.0.0" | ||
"ghost-sandbox": "^1.0.1", | ||
"lodash": "^4.16.4", | ||
"when": "^3.7.7" | ||
}, | ||
@@ -36,4 +38,4 @@ "devDependencies": { | ||
"supertest": "^1.2.0", | ||
"mocha": "^2.5.3" | ||
"mocha": "^3.1.0" | ||
} | ||
} |
@@ -47,5 +47,16 @@ "use strict"; | ||
.get('/') | ||
.expect(200, done); | ||
.expect('Content-Type', /json/) | ||
.expect(200) | ||
.end(function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
Object.keys(res.body).length.should.be.gt(0); | ||
done() | ||
});; | ||
}); | ||
}); | ||
}); |
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
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
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
10469
11
226
3
1
+ Addedlodash@^4.16.4
+ Addedwhen@^3.7.7
+ Addedlodash@4.17.21(transitive)
+ Addedwhen@3.7.8(transitive)
Updatedghost-sandbox@^1.0.1