From f1e41b06169519960c73df000a78c1c32b0e92f5 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Sat, 13 Apr 2024 15:00:02 -0700 Subject: [PATCH] bin/haraka: also list installed NPM plugins (#3310) When running `haraka -l`, also list NPM installed plugins. related to haraka/haraka-plugin-access#25 --- .release | 2 +- Changes.md | 1 + bin/haraka | 37 ++++++++++++++++++++++--------------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.release b/.release index 0890e945e..7cd5707f7 160000 --- a/.release +++ b/.release @@ -1 +1 @@ -Subproject commit 0890e945e4e061c96c7b2ab45017525904c17728 +Subproject commit 7cd5707f7d69f8d4dca1ec407ada911890e59d0a diff --git a/Changes.md b/Changes.md index c01b1767d..4a5e9a175 100644 --- a/Changes.md +++ b/Changes.md @@ -13,6 +13,7 @@ #### Fixed +- fix(bin/haraka): list NPM installed plugin #3310 - fix(bin/haraka): get hook list from doc/Plugins #3306 - fix(outbound): call cb even if no MX is found - fix(helo.checks): declare reject.literal_mismatch as boolean diff --git a/bin/haraka b/bin/haraka index 0c535751f..b970e8c06 100755 --- a/bin/haraka +++ b/bin/haraka @@ -83,30 +83,37 @@ Options: --set-relay \t\tSet connection.relaying `; +function listPlugins (b, dir = 'plugins/') { -function listPlugins (b, dir) { + const inital_dir = path.join((b ?? base), dir); + const plugin_dirs = [ inital_dir ] - if (!dir) dir = "plugins/"; + for (const d of fs.readdirSync(inital_dir)) { + if (fs.statSync(path.join(inital_dir, d)).isDirectory()) { + plugin_dirs.push(path.join(inital_dir, d)); + } + } - let plist = `${dir}\n`; - const subdirs = []; - const gl = path.join((b ? b : base), dir); + let plugin_list = `` + for (const pd of plugin_dirs) { + plugin_list += `\n${pd.match(/plugins.*$/)[0]}\n`; - for (const p of fs.readdirSync(gl)) { - const stat = fs.statSync(`${gl}/${p}`); - if (stat.isFile() && ~p.search('.js')) { - plist += `\t${p.replace('.js', '')}\n`; - } - else if (stat.isDirectory()) { - subdirs.push(`${dir + p}/`); + for (const d of fs.readdirSync(pd)) { + if (fs.statSync(path.join(pd, d)).isFile() && ~d.search('.js')) { + plugin_list += `\t${d.replace('.js', '')}\n`; + } } } - for (const s of subdirs) { - plist += `\n${listPlugins(b, s)}`; + plugin_list += `\nNPM packages (${b ?? base})\n` + const npm_plugins = [] + for (const entry of fs.readdirSync(path.join(b ?? base, 'node_modules'))) { + if (!/^haraka-plugin-/.test(entry)) continue + npm_plugins.push(entry.split('-').slice(2).join('-')) } + plugin_list += `\t${npm_plugins.join('\n\t')}\n` - return plist; + return plugin_list; } // Warning messsage