Added support for plugins

This commit is contained in:
SamTV12345 2024-07-13 21:45:25 +02:00 committed by SamTv12345
parent b7e0e6b216
commit 85dc9c088f
3 changed files with 6 additions and 5 deletions

View file

@ -90,6 +90,7 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function)
const pluginModules = new Set(); const pluginModules = new Set();
for (const part of plugins.parts) { for (const part of plugins.parts) {
for (const [, hookFnName] of Object.entries(part.client_hooks || {})) { for (const [, hookFnName] of Object.entries(part.client_hooks || {})) {
console.log(hookFnName.split(':')[0])
pluginModules.add(hookFnName.split(':')[0]); pluginModules.add(hookFnName.split(':')[0]);
} }
} }

View file

@ -9,7 +9,7 @@ const disabledHookReasons = {
}, },
}; };
const loadFn = (path, hookName) => { const loadFn = (path, hookName, modules) => {
let functionName; let functionName;
const parts = path.split(':'); const parts = path.split(':');
@ -24,7 +24,7 @@ const loadFn = (path, hookName) => {
functionName = parts[1]; functionName = parts[1];
} }
let fn = require(path); let fn = modules ? modules.get(path) : require(/* webpackIgnore: true */ path);
functionName = functionName ? functionName : hookName; functionName = functionName ? functionName : hookName;
for (const name of functionName.split('.')) { for (const name of functionName.split('.')) {
@ -33,7 +33,7 @@ const loadFn = (path, hookName) => {
return fn; return fn;
}; };
const extractHooks = (parts, hookSetName, normalizer) => { const extractHooks = (parts, hookSetName, normalizer, modules) => {
const hooks = {}; const hooks = {};
for (const part of parts) { for (const part of parts) {
for (const [hookName, regHookFnName] of Object.entries(part[hookSetName] || {})) { for (const [hookName, regHookFnName] of Object.entries(part[hookSetName] || {})) {
@ -53,7 +53,7 @@ const extractHooks = (parts, hookSetName, normalizer) => {
} }
let hookFn; let hookFn;
try { try {
hookFn = loadFn(hookFnName, hookName); hookFn = loadFn(hookFnName, hookName, modules);
if (!hookFn) throw new Error('Not a function'); if (!hookFn) throw new Error('Not a function');
} catch (err) { } catch (err) {
console.error(`Failed to load hook function "${hookFnName}" for plugin "${part.plugin}" ` + console.error(`Failed to load hook function "${hookFnName}" for plugin "${part.plugin}" ` +

View file

@ -27,7 +27,7 @@
window.plugins.baseURL = basePath; window.plugins.baseURL = basePath;
await window.plugins.update(new Map([ await window.plugins.update(new Map([
<% for (const module of pluginModules) { %> <% for (const module of pluginModules) { %>
[<%- JSON.stringify(module) %>, require(<%- JSON.stringify(module) %>)], [<%- JSON.stringify(module) %>, require("../../src/plugin_packages/"+<%- JSON.stringify(module) %>)],
<% } %> <% } %>
])); ]));
// Mechanism for tests to register hook functions (install fake plugins). // Mechanism for tests to register hook functions (install fake plugins).