From 32048e371c80bb30ba848561a2ef536c84f96c01 Mon Sep 17 00:00:00 2001 From: arlolra Date: Tue, 17 May 2011 22:51:38 -0700 Subject: [PATCH 1/3] require path for custom plugin dependencies --- bin/haraka | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/haraka b/bin/haraka index 89521e85d..735cd348c 100755 --- a/bin/haraka +++ b/bin/haraka @@ -154,6 +154,7 @@ else if (parsed.help) { else if (parsed['configs']) { process.env.HARAKA = parsed['configs']; + require.paths.unshift(path.join(process.env.HARAKA, 'node_modules')); var logger = require(path.join(base, 'logger')) server = require(path.join(base, 'server')); From 32275b33e545df9c680d402c57f77e27b855d536 Mon Sep 17 00:00:00 2001 From: arlolra Date: Thu, 19 May 2011 12:15:59 -0700 Subject: [PATCH 2/3] list bundled plugins to use with -h --- bin/haraka | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/bin/haraka b/bin/haraka index 8780717a2..bbb5aa9a7 100755 --- a/bin/haraka +++ b/bin/haraka @@ -15,13 +15,15 @@ var fs = require('fs'), "version": Boolean, "help": [String, null], "configs": path, - "install": path + "install": path, + "list": Boolean }, shortHands = { "v": ["--version"], "h": ["--help"], "c": ["--configs"], - "i": ["--install"] + "i": ["--install"], + "l": ["--list"] }, parsed = nopt(knownOpts, shortHands, process.argv, 2); @@ -34,10 +36,36 @@ var usage = [ "\t-h, --help \t\tOutputs this help message", "\t-h NAME \t\tShows help for NAME", "\t-c, --configs \t\tPath to your config directory", - "\t-i, --install \t\tCopies the default configs to a specified dir" + "\t-i, --install \t\tCopies the default configs to a specified dir", + "\t-l, --list \t\tList the plugins bundled with Haraka" ].join('\n'); +var listPlugins = function (dir) { + + if (!dir) { dir = "plugins/"; } + + var plist = "\n" + dir + "\n", + subdirs = [], + pd = fs.readdirSync(path.join(base, dir)); + + pd.forEach(function (p) { + if (~p.search('.js')) { + plist += "\t" + p.replace('.js', '') + "\n"; + } else { + subdirs.push(dir + p + "/"); + } + }); + + subdirs.forEach(function (s) { + plist += listPlugins(s); + }); + + return plist; + +} + + // Show message when create function create(path) { // console.log('\x1b[32mcreate\x1b[0m: ' + path); @@ -167,6 +195,9 @@ function createReadme(readmePath) { if (parsed.version) { console.log("\033[32;40mHaraka.js\033[0m — Version: " + ver); } +else if (parsed.list) { + console.log(listPlugins()); +} else if (parsed.help) { if (parsed.help === 'true') { console.log(usage); From 607521aee2eb52cfd11c2d32d11034970b4e04c9 Mon Sep 17 00:00:00 2001 From: arlolra Date: Thu, 19 May 2011 13:32:17 -0700 Subject: [PATCH 3/3] display local plugins with -l if -c /path/ is supplied --- bin/haraka | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/haraka b/bin/haraka index bbb5aa9a7..fd2c46496 100755 --- a/bin/haraka +++ b/bin/haraka @@ -41,13 +41,14 @@ var usage = [ ].join('\n'); -var listPlugins = function (dir) { - +var listPlugins = function (b, dir) { + if (!dir) { dir = "plugins/"; } - var plist = "\n" + dir + "\n", + var plist = dir + "\n", subdirs = [], - pd = fs.readdirSync(path.join(base, dir)); + gl = path.join((b ? b : base), dir), + pd = fs.readdirSync(gl); pd.forEach(function (p) { if (~p.search('.js')) { @@ -58,7 +59,7 @@ var listPlugins = function (dir) { }); subdirs.forEach(function (s) { - plist += listPlugins(s); + plist += "\n" + listPlugins(b, s); }); return plist; @@ -196,7 +197,10 @@ if (parsed.version) { console.log("\033[32;40mHaraka.js\033[0m — Version: " + ver); } else if (parsed.list) { - console.log(listPlugins()); + console.log("\033[32;40m*global\033[0m\n" + listPlugins()); + if (parsed['configs']) { + console.log("\033[32;40m*local\033[0m\n" + listPlugins(parsed['configs'])); + } } else if (parsed.help) { if (parsed.help === 'true') {