Skip to content

Commit

Permalink
bin/haraka: also list installed NPM plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Apr 9, 2024
1 parent 9e03658 commit 2e80b79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .release
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

0 comments on commit 2e80b79

Please sign in to comment.