mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01: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:
@@ -93,7 +93,7 @@ aliases = Object.keys(aliases).reduce(function (prev, key) {
|
||||
return prev;
|
||||
}, {});
|
||||
|
||||
function beforeBuild(callback) {
|
||||
function beforeBuild(targets, callback) {
|
||||
var db = require('../database');
|
||||
var plugins = require('../plugins');
|
||||
meta = require('../meta');
|
||||
@@ -101,7 +101,9 @@ function beforeBuild(callback) {
|
||||
async.series([
|
||||
db.init,
|
||||
meta.themes.setupPaths,
|
||||
plugins.prepareForBuild,
|
||||
function (next) {
|
||||
plugins.prepareForBuild(targets, next);
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error('[build] Encountered error preparing for build: ' + err.message);
|
||||
@@ -160,6 +162,8 @@ function build(targets, callback) {
|
||||
return arr.indexOf(target) === i;
|
||||
});
|
||||
|
||||
winston.verbose('[build] building the following targets: ' + targets.join(', '));
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function (err) {
|
||||
if (err) {
|
||||
@@ -179,7 +183,9 @@ function build(targets, callback) {
|
||||
var startTime;
|
||||
var totalTime;
|
||||
async.series([
|
||||
beforeBuild,
|
||||
function (next) {
|
||||
beforeBuild(targets, next);
|
||||
},
|
||||
function (next) {
|
||||
var parallel = os.cpus().length > 1 && !nconf.get('series');
|
||||
if (parallel) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -5,6 +5,10 @@ var assert = require('assert');
|
||||
var db = require('./mocks/databasemock');
|
||||
|
||||
describe('Build', function () {
|
||||
before(function (done) {
|
||||
db.setupMockDefaults(done);
|
||||
});
|
||||
|
||||
it('should build all assets', function (done) {
|
||||
this.timeout(50000);
|
||||
var build = require('../src/meta/build');
|
||||
@@ -13,4 +17,8 @@ describe('Build', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -83,42 +83,19 @@
|
||||
|
||||
before(function (done) {
|
||||
this.timeout(30000);
|
||||
var meta;
|
||||
async.waterfall([
|
||||
async.series([
|
||||
function (next) {
|
||||
db.init(next);
|
||||
},
|
||||
function (next) {
|
||||
db.emptydb(next);
|
||||
},
|
||||
function (next) {
|
||||
winston.info('test_database flushed');
|
||||
meta = require('../../src/meta');
|
||||
setupDefaultConfigs(meta, next);
|
||||
},
|
||||
function (next) {
|
||||
meta.configs.init(next);
|
||||
setupMockDefaults(next);
|
||||
},
|
||||
function (next) {
|
||||
db.initSessionStore(next);
|
||||
},
|
||||
function (next) {
|
||||
meta.dependencies.check(next);
|
||||
},
|
||||
function (next) {
|
||||
meta.config.postDelay = 0;
|
||||
meta.config.initialPostDelay = 0;
|
||||
meta.config.newbiePostDelay = 0;
|
||||
var meta = require('../../src/meta');
|
||||
|
||||
enableDefaultPlugins(next);
|
||||
},
|
||||
function (next) {
|
||||
meta.themes.set({
|
||||
type: 'local',
|
||||
id: 'nodebb-theme-persona',
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
// nconf defaults, if not set in config
|
||||
if (!nconf.get('sessionKey')) {
|
||||
nconf.set('sessionKey', 'express.sid');
|
||||
@@ -154,6 +131,40 @@
|
||||
], done);
|
||||
});
|
||||
|
||||
function setupMockDefaults(callback) {
|
||||
var meta = require('../../src/meta');
|
||||
|
||||
async.series([
|
||||
function (next) {
|
||||
db.emptydb(next);
|
||||
},
|
||||
function (next) {
|
||||
winston.info('test_database flushed');
|
||||
setupDefaultConfigs(meta, next);
|
||||
},
|
||||
function (next) {
|
||||
meta.configs.init(next);
|
||||
},
|
||||
function (next) {
|
||||
meta.dependencies.check(next);
|
||||
},
|
||||
function (next) {
|
||||
meta.config.postDelay = 0;
|
||||
meta.config.initialPostDelay = 0;
|
||||
meta.config.newbiePostDelay = 0;
|
||||
|
||||
enableDefaultPlugins(next);
|
||||
},
|
||||
function (next) {
|
||||
meta.themes.set({
|
||||
type: 'local',
|
||||
id: 'nodebb-theme-persona',
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
db.setupMockDefaults = setupMockDefaults;
|
||||
|
||||
function setupDefaultConfigs(meta, next) {
|
||||
winston.info('Populating database with default configs, if not already set...\n');
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ describe('Plugins', function () {
|
||||
assert.ifError(err);
|
||||
assert(plugins.libraries[pluginId]);
|
||||
assert(plugins.loadedHooks['static:app.load']);
|
||||
assert(plugins.staticDirs['nodebb-plugin-markdown/js']);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user