Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/haraka: also list installed NPM plugins #3310

Merged
merged 3 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 22 additions & 15 deletions bin/haraka
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading