mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
issue #478 - hot-swapping of plugins
This commit is contained in:
@@ -17,8 +17,31 @@ var fs = require('fs'),
|
||||
if (this.initialized) return;
|
||||
if (global.env === 'development') winston.info('[plugins] Initializing plugins system');
|
||||
|
||||
this.reload(function(err) {
|
||||
if (err) {
|
||||
if (global.env === 'development') winston.info('[plugins] NodeBB encountered a problem while loading plugins', err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (global.env === 'development') winston.info('[plugins] Plugins OK');
|
||||
|
||||
plugins.initialized = true;
|
||||
plugins.readyEvent.emit('ready');
|
||||
});
|
||||
},
|
||||
ready: function(callback) {
|
||||
if (!this.initialized) this.readyEvent.once('ready', callback);
|
||||
else callback();
|
||||
},
|
||||
initialized: false,
|
||||
reload: function(callback) {
|
||||
var _self = this;
|
||||
|
||||
// Resetting all local plugin data
|
||||
this.loadedHooks = {};
|
||||
this.staticDirs = {};
|
||||
this.cssFiles.length = 0;
|
||||
|
||||
// Read the list of activated plugins and require their libraries
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
@@ -47,23 +70,8 @@ var fs = require('fs'),
|
||||
|
||||
next();
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
if (global.env === 'development') winston.info('[plugins] NodeBB encountered a problem while loading plugins', err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (global.env === 'development') winston.info('[plugins] Plugins OK');
|
||||
|
||||
_self.initialized = true;
|
||||
_self.readyEvent.emit('ready');
|
||||
});
|
||||
], callback);
|
||||
},
|
||||
ready: function(callback) {
|
||||
if (!this.initialized) this.readyEvent.once('ready', callback);
|
||||
else callback();
|
||||
},
|
||||
initialized: false,
|
||||
loadPlugin: function(pluginPath, callback) {
|
||||
var _self = this;
|
||||
|
||||
@@ -80,16 +88,25 @@ var fs = require('fs'),
|
||||
|
||||
fs.exists(libraryPath, function(exists) {
|
||||
if (exists) {
|
||||
_self.libraries[pluginData.id] = require(libraryPath);
|
||||
if (!_self.libraries[pluginData.id]) {
|
||||
_self.libraries[pluginData.id] = require(libraryPath);
|
||||
}
|
||||
|
||||
// Register hooks for this plugin
|
||||
if (pluginData.hooks && Array.isArray(pluginData.hooks) && pluginData.hooks.length > 0) {
|
||||
async.each(pluginData.hooks, function(hook, next) {
|
||||
_self.registerHook(pluginData.id, hook, next);
|
||||
}, next);
|
||||
}
|
||||
} else {
|
||||
winston.warn('[plugins.reload] Library not found for plugin: ' + pluginData.id);
|
||||
next();
|
||||
}
|
||||
});
|
||||
} else next();
|
||||
} else {
|
||||
winston.warn('[plugins.reload] Library not found for plugin: ' + pluginData.id);
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
// Static Directories for Plugins
|
||||
|
||||
Reference in New Issue
Block a user