v1.18.x
Julian Lam 9 years ago
parent 1d607cbed7
commit 1d7a5f58e2

@ -79,31 +79,36 @@ module.exports = function(Meta) {
],
// modules listed below are routed through express (/src/modules) so they can be defined anonymously
modules: [
'./node_modules/chart.js/Chart.js',
'./node_modules/mousetrap/mousetrap.js',
modules: {
"Chart.js": './node_modules/chart.js/Chart.js',
"mousetrap.js": './node_modules/mousetrap/mousetrap.js',
'public/vendor/buzz/buzz.js'
]
"buzz.js": 'public/vendor/buzz/buzz.js'
}
}
};
Meta.js.bridgeModules = function(app, callback) {
// Add routes for AMD-type modules to serve those files
var numBridged = 0;
var numBridged = 0,
addRoute = function(relPath) {
app.get('/src/modules/' + relPath, function(req, res) {
return res.sendFile(path.join(__dirname, '../../', Meta.js.scripts.modules[relPath]), {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
});
};
async.series([
function(next) {
async.each(Meta.js.scripts.modules, function(localPath, next) {
app.get('/src/modules/' + path.basename(localPath), function(req, res) {
return res.sendFile(path.join(__dirname, '../../', localPath), {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
});
for(var relPath in Meta.js.scripts.modules) {
if (Meta.js.scripts.modules.hasOwnProperty(relPath)) {
addRoute(relPath);
++numBridged;
}
}
++numBridged;
next();
}, next);
next();
}
], function(err) {
if (err) {

@ -176,10 +176,19 @@ module.exports = function(Plugins) {
winston.verbose('[plugins] Found ' + pluginData.modules.length + ' AMD-style module(s) for plugin ' + pluginData.id);
}
meta.js.scripts.modules = meta.js.scripts.modules.concat(pluginData.modules.map(function(file) {
return path.join('./node_modules/', pluginData.id, file);
}));
}
var modules = {},
strip = pluginData.hasOwnProperty('modulesStrip') ? parseInt(pluginData.modulesStrip, 10) : 0;
pluginData.modules.forEach(function(file) {
if (strip) {
modules[file.replace(new RegExp('\.?(\/[^\/]+){' + strip + '}\/'), '')] = path.join('./node_modules/', pluginData.id, file);
} else {
modules[path.basename(file)] = path.join('./node_modules/', pluginData.id, file);
}
});
meta.js.scripts.modules = _.extend(meta.js.scripts.modules, modules);
} /* one could conceivably add an else..if here for plugins to pass modules in as an Object */
callback();
};

Loading…
Cancel
Save