mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 22:23:33 +01:00
Minify implements virtual plugins resources.
This commit is contained in:
parent
1a1f222221
commit
0d6ec8c04a
2 changed files with 19 additions and 25 deletions
|
@ -8,31 +8,6 @@ var fs = require("fs");
|
||||||
var ERR = require("async-stacktrace");
|
var ERR = require("async-stacktrace");
|
||||||
|
|
||||||
exports.expressCreateServer = function (hook_name, args, cb) {
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
/* Handle static files for plugins:
|
|
||||||
paths like "/static/plugins/ep_myplugin/js/test.js"
|
|
||||||
are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js,
|
|
||||||
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
|
|
||||||
*/
|
|
||||||
args.app.get(/^\/javascripts\/lib\/([^\/]+)\/static\/(.*)/, function(req, res, next) {
|
|
||||||
var plugin_name = req.params[0];
|
|
||||||
var modulePath = req.url.split("?")[0].substr("/javascripts/lib/".length);
|
|
||||||
var fullPath = require.resolve(modulePath);
|
|
||||||
|
|
||||||
if (plugins.plugins[plugin_name] == undefined) {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.readFile(fullPath, "utf8", function(err, data){
|
|
||||||
if(ERR(err)) return;
|
|
||||||
|
|
||||||
res.send("require.define('" + modulePath + "', function (require, exports, module) {" + data + "})");
|
|
||||||
})
|
|
||||||
|
|
||||||
//require.define("/plugins.js", function (require, exports, module) {
|
|
||||||
|
|
||||||
//res.sendfile(fullPath);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Cache both minified and static.
|
// Cache both minified and static.
|
||||||
var assetCache = new CachingMiddleware;
|
var assetCache = new CachingMiddleware;
|
||||||
args.app.all('/(javascripts|static)/*', assetCache.handle);
|
args.app.all('/(javascripts|static)/*', assetCache.handle);
|
||||||
|
@ -46,6 +21,8 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
||||||
var jsServer = new (Yajsml.Server)({
|
var jsServer = new (Yajsml.Server)({
|
||||||
rootPath: 'javascripts/src/'
|
rootPath: 'javascripts/src/'
|
||||||
, rootURI: 'http://localhost:' + settings.port + '/static/js/'
|
, rootURI: 'http://localhost:' + settings.port + '/static/js/'
|
||||||
|
, libraryPath: 'javascripts/lib/'
|
||||||
|
, libraryURI: 'http://localhost:' + settings.port + '/static/plugins/'
|
||||||
});
|
});
|
||||||
|
|
||||||
var StaticAssociator = Yajsml.associators.StaticAssociator;
|
var StaticAssociator = Yajsml.associators.StaticAssociator;
|
||||||
|
|
|
@ -27,6 +27,7 @@ var cleanCSS = require('clean-css');
|
||||||
var jsp = require("uglify-js").parser;
|
var jsp = require("uglify-js").parser;
|
||||||
var pro = require("uglify-js").uglify;
|
var pro = require("uglify-js").uglify;
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||||
var RequireKernel = require('require-kernel');
|
var RequireKernel = require('require-kernel');
|
||||||
var server = require('../server');
|
var server = require('../server');
|
||||||
|
|
||||||
|
@ -63,6 +64,22 @@ exports.minify = function(req, res, next)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handle static files for plugins:
|
||||||
|
paths like "plugins/ep_myplugin/static/js/test.js"
|
||||||
|
are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js,
|
||||||
|
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
|
||||||
|
*/
|
||||||
|
var match = filename.match(/^plugins\/([^\/]+)\/static\/(.*)/);
|
||||||
|
if (match) {
|
||||||
|
var pluginName = match[1];
|
||||||
|
var resourcePath = match[2];
|
||||||
|
var plugin = plugins.plugins[pluginName];
|
||||||
|
if (plugin) {
|
||||||
|
var pluginPath = plugin.package.realPath;
|
||||||
|
filename = path.relative(ROOT_DIR, pluginPath + '/static/' + resourcePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// What content type should this be?
|
// What content type should this be?
|
||||||
// TODO: This should use a MIME module.
|
// TODO: This should use a MIME module.
|
||||||
var contentType;
|
var contentType;
|
||||||
|
|
Loading…
Reference in a new issue