Skip to content
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
4 changes: 2 additions & 2 deletions src/node/hooks/express/adminplugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ exports.expressCreateServer = (hookName, args, cb) => {
epVersion,
installedPlugins: `<pre>${plugins.formatPlugins().replace(/, /g, '\n')}</pre>`,
installedParts: `<pre>${plugins.formatParts()}</pre>`,
installedServerHooks: `<div>${plugins.formatHooks()}</div>`,
installedClientHooks: `<div>${plugins.formatHooks('client_hooks')}</div>`,
installedServerHooks: `<div>${plugins.formatHooks('hooks', true)}</div>`,
installedClientHooks: `<div>${plugins.formatHooks('client_hooks', true)}</div>`,
latestVersion: UpdateCheck.getLatestVersion(),
req,
}));
Expand Down
2 changes: 1 addition & 1 deletion src/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ exports.start = async () => {
.join(', ');
logger.info(`Installed plugins: ${installedPlugins}`);
logger.debug(`Installed parts:\n${plugins.formatParts()}`);
logger.debug(`Installed hooks:\n${plugins.formatHooks()}`);
logger.debug(`Installed server-side hooks:\n${plugins.formatHooks('hooks', false)}`);
await hooks.aCallAll('loadSettings', {settings});
await hooks.aCallAll('createServer');
} catch (err) {
Expand Down
48 changes: 40 additions & 8 deletions src/static/js/pluginfw/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,48 @@ exports.formatPlugins = () => Object.keys(defs.plugins).join(', ');

exports.formatParts = () => defs.parts.map((part) => part.full_name).join('\n');

exports.formatHooks = (hookSetName) => {
const res = [];
const hooks = pluginUtils.extractHooks(defs.parts, hookSetName || 'hooks');
for (const registeredHooks of Object.values(hooks)) {
for (const hook of registeredHooks) {
res.push(`<dt>${hook.hook_name}</dt><dd>${hook.hook_fn_name} ` +
`from ${hook.part.full_name}</dd>`);
exports.formatHooks = (hookSetName, html) => {
let hooks = new Map();
for (const [pluginName, def] of Object.entries(defs.plugins)) {
for (const part of def.parts) {
for (const [hookName, hookFnName] of Object.entries(part[hookSetName] || {})) {
let hookEntry = hooks.get(hookName);
if (!hookEntry) {
hookEntry = new Map();
hooks.set(hookName, hookEntry);
}
let pluginEntry = hookEntry.get(pluginName);
if (!pluginEntry) {
pluginEntry = new Map();
hookEntry.set(pluginName, pluginEntry);
}
pluginEntry.set(part.name, hookFnName);
}
}
}
const lines = [];
const sortStringKeys = (a, b) => String(a[0]).localeCompare(b[0]);
if (html) lines.push('<dl>');
hooks = new Map([...hooks].sort(sortStringKeys));
for (const [hookName, hookEntry] of hooks) {
lines.push(html ? ` <dt>${hookName}:</dt><dd><dl>` : ` ${hookName}:`);
const sortedHookEntry = new Map([...hookEntry].sort(sortStringKeys));
hooks.set(hookName, sortedHookEntry);
for (const [pluginName, pluginEntry] of sortedHookEntry) {
lines.push(html ? ` <dt>${pluginName}:</dt><dd><dl>` : ` ${pluginName}:`);
const sortedPluginEntry = new Map([...pluginEntry].sort(sortStringKeys));
sortedHookEntry.set(pluginName, sortedPluginEntry);
for (const [partName, hookFnName] of sortedPluginEntry) {
lines.push(html
? ` <dt>${partName}:</dt><dd>${hookFnName}</dd>`
: ` ${partName}: ${hookFnName}`);
}
if (html) lines.push(' </dl></dd>');
}
if (html) lines.push(' </dl></dd>');
}
return `<dl>${res.join('\n')}</dl>`;
if (html) lines.push('</dl>');
return lines.join('\n');
};

const callInit = async () => {
Expand Down
7 changes: 4 additions & 3 deletions src/static/js/pluginfw/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ const extractHooks = (parts, hookSetName, normalizer) => {
try {
hookFn = loadFn(hookFnName, hookName);
if (!hookFn) throw new Error('Not a function');
} catch (exc) {
console.error(`Failed to load '${hookFnName}' for ` +
`'${part.full_name}/${hookSetName}/${hookName}': ${exc.toString()}`);
} catch (err) {
console.error(`Failed to load hook function "${hookFnName}" for plugin "${part.plugin}" ` +
`part "${part.name}" hook set "${hookSetName}" hook "${hookName}": ` +
`${err.stack || err}`);
}
if (hookFn) {
if (hooks[hookName] == null) hooks[hookName] = [];
Expand Down