mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-08 08:01:02 -04:00
Implemented PoC for managing plugins with live-plugin-manager
This commit is contained in:
parent
71a29884d6
commit
69de1608e2
4 changed files with 16 additions and 23 deletions
|
@ -76,6 +76,7 @@ exports.require = (name, args, mod) => {
|
||||||
basedir = path.dirname(mod.filename);
|
basedir = path.dirname(mod.filename);
|
||||||
paths = mod.paths;
|
paths = mod.paths;
|
||||||
}
|
}
|
||||||
|
paths.push(settings.root + '/plugin_packages')
|
||||||
|
|
||||||
const ejspath = resolve.sync(name, {paths, basedir, extensions: ['.html', '.ejs']});
|
const ejspath = resolve.sync(name, {paths, basedir, extensions: ['.html', '.ejs']});
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
"jsdom": "^23.2.0",
|
"jsdom": "^23.2.0",
|
||||||
"jsonminify": "0.4.2",
|
"jsonminify": "0.4.2",
|
||||||
"languages4translatewiki": "0.1.3",
|
"languages4translatewiki": "0.1.3",
|
||||||
|
"live-plugin-manager": "^0.18.1",
|
||||||
"lodash.clonedeep": "4.5.0",
|
"lodash.clonedeep": "4.5.0",
|
||||||
"log4js": "^6.9.1",
|
"log4js": "^6.9.1",
|
||||||
"measured-core": "^2.0.0",
|
"measured-core": "^2.0.0",
|
||||||
|
@ -56,7 +57,6 @@
|
||||||
"npm": "^6.14.18",
|
"npm": "^6.14.18",
|
||||||
"openapi-backend": "^5.10.5",
|
"openapi-backend": "^5.10.5",
|
||||||
"proxy-addr": "^2.0.7",
|
"proxy-addr": "^2.0.7",
|
||||||
"live-plugin-manager": "^0.18.1",
|
|
||||||
"rate-limiter-flexible": "^4.0.0",
|
"rate-limiter-flexible": "^4.0.0",
|
||||||
"rehype": "^13.0.1",
|
"rehype": "^13.0.1",
|
||||||
"rehype-minify-whitespace": "^6.0.0",
|
"rehype-minify-whitespace": "^6.0.0",
|
||||||
|
|
|
@ -37,16 +37,7 @@ const wrapTaskCb = (cb) => {
|
||||||
exports.uninstall = async (pluginName, cb = null) => {
|
exports.uninstall = async (pluginName, cb = null) => {
|
||||||
cb = wrapTaskCb(cb);
|
cb = wrapTaskCb(cb);
|
||||||
logger.info(`Uninstalling plugin ${pluginName}...`);
|
logger.info(`Uninstalling plugin ${pluginName}...`);
|
||||||
try {
|
await exports.manager.uninstall(pluginName);
|
||||||
// The --no-save flag prevents npm from creating package.json or package-lock.json.
|
|
||||||
// The --legacy-peer-deps flag is required to work around a bug in npm v7:
|
|
||||||
// https://github.com/npm/cli/issues/2199
|
|
||||||
await runCmd(['npm', 'uninstall', '--no-save', '--legacy-peer-deps', pluginName]);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error(`Failed to uninstall plugin ${pluginName}`);
|
|
||||||
cb(err || new Error(err));
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
logger.info(`Successfully uninstalled plugin ${pluginName}`);
|
logger.info(`Successfully uninstalled plugin ${pluginName}`);
|
||||||
await hooks.aCallAll('pluginUninstall', {pluginName});
|
await hooks.aCallAll('pluginUninstall', {pluginName});
|
||||||
await plugins.update();
|
await plugins.update();
|
||||||
|
@ -56,16 +47,7 @@ exports.uninstall = async (pluginName, cb = null) => {
|
||||||
exports.install = async (pluginName, cb = null) => {
|
exports.install = async (pluginName, cb = null) => {
|
||||||
cb = wrapTaskCb(cb);
|
cb = wrapTaskCb(cb);
|
||||||
logger.info(`Installing plugin ${pluginName}...`);
|
logger.info(`Installing plugin ${pluginName}...`);
|
||||||
try {
|
await exports.manager.install(pluginName);
|
||||||
// The --no-save flag prevents npm from creating package.json or package-lock.json.
|
|
||||||
// The --legacy-peer-deps flag is required to work around a bug in npm v7:
|
|
||||||
// https://github.com/npm/cli/issues/2199
|
|
||||||
await runCmd(['npm', 'install', '--no-save', '--legacy-peer-deps', pluginName]);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error(`Failed to install plugin ${pluginName}`);
|
|
||||||
cb(err || new Error(err));
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
logger.info(`Successfully installed plugin ${pluginName}`);
|
logger.info(`Successfully installed plugin ${pluginName}`);
|
||||||
await hooks.aCallAll('pluginInstall', {pluginName});
|
await hooks.aCallAll('pluginInstall', {pluginName});
|
||||||
await plugins.update();
|
await plugins.update();
|
||||||
|
|
|
@ -84,6 +84,8 @@ exports.pathNormalization = (part, hookFnName, hookName) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update = async () => {
|
exports.update = async () => {
|
||||||
|
await manager.install('ep_bookmark')
|
||||||
|
await manager.install('ep_align')
|
||||||
const packages = await exports.getPackages();
|
const packages = await exports.getPackages();
|
||||||
const parts = {}; // Key is full name. sortParts converts this into a topologically sorted array.
|
const parts = {}; // Key is full name. sortParts converts this into a topologically sorted array.
|
||||||
const plugins = {};
|
const plugins = {};
|
||||||
|
@ -107,6 +109,13 @@ exports.update = async () => {
|
||||||
|
|
||||||
exports.getPackages = async () => {
|
exports.getPackages = async () => {
|
||||||
logger.info('Running npm to get a list of installed plugins...');
|
logger.info('Running npm to get a list of installed plugins...');
|
||||||
|
let plugins = manager.list()
|
||||||
|
let newDependencies = {}
|
||||||
|
for (const plugin of plugins) {
|
||||||
|
plugin.realPath = await fs.realpath(plugin.location);
|
||||||
|
plugin.path = plugin.realPath;
|
||||||
|
newDependencies[plugin.name] = plugin
|
||||||
|
}
|
||||||
// Notes:
|
// Notes:
|
||||||
// * Do not pass `--prod` otherwise `npm ls` will fail if there is no `package.json`.
|
// * Do not pass `--prod` otherwise `npm ls` will fail if there is no `package.json`.
|
||||||
// * The `--no-production` flag is required (or the `NODE_ENV` environment variable must be
|
// * The `--no-production` flag is required (or the `NODE_ENV` environment variable must be
|
||||||
|
@ -121,11 +130,12 @@ exports.getPackages = async () => {
|
||||||
}
|
}
|
||||||
info.realPath = await fs.realpath(info.path);
|
info.realPath = await fs.realpath(info.path);
|
||||||
}));
|
}));
|
||||||
return dependencies;
|
let newList = Object.assign({}, dependencies, newDependencies)
|
||||||
|
console.log('blub', newList)
|
||||||
|
return newList;
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadPlugin = async (packages, pluginName, plugins, parts) => {
|
const loadPlugin = async (packages, pluginName, plugins, parts) => {
|
||||||
console.log('Plugins', manager.list());
|
|
||||||
const pluginPath = path.resolve(packages[pluginName].path, 'ep.json');
|
const pluginPath = path.resolve(packages[pluginName].path, 'ep.json');
|
||||||
try {
|
try {
|
||||||
const data = await fs.readFile(pluginPath);
|
const data = await fs.readFile(pluginPath);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue