mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
lint: pluginfw: plugins.js and engine update
This commit is contained in:
parent
2fdc737355
commit
f6661d41be
3 changed files with 14259 additions and 2097 deletions
16298
src/package-lock.json
generated
16298
src/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -140,7 +140,7 @@
|
||||||
"root": true
|
"root": true
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.13.0",
|
"node": ">=10.17.0",
|
||||||
"npm": ">=5.5.1"
|
"npm": ">=5.5.1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const hooks = require('./hooks');
|
const hooks = require('./hooks');
|
||||||
const npm = require('npm/lib/npm.js');
|
|
||||||
const readInstalled = require('./read-installed.js');
|
const readInstalled = require('./read-installed.js');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const tsort = require('./tsort');
|
const tsort = require('./tsort');
|
||||||
|
@ -13,11 +14,9 @@ const defs = require('./plugin_defs');
|
||||||
|
|
||||||
exports.prefix = 'ep_';
|
exports.prefix = 'ep_';
|
||||||
|
|
||||||
exports.formatPlugins = function () {
|
exports.formatPlugins = () => Object.keys(defs.plugins).join(', ');
|
||||||
return _.keys(defs.plugins).join(', ');
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.formatPluginsWithVersion = function () {
|
exports.formatPluginsWithVersion = () => {
|
||||||
const plugins = [];
|
const plugins = [];
|
||||||
_.forEach(defs.plugins, (plugin) => {
|
_.forEach(defs.plugins, (plugin) => {
|
||||||
if (plugin.package.name !== 'ep_etherpad-lite') {
|
if (plugin.package.name !== 'ep_etherpad-lite') {
|
||||||
|
@ -28,17 +27,17 @@ exports.formatPluginsWithVersion = function () {
|
||||||
return plugins.join(', ');
|
return plugins.join(', ');
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.formatParts = function () {
|
exports.formatParts = () => _.map(defs.parts, (part) => part.full_name).join('\n');
|
||||||
return _.map(defs.parts, (part) => part.full_name).join('\n');
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.formatHooks = function (hook_set_name) {
|
exports.formatHooks = (hook_set_name) => {
|
||||||
const res = [];
|
const res = [];
|
||||||
const hooks = pluginUtils.extractHooks(defs.parts, hook_set_name || 'hooks');
|
const hooks = pluginUtils.extractHooks(defs.parts, hook_set_name || 'hooks');
|
||||||
|
|
||||||
_.chain(hooks).keys().forEach((hook_name) => {
|
_.chain(hooks).keys().forEach((hook_name) => {
|
||||||
_.forEach(hooks[hook_name], (hook) => {
|
_.forEach(hooks[hook_name], (hook) => {
|
||||||
res.push(`<dt>${hook.hook_name}</dt><dd>${hook.hook_fn_name} from ${hook.part.full_name}</dd>`);
|
res.push(`<dt>${hook.hook_name}</dt>
|
||||||
|
<dd>${hook.hook_fn_name} from ${hook.part.full_name}</dd>
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return `<dl>${res.join('\n')}</dl>`;
|
return `<dl>${res.join('\n')}</dl>`;
|
||||||
|
@ -57,7 +56,7 @@ const callInit = async () => {
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.pathNormalization = function (part, hook_fn_name, hook_name) {
|
exports.pathNormalization = (part, hook_fn_name, hook_name) => {
|
||||||
const tmp = hook_fn_name.split(':'); // hook_fn_name might be something like 'C:\\foo.js:myFunc'.
|
const tmp = hook_fn_name.split(':'); // hook_fn_name might be something like 'C:\\foo.js:myFunc'.
|
||||||
// If there is a single colon assume it's 'filename:funcname' not 'C:\\filename'.
|
// If there is a single colon assume it's 'filename:funcname' not 'C:\\filename'.
|
||||||
const functionName = (tmp.length > 1 ? tmp.pop() : null) || hook_name;
|
const functionName = (tmp.length > 1 ? tmp.pop() : null) || hook_name;
|
||||||
|
@ -67,7 +66,7 @@ exports.pathNormalization = function (part, hook_fn_name, hook_name) {
|
||||||
return `${fileName}:${functionName}`;
|
return `${fileName}:${functionName}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update = async function () {
|
exports.update = async () => {
|
||||||
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 = {};
|
||||||
|
@ -83,13 +82,14 @@ exports.update = async function () {
|
||||||
await callInit();
|
await callInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getPackages = async function () {
|
exports.getPackages = async () => {
|
||||||
// Load list of installed NPM packages, flatten it to a list, and filter out only packages with names that
|
// Load list of installed NPM packages, flatten it to a list
|
||||||
|
// and filter out only packages with names that
|
||||||
const dir = settings.root;
|
const dir = settings.root;
|
||||||
const data = await util.promisify(readInstalled)(dir);
|
const data = await util.promisify(readInstalled)(dir);
|
||||||
|
|
||||||
const packages = {};
|
const packages = {};
|
||||||
function flatten(deps) {
|
const flatten = (deps) => {
|
||||||
_.chain(deps).keys().each((name) => {
|
_.chain(deps).keys().each((name) => {
|
||||||
if (name.indexOf(exports.prefix) === 0) {
|
if (name.indexOf(exports.prefix) === 0) {
|
||||||
packages[name] = _.clone(deps[name]);
|
packages[name] = _.clone(deps[name]);
|
||||||
|
@ -102,7 +102,7 @@ exports.getPackages = async function () {
|
||||||
// I don't think we need recursion
|
// I don't think we need recursion
|
||||||
// if (deps[name].dependencies !== undefined) flatten(deps[name].dependencies);
|
// if (deps[name].dependencies !== undefined) flatten(deps[name].dependencies);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const tmp = {};
|
const tmp = {};
|
||||||
tmp[data.name] = data;
|
tmp[data.name] = data;
|
||||||
|
@ -110,7 +110,7 @@ exports.getPackages = async function () {
|
||||||
return packages;
|
return packages;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function loadPlugin(packages, plugin_name, plugins, parts) {
|
const loadPlugin = async (packages, plugin_name, plugins, parts) => {
|
||||||
const plugin_path = path.resolve(packages[plugin_name].path, 'ep.json');
|
const plugin_path = path.resolve(packages[plugin_name].path, 'ep.json');
|
||||||
try {
|
try {
|
||||||
const data = await fs.readFile(plugin_path);
|
const data = await fs.readFile(plugin_path);
|
||||||
|
@ -129,9 +129,9 @@ async function loadPlugin(packages, plugin_name, plugins, parts) {
|
||||||
} catch (er) {
|
} catch (er) {
|
||||||
console.error(`Unable to load plugin definition file ${plugin_path}`);
|
console.error(`Unable to load plugin definition file ${plugin_path}`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function partsToParentChildList(parts) {
|
const partsToParentChildList = (parts) => {
|
||||||
const res = [];
|
const res = [];
|
||||||
_.chain(parts).keys().forEach((name) => {
|
_.chain(parts).keys().forEach((name) => {
|
||||||
_.each(parts[name].post || [], (child_name) => {
|
_.each(parts[name].post || [], (child_name) => {
|
||||||
|
@ -145,15 +145,13 @@ function partsToParentChildList(parts) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Used only in Node, so no need for _
|
// Used only in Node, so no need for _
|
||||||
function sortParts(parts) {
|
const sortParts = (parts) => tsort(
|
||||||
return tsort(
|
partsToParentChildList(parts)
|
||||||
partsToParentChildList(parts)
|
).filter(
|
||||||
).filter(
|
(name) => parts[name] !== undefined
|
||||||
(name) => parts[name] !== undefined
|
).map(
|
||||||
).map(
|
(name) => parts[name]
|
||||||
(name) => parts[name]
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue