diff --git a/bin/haraka b/bin/haraka index 5d41b39b1..93da9e23a 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,37 @@ 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 (b, dir) { + + if (!dir) { dir = "plugins/"; } + + var plist = dir + "\n", + subdirs = [], + gl = path.join((b ? b : base), dir), + pd = fs.readdirSync(gl); + + pd.forEach(function (p) { + if (~p.search('.js')) { + plist += "\t" + p.replace('.js', '') + "\n"; + } else { + subdirs.push(dir + p + "/"); + } + }); + + subdirs.forEach(function (s) { + plist += "\n" + listPlugins(b, s); + }); + + return plist; + +} + + // Show message when create function create(path) { // console.log('\x1b[32mcreate\x1b[0m: ' + path); @@ -167,6 +196,12 @@ function createReadme(readmePath) { if (parsed.version) { console.log("\033[32;40mHaraka.js\033[0m — Version: " + ver); } +else if (parsed.list) { + 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') { console.log(usage); @@ -188,6 +223,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'));