mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-04 22:27:10 -04:00
Added support for plugins
This commit is contained in:
parent
b7e0e6b216
commit
85dc9c088f
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();
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}" ` +
|
||||||
|
|
|
@ -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).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue