2012-02-24 20:45:02 +01:00
|
|
|
var path = require('path');
|
2012-02-25 17:23:44 +01:00
|
|
|
var minify = require('../../utils/Minify');
|
2012-03-01 19:00:58 +01:00
|
|
|
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
2012-03-04 23:45:33 +01:00
|
|
|
var CachingMiddleware = require('../../utils/caching_middleware');
|
|
|
|
var settings = require("../../utils/Settings");
|
|
|
|
var Yajsml = require('yajsml');
|
|
|
|
var fs = require("fs");
|
|
|
|
var ERR = require("async-stacktrace");
|
2012-04-04 15:10:27 +02:00
|
|
|
var _ = require("underscore");
|
2012-02-24 20:45:02 +01:00
|
|
|
|
2012-02-25 16:53:15 +01:00
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
2012-03-04 23:45:33 +01:00
|
|
|
// Cache both minified and static.
|
|
|
|
var assetCache = new CachingMiddleware;
|
2012-03-10 23:13:08 +01:00
|
|
|
args.app.all('/(javascripts|static)/*', assetCache.handle);
|
2012-03-04 23:45:33 +01:00
|
|
|
|
|
|
|
// Minify will serve static files compressed (minify enabled). It also has
|
|
|
|
// file-specific hacks for ace/require-kernel/etc.
|
|
|
|
args.app.all('/static/:filename(*)', minify.minify);
|
|
|
|
|
|
|
|
// Setup middleware that will package JavaScript files served by minify for
|
|
|
|
// CommonJS loader on the client-side.
|
|
|
|
var jsServer = new (Yajsml.Server)({
|
2012-03-10 23:13:08 +01:00
|
|
|
rootPath: 'javascripts/src/'
|
2012-03-04 23:45:33 +01:00
|
|
|
, rootURI: 'http://localhost:' + settings.port + '/static/js/'
|
2012-03-10 23:03:29 +01:00
|
|
|
, libraryPath: 'javascripts/lib/'
|
|
|
|
, libraryURI: 'http://localhost:' + settings.port + '/static/plugins/'
|
2012-02-25 19:43:00 +01:00
|
|
|
});
|
|
|
|
|
2012-03-04 23:45:33 +01:00
|
|
|
var StaticAssociator = Yajsml.associators.StaticAssociator;
|
|
|
|
var associations =
|
|
|
|
Yajsml.associators.associationsForSimpleMapping(minify.tar);
|
|
|
|
var associator = new StaticAssociator(associations);
|
|
|
|
jsServer.setAssociator(associator);
|
|
|
|
args.app.use(jsServer);
|
|
|
|
|
|
|
|
// serve plugin definitions
|
|
|
|
// not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js");
|
|
|
|
args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) {
|
2012-04-04 15:10:27 +02:00
|
|
|
|
|
|
|
var clientParts = _(plugins.parts)
|
|
|
|
.filter(function(part){ return _(part).has('client_hooks') });
|
|
|
|
|
|
|
|
var clientPlugins = {};
|
|
|
|
|
|
|
|
_(clientParts).chain()
|
|
|
|
.map(function(part){ return part.plugin })
|
|
|
|
.uniq()
|
|
|
|
.each(function(name){
|
|
|
|
clientPlugins[name] = _(plugins.plugins[name]).clone();
|
|
|
|
delete clientPlugins[name]['package'];
|
|
|
|
});
|
|
|
|
|
2012-03-24 13:28:17 +01:00
|
|
|
res.header("Content-Type","application/json; charset=utf-8");
|
2012-04-04 15:10:27 +02:00
|
|
|
res.write(JSON.stringify({"plugins": clientPlugins, "parts": clientParts}));
|
2012-03-04 23:45:33 +01:00
|
|
|
res.end();
|
2012-02-24 20:45:02 +01:00
|
|
|
});
|
|
|
|
}
|