mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-04 14:19:13 -04:00
Added support for plugins
This commit is contained in:
parent
105016bd60
commit
4c2f4d2384
3 changed files with 6 additions and 5 deletions
|
@ -90,6 +90,7 @@ exports.expressCreateServer = async (hookName: string, args: any, cb: Function)
|
|||
const pluginModules = new Set();
|
||||
for (const part of plugins.parts) {
|
||||
for (const [, hookFnName] of Object.entries(part.client_hooks || {})) {
|
||||
console.log(hookFnName.split(':')[0])
|
||||
pluginModules.add(hookFnName.split(':')[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ const disabledHookReasons = {
|
|||
},
|
||||
};
|
||||
|
||||
const loadFn = (path, hookName) => {
|
||||
const loadFn = (path, hookName, modules) => {
|
||||
let functionName;
|
||||
const parts = path.split(':');
|
||||
|
||||
|
@ -24,7 +24,7 @@ const loadFn = (path, hookName) => {
|
|||
functionName = parts[1];
|
||||
}
|
||||
|
||||
let fn = require(path);
|
||||
let fn = modules ? modules.get(path) : require(/* webpackIgnore: true */ path);
|
||||
functionName = functionName ? functionName : hookName;
|
||||
|
||||
for (const name of functionName.split('.')) {
|
||||
|
@ -33,7 +33,7 @@ const loadFn = (path, hookName) => {
|
|||
return fn;
|
||||
};
|
||||
|
||||
const extractHooks = (parts, hookSetName, normalizer) => {
|
||||
const extractHooks = (parts, hookSetName, normalizer, modules) => {
|
||||
const hooks = {};
|
||||
for (const part of parts) {
|
||||
for (const [hookName, regHookFnName] of Object.entries(part[hookSetName] || {})) {
|
||||
|
@ -53,7 +53,7 @@ const extractHooks = (parts, hookSetName, normalizer) => {
|
|||
}
|
||||
let hookFn;
|
||||
try {
|
||||
hookFn = loadFn(hookFnName, hookName);
|
||||
hookFn = loadFn(hookFnName, hookName, modules);
|
||||
if (!hookFn) throw new Error('Not a function');
|
||||
} catch (err) {
|
||||
console.error(`Failed to load hook function "${hookFnName}" for plugin "${part.plugin}" ` +
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
window.plugins.baseURL = basePath;
|
||||
await window.plugins.update(new Map([
|
||||
<% 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).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue