Merge branch 'plugin-fix-require' into plugin
This commit is contained in:
commit
7b497b1522
|
@ -3,7 +3,6 @@
|
|||
{ "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" } },
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
var minify = require('../../utils/Minify');
|
||||
|
||||
exports.expressCreateServer = function (hook_name, args, cb) {
|
||||
//serve minified files
|
||||
args.app.get(/^\/minified\/(.*)/, minify.minifyJS);
|
||||
}
|
|
@ -8,34 +8,9 @@ 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(/^\/minified\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) {
|
||||
var plugin_name = req.params[0];
|
||||
var modulePath = req.url.split("?")[0].substr("/minified/plugins/".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('/(minified|static)/*', assetCache.handle);
|
||||
args.app.all('/(javascripts|static)/*', assetCache.handle);
|
||||
|
||||
// Minify will serve static files compressed (minify enabled). It also has
|
||||
// file-specific hacks for ace/require-kernel/etc.
|
||||
|
@ -44,8 +19,10 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
|||
// Setup middleware that will package JavaScript files served by minify for
|
||||
// CommonJS loader on the client-side.
|
||||
var jsServer = new (Yajsml.Server)({
|
||||
rootPath: 'minified/'
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -156,7 +156,7 @@ function Ace2Editor()
|
|||
}
|
||||
function pushRequireScriptTo(buffer) {
|
||||
var KERNEL_SOURCE = '../static/js/require-kernel.js';
|
||||
var KERNEL_BOOT = 'require.setRootURI("../minified/");\nrequire.setLibraryURI("../minified/plugins/");\nrequire.setGlobalKeyPath("require");'
|
||||
var KERNEL_BOOT = 'require.setRootURI("../javascripts/src");\nrequire.setLibraryURI("../javascripts/lib");\nrequire.setGlobalKeyPath("require");'
|
||||
if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) {
|
||||
buffer.push('<script type="text/javascript">');
|
||||
buffer.push(Ace2Editor.EMBEDED[KERNEL_SOURCE]);
|
||||
|
@ -166,8 +166,8 @@ function Ace2Editor()
|
|||
}
|
||||
function pushScriptsTo(buffer) {
|
||||
/* Folling is for packaging regular expression. */
|
||||
/* $$INCLUDE_JS("../minified/ace2_inner.js?callback=require.define"); */
|
||||
var ACE_SOURCE = '../minified/ace2_inner.js?callback=require.define';
|
||||
/* $$INCLUDE_JS("../javascripts/src/ace2_inner.js?callback=require.define"); */
|
||||
var ACE_SOURCE = '../javascripts/src/ace2_inner.js?callback=require.define';
|
||||
if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[ACE_SOURCE]) {
|
||||
buffer.push('<script type="text/javascript">');
|
||||
buffer.push(Ace2Editor.EMBEDED[ACE_SOURCE]);
|
||||
|
@ -175,11 +175,6 @@ function Ace2Editor()
|
|||
buffer.push('<\/script>');
|
||||
} else {
|
||||
file = ACE_SOURCE;
|
||||
file = file.replace(/^\.\.\/static\/js\//, '../minified/');
|
||||
buffer.push('<script type="text/javascript" src="../static/js/require-kernel.js"><\/script>');
|
||||
buffer.push('<script type="text/javascript">');
|
||||
buffer.push('require.setRootURI("../minified/"); require.setLibraryURI("../minified/plugins/"); require.setGlobalKeyPath("require");');
|
||||
buffer.push('<\/script>');
|
||||
buffer.push('<script type="application/javascript" src="' + ACE_SOURCE + '"><\/script>');
|
||||
buffer.push('<script type="text/javascript">');
|
||||
buffer.push('require("ep_etherpad-lite/static/js/ace2_inner");');
|
||||
|
@ -261,9 +256,7 @@ function Ace2Editor()
|
|||
pushRequireScriptTo(iframeHTML);
|
||||
// Inject my plugins into my child.
|
||||
iframeHTML.push('\
|
||||
<script type="text/javascript" src="../static/js/require-kernel.js"></script>\
|
||||
<script type="text/javascript">\
|
||||
require.setRootURI("../minified/"); require.setLibraryURI("../minified/plugins/"); require.setGlobalKeyPath("require");\
|
||||
require.define("/plugins", null);\n\
|
||||
require.define("/plugins.js", function (require, exports, module) {\
|
||||
module.exports = require("ep_etherpad-lite/static/js/plugins");\
|
||||
|
|
|
@ -260,12 +260,12 @@
|
|||
<script type="text/javascript" src="../static/js/require-kernel.js"></script>
|
||||
<script type="text/javascript" src="../static/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="../socket.io/socket.io.js"></script>
|
||||
<script type="text/javascript" src="../minified/pad.js?callback=require.define"></script>
|
||||
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define"></script>
|
||||
<script type="text/javascript">
|
||||
var clientVars = {};
|
||||
(function () {
|
||||
require.setRootURI("../minified/");
|
||||
require.setLibraryURI("../minified/plugins/");
|
||||
require.setRootURI("../javascripts/src");
|
||||
require.setLibraryURI("../javascripts/lib");
|
||||
require.setGlobalKeyPath("require");
|
||||
|
||||
var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
|
||||
|
|
|
@ -200,13 +200,13 @@
|
|||
<script type="text/javascript" src="../../../static/js/require-kernel.js"></script>
|
||||
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="../../../socket.io/socket.io.js"></script>
|
||||
<script type="text/javascript" src="../../../minified/timeslider.js?callback=require.define"></script>
|
||||
<script type="text/javascript" src="../../../javascripts/lib/ep_etherpad-lite/static/js/timeslider.js?callback=require.define"></script>
|
||||
<script type="text/javascript" src="../../../static/custom/timeslider.js"></script>
|
||||
<script type="text/javascript" >
|
||||
var clientVars = {};
|
||||
(function () {
|
||||
require.setRootURI("../../../minified/");
|
||||
require.setLibraryURI("../../../minified/plugins/");
|
||||
require.setRootURI("../../../javascripts/src");
|
||||
require.setLibraryURI("../../../javascripts/lib");
|
||||
require.setGlobalKeyPath("require");
|
||||
|
||||
var plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
|
||||
|
|
Loading…
Reference in New Issue