Minify implements virtual plugins resources.

This commit is contained in:
Chad Weider 2012-03-10 14:03:29 -08:00
parent 1a1f222221
commit 0d6ec8c04a
2 changed files with 19 additions and 25 deletions

View File

@ -8,31 +8,6 @@ var fs = require("fs");
var ERR = require("async-stacktrace");
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.
var assetCache = new CachingMiddleware;
args.app.all('/(javascripts|static)/*', assetCache.handle);
@ -46,6 +21,8 @@ exports.expressCreateServer = function (hook_name, args, cb) {
var jsServer = new (Yajsml.Server)({
rootPath: 'javascripts/src/'
, rootURI: 'http://localhost:' + settings.port + '/static/js/'
, libraryPath: 'javascripts/lib/'
, libraryURI: 'http://localhost:' + settings.port + '/static/plugins/'
});
var StaticAssociator = Yajsml.associators.StaticAssociator;

View File

@ -27,6 +27,7 @@ var cleanCSS = require('clean-css');
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
var path = require('path');
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
var RequireKernel = require('require-kernel');
var server = require('../server');
@ -63,6 +64,22 @@ exports.minify = function(req, res, next)
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?
// TODO: This should use a MIME module.
var contentType;