From 307f6f34b92404e0d7085970f6d8e8f97f6374d9 Mon Sep 17 00:00:00 2001
From: Julian Lam <julian.lam@gmail.com>
Date: Sun, 28 Jul 2013 12:52:58 -0400
Subject: [PATCH] added plugins.showInstalled method

---
 src/plugins.js | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/plugins.js b/src/plugins.js
index d6c5a6db79..cc52ffa017 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -110,6 +110,43 @@ var	fs = require('fs'),
 					break;
 				}
 			}
+		},
+		showInstalled: function() {
+			// TODO: Also check /node_modules
+			var	moduleBasePath = path.join(__dirname, '../plugins');
+
+			async.waterfall([
+				function(next) {
+					fs.readdir(moduleBasePath, next);
+				},
+				function(files, next) {
+					var	plugins = [];
+
+					async.each(files, function(file, next) {
+						var	modulePath = path.join(moduleBasePath, file),
+							configPath;
+
+						fs.stat(path.join(moduleBasePath, file), function(err, stats) {
+							if (err || !stats.isDirectory()) return next();	//Silently fail
+
+							// Load the config file
+							fs.readFile(path.join(modulePath, 'plugin.json'), function(err, configJSON) {
+								if (err) return next();	// Silently fail if config can't be read
+								var	config = JSON.parse(configJSON);
+								delete config.library;
+								delete config.hooks;
+
+								plugins.push(config);
+								next();
+							});
+						});
+					}, function(err) {
+						next(null, plugins);
+					});
+				}
+			], function(err, plugins) {
+				console.log('plugins:', plugins);
+			});
 		}
 	}