Removed old pluginfw stuff
parent
73aa0687b8
commit
81440cd856
20
src/ep.json
20
src/ep.json
|
@ -1,15 +1,15 @@
|
|||
{
|
||||
"parts": [
|
||||
{ "name": "static", "hooks": { "expressCreateServer": "../hooks/express/static:expressCreateServer" } },
|
||||
{ "name": "specialpages", "hooks": { "expressCreateServer": "../hooks/express/specialpages:expressCreateServer" } },
|
||||
{ "name": "padurlsanitize", "hooks": { "expressCreateServer": "../hooks/express/padurlsanitize:expressCreateServer" } },
|
||||
{ "name": "minified", "hooks": { "expressCreateServer": "../hooks/express/minified:expressCreateServer" } },
|
||||
{ "name": "padreadonly", "hooks": { "expressCreateServer": "../hooks/express/padreadonly:expressCreateServer" } },
|
||||
{ "name": "webaccess", "hooks": { "expressConfigure": "../hooks/express/webaccess:expressConfigure" } },
|
||||
{ "name": "apicalls", "hooks": { "expressCreateServer": "../hooks/express/apicalls:expressCreateServer" } },
|
||||
{ "name": "importexport", "hooks": { "expressCreateServer": "../hooks/express/importexport:expressCreateServer" } },
|
||||
{ "name": "errorhandling", "hooks": { "expressCreateServer": "../hooks/express/errorhandling:expressCreateServer" } },
|
||||
{ "name": "socketio", "hooks": { "expressCreateServer": "../hooks/express/socketio:expressCreateServer" } }
|
||||
{ "name": "static", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/static:expressCreateServer" } },
|
||||
{ "name": "specialpages", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/specialpages:expressCreateServer" } },
|
||||
{ "name": "padurlsanitize", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/padurlsanitize:expressCreateServer" } },
|
||||
{ "name": "minified", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/minified:expressCreateServer" } },
|
||||
{ "name": "padreadonly", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/padreadonly:expressCreateServer" } },
|
||||
{ "name": "webaccess", "hooks": { "expressConfigure": "ep_etherpad-lite/node/hooks/express/webaccess:expressConfigure" } },
|
||||
{ "name": "apicalls", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/apicalls:expressCreateServer" } },
|
||||
{ "name": "importexport", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/importexport:expressCreateServer" } },
|
||||
{ "name": "errorhandling", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/errorhandling:expressCreateServer" } },
|
||||
{ "name": "socketio", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/socketio:expressCreateServer" } }
|
||||
|
||||
]
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ var authorManager = require("../db/AuthorManager");
|
|||
var readOnlyManager = require("../db/ReadOnlyManager");
|
||||
var settings = require('../utils/Settings');
|
||||
var securityManager = require("../db/SecurityManager");
|
||||
var plugins = require("../pluginfw/plugins.js");
|
||||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins.js");
|
||||
var log4js = require('log4js');
|
||||
var messageLogger = log4js.getLogger("message");
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ var log4js = require('log4js');
|
|||
var socketio = require('socket.io');
|
||||
var settings = require('../../utils/Settings');
|
||||
var socketIORouter = require("../../handler/SocketIORouter");
|
||||
var hooks = require("../../pluginfw/hooks");
|
||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
||||
|
||||
var padMessageHandler = require("../../handler/PadMessageHandler");
|
||||
var timesliderMessageHandler = require("../../handler/TimesliderMessageHandler");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var path = require('path');
|
||||
var minify = require('../../utils/Minify');
|
||||
var plugins = require("../../pluginfw/plugins");
|
||||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||
|
||||
exports.expressCreateServer = function (hook_name, args, cb) {
|
||||
//serve static files
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
var plugins = require("./plugins");
|
||||
var async = require("async");
|
||||
|
||||
|
||||
var hookCallWrapper = function (hook, hook_name, args, cb) {
|
||||
if (cb === undefined) cb = function (x) { return x; };
|
||||
try {
|
||||
return hook.hook_fn(hook_name, args, cb);
|
||||
} catch (ex) {
|
||||
console.error([hook_name, hook.part.full_name, ex]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Don't use Array.concat as it flatterns arrays within the array */
|
||||
exports.flatten = function (lst) {
|
||||
var res = [];
|
||||
if (lst != undefined && lst != null) {
|
||||
for (var i = 0; i < lst.length; i++) {
|
||||
if (lst[i] != undefined && lst[i] != null) {
|
||||
for (var j = 0; j < lst[i].length; j++) {
|
||||
res.push(lst[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
exports.callAll = function (hook_name, args) {
|
||||
if (plugins.hooks[hook_name] === undefined) return [];
|
||||
return exports.flatten(plugins.hooks[hook_name].map(function (hook) {
|
||||
return hookCallWrapper(hook, hook_name, args);
|
||||
}));
|
||||
}
|
||||
|
||||
exports.aCallAll = function (hook_name, args, cb) {
|
||||
if (plugins.hooks[hook_name] === undefined) cb([]);
|
||||
async.map(
|
||||
plugins.hooks[hook_name],
|
||||
function (hook, cb) {
|
||||
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
||||
},
|
||||
function (err, res) {
|
||||
cb(exports.flatten(res));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports.callFirst = function (hook_name, args) {
|
||||
if (plugins.hooks[hook_name][0] === undefined) return [];
|
||||
return exports.flatten(hookCallWrapper(plugins.hooks[hook_name][0], hook_name, args));
|
||||
}
|
||||
|
||||
exports.aCallFirst = function (hook_name, args, cb) {
|
||||
if (plugins.hooks[hook_name][0] === undefined) cb([]);
|
||||
hookCallWrapper(plugins.hooks[hook_name][0], hook_name, args, function (res) { cb(exports.flatten(res)); });
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
var npm = require("npm/lib/npm.js");
|
||||
var readInstalled = require("npm/lib/utils/read-installed.js");
|
||||
var relativize = require("npm/lib/utils/relativize.js");
|
||||
var readJson = require("npm/lib/utils/read-json.js");
|
||||
var path = require("path");
|
||||
var async = require("async");
|
||||
var fs = require("fs");
|
||||
var tsort = require("./tsort");
|
||||
var util = require("util");
|
||||
|
||||
exports.prefix = 'ep_';
|
||||
exports.loaded = false;
|
||||
exports.plugins = {};
|
||||
exports.parts = [];
|
||||
exports.hooks = {};
|
||||
|
||||
exports.ensure = function (cb) {
|
||||
if (!exports.loaded)
|
||||
exports.update(cb);
|
||||
else
|
||||
cb();
|
||||
}
|
||||
|
||||
exports.formatPlugins = function () {
|
||||
return Object.keys(exports.plugins).join(", ");
|
||||
}
|
||||
|
||||
exports.formatParts = function () {
|
||||
return exports.parts.map(function (part) { return part.full_name; }).join("\n");
|
||||
}
|
||||
|
||||
exports.formatHooks = function () {
|
||||
var res = [];
|
||||
Object.keys(exports.hooks).forEach(function (hook_name) {
|
||||
exports.hooks[hook_name].forEach(function (hook) {
|
||||
res.push(hook.hook_name + ": " + hook.hook_fn_name + " from " + hook.part.full_name);
|
||||
});
|
||||
});
|
||||
return res.join("\n");
|
||||
}
|
||||
|
||||
exports.update = function (cb) {
|
||||
exports.getPackages(function (er, packages) {
|
||||
var parts = [];
|
||||
var plugins = {};
|
||||
// Load plugin metadata ep.json
|
||||
async.forEach(
|
||||
Object.keys(packages),
|
||||
function (plugin_name, cb) {
|
||||
exports.loadPlugin(packages, plugin_name, plugins, parts, cb);
|
||||
},
|
||||
function (err) {
|
||||
exports.plugins = plugins;
|
||||
exports.parts = exports.sortParts(parts);
|
||||
exports.hooks = exports.extractHooks(exports.parts);
|
||||
exports.loaded = true;
|
||||
cb(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
exports.getPackages = function (cb) {
|
||||
// Load list of installed NPM packages, flatten it to a list, and filter out only packages with names that
|
||||
var dir = path.resolve(npm.dir, '..');
|
||||
readInstalled(dir, function (er, data) {
|
||||
if (er) cb(er, null);
|
||||
var packages = {};
|
||||
function flatten(deps) {
|
||||
Object.keys(deps).forEach(function (name) {
|
||||
if (name.indexOf(exports.prefix) == 0) {
|
||||
packages[name] = deps[name];
|
||||
}
|
||||
if (deps[name].dependencies !== undefined)
|
||||
flatten(deps[name].dependencies);
|
||||
delete deps[name].dependencies;
|
||||
});
|
||||
}
|
||||
flatten([data]);
|
||||
cb(null, packages);
|
||||
});
|
||||
}
|
||||
|
||||
exports.extractHooks = function (parts) {
|
||||
var hooks = {};
|
||||
parts.forEach(function (part) {
|
||||
Object.keys(part.hooks || {}).forEach(function (hook_name) {
|
||||
if (hooks[hook_name] === undefined) hooks[hook_name] = [];
|
||||
var hook_fn_name = part.hooks[hook_name];
|
||||
var hook_fn = exports.loadFn(part.hooks[hook_name]);
|
||||
if (hook_fn) {
|
||||
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
|
||||
} else {
|
||||
console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]);
|
||||
}
|
||||
});
|
||||
});
|
||||
return hooks;
|
||||
}
|
||||
|
||||
exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) {
|
||||
var plugin_path = path.resolve(packages[plugin_name].path, "ep.json");
|
||||
fs.readFile(
|
||||
plugin_path,
|
||||
function (er, data) {
|
||||
if (er) {
|
||||
console.error("Unable to load plugin definition file " + plugin_path);
|
||||
return cb();
|
||||
}
|
||||
try {
|
||||
var plugin = JSON.parse(data);
|
||||
plugin.package = packages[plugin_name];
|
||||
plugins[plugin_name] = plugin;
|
||||
plugin.parts.forEach(function (part) {
|
||||
part.plugin = plugin_name;
|
||||
part.full_name = plugin_name + "/" + part.name;
|
||||
parts[part.full_name] = part;
|
||||
});
|
||||
} catch (ex) {
|
||||
console.error("Unable to parse plugin definition file " + plugin_path + ": " + ex.toString());
|
||||
}
|
||||
cb();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports.partsToParentChildList = function (parts) {
|
||||
var res = [];
|
||||
Object.keys(parts).forEach(function (name) {
|
||||
(parts[name].post || []).forEach(function (child_name) {
|
||||
res.push([name, child_name]);
|
||||
});
|
||||
(parts[name].pre || []).forEach(function (parent_name) {
|
||||
res.push([parent_name, name]);
|
||||
});
|
||||
if (!parts[name].pre && !parts[name].post) {
|
||||
res.push([name, ":" + name]); // Include apps with no dependency info
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
exports.sortParts = function(parts) {
|
||||
return tsort(
|
||||
exports.partsToParentChildList(parts)
|
||||
).filter(
|
||||
function (name) { return parts[name] !== undefined; }
|
||||
).map(
|
||||
function (name) { return parts[name]; }
|
||||
);
|
||||
};
|
||||
|
||||
exports.loadFn = function (path) {
|
||||
var x = path.split(":");
|
||||
var fn = require(x[0]);
|
||||
x[1].split(".").forEach(function (name) {
|
||||
fn = fn[name];
|
||||
});
|
||||
return fn;
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
var plugins = require('./plugins');
|
||||
var path = require('path');
|
||||
|
||||
var SERVER_JS_SRC = path.normalize(path.join(__dirname, '../../'));
|
||||
var CLIENT_JS_SRC = path.normalize(path.join(__dirname, '../../static/js'));
|
||||
|
||||
global.ep_require = function (url) {
|
||||
if (url.indexOf("/plugins/") == 0) {
|
||||
/* Handle paths like "/plugins/ep_myplugin/test.js"
|
||||
by rewriting it to ROOT_PATH_OF_MYPLUGIN/test.js,
|
||||
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/test.js
|
||||
*/
|
||||
url = url.split("/");
|
||||
url.splice(0, 1);
|
||||
var plugin_name = url.splice(0, 1)[0];
|
||||
url = url.join("/");
|
||||
url = path.normalize(path.join(plugins.plugins[plugin_name].package.path, url));
|
||||
} else if (url.indexOf("/") == 0) {
|
||||
/* Handle all non-plugin paths for files in / */
|
||||
url = path.normalize(path.join(SERVER_JS_SRC, url))
|
||||
}
|
||||
return require(url);
|
||||
}
|
||||
|
||||
global.ep_client_require = function (url) {
|
||||
if (url.indexOf("/plugins/") == 0) {
|
||||
/* Handle paths like "/plugins/ep_myplugin/test.js"
|
||||
by rewriting it to ROOT_PATH_OF_MYPLUGIN/static/js/test.js,
|
||||
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
|
||||
For more information see hooks/express/static.js
|
||||
*/
|
||||
url = url.split("/");
|
||||
url.splice(0, 2);
|
||||
var plugin_name = url.splice(0, 1)[0];
|
||||
url = url.join("/");
|
||||
url = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static/js", url));
|
||||
} else if (url.indexOf("/") == 0) {
|
||||
/* Handle all non-plugin paths for files in /static */
|
||||
url = path.normalize(path.join(CLIENT_JS_SRC, url))
|
||||
}
|
||||
return require(url);
|
||||
}
|
|
@ -27,8 +27,8 @@ var db = require('./db/DB');
|
|||
var async = require('async');
|
||||
var express = require('express');
|
||||
var path = require('path');
|
||||
var plugins = require("./pluginfw/plugins");
|
||||
var hooks = require("./pluginfw/hooks");
|
||||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
||||
var npm = require("npm/lib/npm.js");
|
||||
|
||||
//try to get the git version
|
||||
|
|
Loading…
Reference in New Issue