Implemented PoC for managing plugins with live-plugin-manager
parent
cf32d45f66
commit
24940fc4de
|
@ -76,6 +76,7 @@ exports.require = (name, args, mod) => {
|
|||
basedir = path.dirname(mod.filename);
|
||||
paths = mod.paths;
|
||||
}
|
||||
paths.push(settings.root + '/plugin_packages')
|
||||
|
||||
const ejspath = resolve.sync(name, {paths, basedir, extensions: ['.html', '.ejs']});
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -49,6 +49,7 @@
|
|||
"jsdom": "^20.0.0",
|
||||
"jsonminify": "0.4.2",
|
||||
"languages4translatewiki": "0.1.3",
|
||||
"live-plugin-manager": "^0.18.1",
|
||||
"lodash.clonedeep": "4.5.0",
|
||||
"log4js": "0.6.38",
|
||||
"measured-core": "^2.0.0",
|
||||
|
@ -56,7 +57,6 @@
|
|||
"npm": "^6.14.18",
|
||||
"openapi-backend": "^5.10.5",
|
||||
"proxy-addr": "^2.0.7",
|
||||
"live-plugin-manager": "^0.18.1",
|
||||
"rate-limiter-flexible": "^3.0.0",
|
||||
"rehype": "^13.0.1",
|
||||
"rehype-minify-whitespace": "^6.0.0",
|
||||
|
|
|
@ -33,16 +33,7 @@ const wrapTaskCb = (cb) => {
|
|||
exports.uninstall = async (pluginName, cb = null) => {
|
||||
cb = wrapTaskCb(cb);
|
||||
logger.info(`Uninstalling plugin ${pluginName}...`);
|
||||
try {
|
||||
// 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;
|
||||
}
|
||||
await exports.manager.uninstall(pluginName);
|
||||
logger.info(`Successfully uninstalled plugin ${pluginName}`);
|
||||
await hooks.aCallAll('pluginUninstall', {pluginName});
|
||||
await plugins.update();
|
||||
|
@ -52,16 +43,7 @@ exports.uninstall = async (pluginName, cb = null) => {
|
|||
exports.install = async (pluginName, cb = null) => {
|
||||
cb = wrapTaskCb(cb);
|
||||
logger.info(`Installing plugin ${pluginName}...`);
|
||||
try {
|
||||
// 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;
|
||||
}
|
||||
await exports.manager.install(pluginName);
|
||||
logger.info(`Successfully installed plugin ${pluginName}`);
|
||||
await hooks.aCallAll('pluginInstall', {pluginName});
|
||||
await plugins.update();
|
||||
|
|
|
@ -84,6 +84,8 @@ exports.pathNormalization = (part, hookFnName, hookName) => {
|
|||
};
|
||||
|
||||
exports.update = async () => {
|
||||
await manager.install('ep_bookmark')
|
||||
await manager.install('ep_align')
|
||||
const packages = await exports.getPackages();
|
||||
const parts = {}; // Key is full name. sortParts converts this into a topologically sorted array.
|
||||
const plugins = {};
|
||||
|
@ -107,6 +109,13 @@ exports.update = async () => {
|
|||
|
||||
exports.getPackages = async () => {
|
||||
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:
|
||||
// * 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
|
||||
|
@ -121,11 +130,12 @@ exports.getPackages = async () => {
|
|||
}
|
||||
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) => {
|
||||
console.log('Plugins', manager.list());
|
||||
const pluginPath = path.resolve(packages[pluginName].path, 'ep.json');
|
||||
try {
|
||||
const data = await fs.readFile(pluginPath);
|
||||
|
|
Loading…
Reference in New Issue