var fs = require('fs'), path = require('path'), RDB = require('./redis.js'), async = require('async'), winston = require('winston'), plugins = { libraries: [], loadedHooks: {}, init: function() { if (this.initialized) return; if (global.env === 'development') winston.info('[plugins] Initializing plugins system'); var _self = this; // Read the list of activated plugins and require their libraries async.waterfall([ function(next) { RDB.smembers('plugins:active', next); }, function(plugins, next) { async.each(plugins, function(plugin) { // TODO: Update this check to also check node_modules var pluginPath = path.join(__dirname, '../plugins/', plugin); fs.exists(pluginPath, function(exists) { if (exists) { fs.readFile(path.join(pluginPath, 'plugin.json'), function(err, data) { if (err) return next(err); var pluginData = JSON.parse(data); _self.libraries[pluginData.id] = require(path.join(pluginPath, pluginData.library)); if (pluginData.hooks) { for(var x=0,numHooks=pluginData.hooks.length;x