mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-18 16:31:45 +02:00
Only load necessary plugin data
Fix tests to work in this case Add more verbose messages to plugins/data
This commit is contained in:
@@ -125,7 +125,12 @@ function getStaticDirectories(pluginData, callback) {
|
||||
next();
|
||||
});
|
||||
}, function (err) {
|
||||
callback(err, staticDirs);
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
winston.verbose('[plugins] found ' + Object.keys(staticDirs).length +
|
||||
' static directories for ' + pluginData.id);
|
||||
callback(null, staticDirs);
|
||||
});
|
||||
}
|
||||
Data.getStaticDirectories = getStaticDirectories;
|
||||
@@ -135,9 +140,7 @@ function getFiles(pluginData, type, callback) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (global.env === 'development') {
|
||||
winston.verbose('[plugins] Found ' + pluginData[type].length + ' ' + type + ' file(s) for plugin ' + pluginData.id);
|
||||
}
|
||||
winston.verbose('[plugins] Found ' + pluginData[type].length + ' ' + type + ' file(s) for plugin ' + pluginData.id);
|
||||
|
||||
var files = pluginData[type].map(function (file) {
|
||||
return path.join(pluginData.id, file);
|
||||
@@ -202,7 +205,7 @@ function getScripts(pluginData, target, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (scripts.length && global.env === 'development') {
|
||||
if (scripts.length) {
|
||||
winston.verbose('[plugins] Found ' + scripts.length + ' js file(s) for plugin ' + pluginData.id);
|
||||
}
|
||||
callback(err, scripts);
|
||||
@@ -250,10 +253,9 @@ function getModules(pluginData, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (global.env === 'development') {
|
||||
var len = Object.keys(modules).length;
|
||||
winston.verbose('[plugins] Found ' + len + ' AMD-style module(s) for plugin ' + pluginData.id);
|
||||
}
|
||||
var len = Object.keys(modules).length;
|
||||
winston.verbose('[plugins] Found ' + len + ' AMD-style module(s) for plugin ' + pluginData.id);
|
||||
|
||||
callback(null, modules);
|
||||
});
|
||||
}
|
||||
@@ -290,10 +292,9 @@ function getSoundpack(pluginData, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (global.env === 'development') {
|
||||
var len = Object.keys(soundpack).length;
|
||||
winston.verbose('[plugins] Found ' + len + ' sound file(s) for plugin ' + pluginData.id);
|
||||
}
|
||||
var len = Object.keys(soundpack.sounds).length;
|
||||
winston.verbose('[plugins] Found ' + len + ' sound file(s) for plugin ' + pluginData.id);
|
||||
|
||||
callback(null, soundpack);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -67,19 +67,39 @@ module.exports = function (Plugins) {
|
||||
});
|
||||
}
|
||||
|
||||
Plugins.prepareForBuild = function (callback) {
|
||||
Plugins.prepareForBuild = function (targets, callback) {
|
||||
Plugins.cssFiles.length = 0;
|
||||
Plugins.lessFiles.length = 0;
|
||||
Plugins.clientScripts.length = 0;
|
||||
Plugins.acpScripts.length = 0;
|
||||
Plugins.soundpacks.length = 0;
|
||||
|
||||
var map = {
|
||||
'plugin static dirs': ['staticDirs'],
|
||||
'requirejs modules': ['modules'],
|
||||
'client js bundle': ['clientScripts'],
|
||||
'admin js bundle': ['acpScripts'],
|
||||
'client side styles': ['cssFiles', 'lessFiles'],
|
||||
'admin control panel styles': ['cssFiles', 'lessFiles'],
|
||||
sounds: ['soundpack'],
|
||||
};
|
||||
|
||||
var fields = targets.reduce(function (prev, target) {
|
||||
if (!map[target]) {
|
||||
return prev;
|
||||
}
|
||||
return prev.concat(map[target]);
|
||||
}, []).filter(function (field, i, arr) {
|
||||
return arr.indexOf(field) === i;
|
||||
});
|
||||
|
||||
winston.verbose('[plugins] loading the following fields from plugin data: ' + fields.join(', '));
|
||||
|
||||
async.waterfall([
|
||||
Plugins.data.getActive,
|
||||
function (plugins, next) {
|
||||
async.each(plugins, function (pluginData, next) {
|
||||
// TODO: only load the data that's needed for the build
|
||||
registerPluginAssets(pluginData, true, next);
|
||||
registerPluginAssets(pluginData, fields, next);
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
@@ -101,10 +121,7 @@ module.exports = function (Plugins) {
|
||||
registerHooks(pluginData, next);
|
||||
},
|
||||
function (next) {
|
||||
// TODO: change this from `true` to `['soundpack']`
|
||||
// this will skip several build-only plugin loading methods
|
||||
// and only load soundpacks, which will speed up startup
|
||||
registerPluginAssets(pluginData, true, next);
|
||||
registerPluginAssets(pluginData, ['soundpack'], next);
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user