|
|
@ -17,8 +17,31 @@ var fs = require('fs'),
|
|
|
|
if (this.initialized) return;
|
|
|
|
if (this.initialized) return;
|
|
|
|
if (global.env === 'development') winston.info('[plugins] Initializing plugins system');
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
// Read the list of activated plugins and require their libraries
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function(next) {
|
|
|
|
function(next) {
|
|
|
@ -47,23 +70,8 @@ var fs = require('fs'),
|
|
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
], function(err) {
|
|
|
|
], callback);
|
|
|
|
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');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
ready: function(callback) {
|
|
|
|
|
|
|
|
if (!this.initialized) this.readyEvent.once('ready', callback);
|
|
|
|
|
|
|
|
else callback();
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
initialized: false,
|
|
|
|
|
|
|
|
loadPlugin: function(pluginPath, callback) {
|
|
|
|
loadPlugin: function(pluginPath, callback) {
|
|
|
|
var _self = this;
|
|
|
|
var _self = this;
|
|
|
|
|
|
|
|
|
|
|
@ -80,16 +88,25 @@ var fs = require('fs'),
|
|
|
|
|
|
|
|
|
|
|
|
fs.exists(libraryPath, function(exists) {
|
|
|
|
fs.exists(libraryPath, function(exists) {
|
|
|
|
if (exists) {
|
|
|
|
if (exists) {
|
|
|
|
|
|
|
|
if (!_self.libraries[pluginData.id]) {
|
|
|
|
_self.libraries[pluginData.id] = require(libraryPath);
|
|
|
|
_self.libraries[pluginData.id] = require(libraryPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Register hooks for this plugin
|
|
|
|
if (pluginData.hooks && Array.isArray(pluginData.hooks) && pluginData.hooks.length > 0) {
|
|
|
|
if (pluginData.hooks && Array.isArray(pluginData.hooks) && pluginData.hooks.length > 0) {
|
|
|
|
async.each(pluginData.hooks, function(hook, next) {
|
|
|
|
async.each(pluginData.hooks, function(hook, next) {
|
|
|
|
_self.registerHook(pluginData.id, hook, next);
|
|
|
|
_self.registerHook(pluginData.id, hook, next);
|
|
|
|
}, 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) {
|
|
|
|
function(next) {
|
|
|
|
// Static Directories for Plugins
|
|
|
|
// Static Directories for Plugins
|
|
|
|