mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
fixes #4576
This commit is contained in:
@@ -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;
|
||||
|
||||
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), {
|
||||
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) {
|
||||
for(var relPath in Meta.js.scripts.modules) {
|
||||
if (Meta.js.scripts.modules.hasOwnProperty(relPath)) {
|
||||
addRoute(relPath);
|
||||
++numBridged;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user