From a3cab53b732dc3019fc1a053b9fa97ec6c5f1b5e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 22 Aug 2013 10:47:24 -0400 Subject: [PATCH] added username mentions plugin to default, and tweaked admin panel to show plugins installed via npm --- package.json | 3 ++- src/plugins.js | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index ed0c057ace..0a71eeb5cf 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "cheerio": "~0.12.0", "request": "~2.25.0", "reds": "~0.2.4", - "winston": "~0.7.2" + "winston": "~0.7.2", + "nodebb-plugin-mentions": "~0.1.0" }, "bugs": { "url": "https://github.com/designcreateplay/NodeBB/issues" diff --git a/src/plugins.js b/src/plugins.js index 4bad96d7e1..2c1acf8739 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -156,26 +156,49 @@ var fs = require('fs'), showInstalled: function(callback) { // TODO: Also check /node_modules var _self = this; - moduleBasePath = path.join(__dirname, '../plugins'); + localPluginPath = path.join(__dirname, '../plugins'), + npmPluginPath = path.join(__dirname, '../node_modules'); async.waterfall([ function(next) { - fs.readdir(moduleBasePath, next); + async.parallel([ + function(next) { + fs.readdir(localPluginPath, next); + }, + function(next) { + fs.readdir(npmPluginPath, next); + } + ], function(err, dirs) { + if (err) return next(err); + + dirs[0] = dirs[0].map(function(file) { + return path.join(localPluginPath, file); + }).filter(function(file) { + var stats = fs.statSync(file); + if (stats.isDirectory()) return true; + else return false; + }); + + dirs[1] = dirs[1].map(function(file) { + return path.join(npmPluginPath, file); + }).filter(function(file) { + var stats = fs.statSync(file); + if (stats.isDirectory() && file.substr(npmPluginPath.length+1, 14) === 'nodebb-plugin-') return true; + else return false; + }); + + next(err, dirs[0].concat(dirs[1])); + }); }, function(files, next) { var plugins = []; async.each(files, function(file, next) { - var modulePath = path.join(moduleBasePath, file), - configPath; + var configPath; async.waterfall([ function(next) { - fs.stat(path.join(moduleBasePath, file), next); - }, - function(stats, next) { - if (stats.isDirectory()) fs.readFile(path.join(modulePath, 'plugin.json'), next); - else next(new Error('not-a-directory')); + fs.readFile(path.join(file, 'plugin.json'), next); }, function(configJSON, next) { var config = JSON.parse(configJSON);