Merge pull request #331 from cweider/packaging-improvement
Packaging improvement
This commit is contained in:
commit
a313c2570e
|
@ -32,9 +32,8 @@ var gzip = require('gzip');
|
|||
var server = require('../server');
|
||||
var os = require('os');
|
||||
|
||||
var padJS = ["jquery.min.js", "pad_utils.js", "plugins.js", "undo-xpopup.js", "json2.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "ace.js", "collab_client.js", "pad_userlist.js", "pad_impexp.js", "pad_savedrevs.js", "pad_connectionstatus.js", "pad2.js", "jquery-ui.js", "chat.js", "excanvas.js", "farbtastic.js"];
|
||||
|
||||
var timesliderJS = ["jquery.min.js", "plugins.js", "undo-xpopup.js", "json2.js", "colorutils.js", "draggable.js", "pad_utils.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "pad_impexp.js", "easysync2_client.js", "domline_client.js", "linestylefilter_client.js", "cssmanager_client.js", "broadcast.js", "broadcast_slider.js", "broadcast_revisions.js"];
|
||||
var TAR_PATH = path.join(__dirname, 'tar.json');
|
||||
var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));
|
||||
|
||||
/**
|
||||
* creates the minifed javascript for the given minified name
|
||||
|
@ -46,16 +45,10 @@ exports.minifyJS = function(req, res, jsFilename)
|
|||
res.header("Content-Type","text/javascript");
|
||||
|
||||
//choose the js files we need
|
||||
if(jsFilename == "pad.js")
|
||||
{
|
||||
jsFiles = padJS;
|
||||
}
|
||||
else if(jsFilename == "timeslider.js")
|
||||
{
|
||||
jsFiles = timesliderJS;
|
||||
}
|
||||
else
|
||||
{
|
||||
var jsFiles = undefined;
|
||||
if (Object.prototype.hasOwnProperty.call(tar, jsFilename)) {
|
||||
jsFiles = tar[jsFilename];
|
||||
} else {
|
||||
throw new Error("there is no profile for creating " + name);
|
||||
}
|
||||
|
||||
|
@ -162,52 +155,36 @@ exports.minifyJS = function(req, res, jsFilename)
|
|||
|
||||
var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length);
|
||||
|
||||
var quote = item.search("_Q") != -1;
|
||||
|
||||
//read the included file
|
||||
fs.readFile(filename, "utf-8", function(err, data)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//compress the file
|
||||
|
||||
if(type == "JS")
|
||||
{
|
||||
embeds[item] = "<script>\n" + compressJS([data])+ "\n\\x3c/script>";
|
||||
embeds[filename] = compressJS([data]);
|
||||
}
|
||||
else
|
||||
{
|
||||
embeds[item] = "<style>" + compressCSS([data])+ "</style>";
|
||||
embeds[filename] = compressCSS([data]);
|
||||
}
|
||||
|
||||
//do the first escape
|
||||
embeds[item] = JSON.stringify(embeds[item]).replace(/'/g, "\\'").replace(/\\"/g, "\"");
|
||||
embeds[item] = embeds[item].substr(1);
|
||||
embeds[item] = embeds[item].substr(0, embeds[item].length-1);
|
||||
|
||||
//add quotes, if wished
|
||||
if(quote)
|
||||
{
|
||||
embeds[item] = "'" + embeds[item] + "'";
|
||||
}
|
||||
|
||||
//do the second escape
|
||||
embeds[item] = JSON.stringify(embeds[item]).replace(/'/g, "\\'").replace(/\"/g, "\"");
|
||||
embeds[item] = embeds[item].substr(1);
|
||||
embeds[item] = embeds[item].substr(0, embeds[item].length-1);
|
||||
embeds[item] = "'" + embeds[item] + "'";
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
}, function(err)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
|
||||
//replace the include command with the include
|
||||
for(var i in embeds)
|
||||
|
||||
fileValues["ace.js"] += ';\n'
|
||||
fileValues["ace.js"] +=
|
||||
'Ace2Editor.EMBEDED = Ace2Editor.EMBED || {};\n'
|
||||
for (var filename in embeds)
|
||||
{
|
||||
fileValues["ace.js"]=fileValues["ace.js"].replace(i, embeds[i]);
|
||||
fileValues["ace.js"] +=
|
||||
'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = '
|
||||
+ JSON.stringify(embeds[filename]) + ';\n';
|
||||
}
|
||||
|
||||
|
||||
callback();
|
||||
});
|
||||
},
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"pad.js": [
|
||||
"jquery.min.js"
|
||||
, "pad_utils.js"
|
||||
, "plugins.js"
|
||||
, "undo-xpopup.js"
|
||||
, "json2.js"
|
||||
, "pad_cookie.js"
|
||||
, "pad_editor.js"
|
||||
, "pad_editbar.js"
|
||||
, "pad_docbar.js"
|
||||
, "pad_modals.js"
|
||||
, "ace.js"
|
||||
, "collab_client.js"
|
||||
, "pad_userlist.js"
|
||||
, "pad_impexp.js"
|
||||
, "pad_savedrevs.js"
|
||||
, "pad_connectionstatus.js"
|
||||
, "pad2.js"
|
||||
, "jquery-ui.js"
|
||||
, "chat.js"
|
||||
, "excanvas.js"
|
||||
, "farbtastic.js"
|
||||
]
|
||||
, "timeslider.js": [
|
||||
"jquery.min.js"
|
||||
, "plugins.js"
|
||||
, "undo-xpopup.js"
|
||||
, "json2.js"
|
||||
, "colorutils.js"
|
||||
, "draggable.js"
|
||||
, "pad_utils.js"
|
||||
, "pad_cookie.js"
|
||||
, "pad_editor.js"
|
||||
, "pad_editbar.js"
|
||||
, "pad_docbar.js"
|
||||
, "pad_modals.js"
|
||||
, "pad_impexp.js"
|
||||
, "easysync2_client.js"
|
||||
, "domline_client.js"
|
||||
, "linestylefilter_client.js"
|
||||
, "cssmanager_client.js"
|
||||
, "broadcast.js"
|
||||
, "broadcast_slider.js"
|
||||
, "broadcast_revisions.js"
|
||||
]
|
||||
}
|
147
static/js/ace.js
147
static/js/ace.js
|
@ -196,31 +196,62 @@ function Ace2Editor()
|
|||
info.ace_replaceRange(start, end, text);
|
||||
});
|
||||
|
||||
function sortFilesByEmbeded(files) {
|
||||
var embededFiles = [];
|
||||
var remoteFiles = [];
|
||||
|
||||
// calls to these functions ($$INCLUDE_...) are replaced when this file is processed
|
||||
// and compressed, putting the compressed code from the named file directly into the
|
||||
// source here.
|
||||
var $$INCLUDE_CSS = function(fileName)
|
||||
{
|
||||
return '<link rel="stylesheet" type="text/css" href="' + fileName + '"/>';
|
||||
};
|
||||
var $$INCLUDE_JS = function(fileName)
|
||||
{
|
||||
return '\x3cscript type="text/javascript" src="' + fileName + '">\x3c/script>';
|
||||
};
|
||||
var $$INCLUDE_JS_DEV = $$INCLUDE_JS;
|
||||
var $$INCLUDE_CSS_DEV = $$INCLUDE_CSS;
|
||||
if (Ace2Editor.EMBEDED) {
|
||||
for (var i = 0, ii = files.length; i < ii; i++) {
|
||||
var file = files[i];
|
||||
if (Object.prototype.hasOwnProperty.call(Ace2Editor.EMBEDED, file)) {
|
||||
embededFiles.push(file);
|
||||
} else {
|
||||
remoteFiles.push(file);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
remoteFiles = files;
|
||||
}
|
||||
|
||||
var $$INCLUDE_CSS_Q = function(fileName)
|
||||
{
|
||||
return '\'<link rel="stylesheet" type="text/css" href="' + fileName + '"/>\'';
|
||||
};
|
||||
var $$INCLUDE_JS_Q = function(fileName)
|
||||
{
|
||||
return '\'\\x3cscript type="text/javascript" src="' + fileName + '">\\x3c/script>\'';
|
||||
};
|
||||
var $$INCLUDE_JS_Q_DEV = $$INCLUDE_JS_Q;
|
||||
var $$INCLUDE_CSS_Q_DEV = $$INCLUDE_CSS_Q;
|
||||
return {embeded: embededFiles, remote: remoteFiles};
|
||||
}
|
||||
function pushScriptTagsFor(buffer, files) {
|
||||
var sorted = sortFilesByEmbeded(files);
|
||||
var embededFiles = sorted.embeded;
|
||||
var remoteFiles = sorted.remote;
|
||||
|
||||
if (embededFiles.length > 0) {
|
||||
buffer.push('<script type="text/javascript">');
|
||||
for (var i = 0, ii = embededFiles.length; i < ii; i++) {
|
||||
var file = embededFiles[i];
|
||||
buffer.push(Ace2Editor.EMBEDED[file].replace(/<\//g, '<\\/'));
|
||||
buffer.push(';\n');
|
||||
}
|
||||
buffer.push('<\/script>');
|
||||
}
|
||||
for (var i = 0, ii = remoteFiles.length; i < ii; i++) {
|
||||
var file = remoteFiles[i];
|
||||
buffer.push('<script type="application/javascript" src="' + file + '"><\/script>');
|
||||
}
|
||||
}
|
||||
function pushStyleTagsFor(buffer, files) {
|
||||
var sorted = sortFilesByEmbeded(files);
|
||||
var embededFiles = sorted.embeded;
|
||||
var remoteFiles = sorted.remote;
|
||||
|
||||
if (embededFiles.length > 0) {
|
||||
buffer.push('<style type="text/css">');
|
||||
for (var i = 0, ii = embededFiles.length; i < ii; i++) {
|
||||
var file = embededFiles[i];
|
||||
buffer.push(Ace2Editor.EMBEDED[file].replace(/<\//g, '<\\/'));
|
||||
}
|
||||
buffer.push('<\/style>');
|
||||
}
|
||||
for (var i = 0, ii = remoteFiles.length; i < ii; i++) {
|
||||
var file = remoteFiles[i];
|
||||
buffer.push('<link rel="stylesheet" type="text/css" href="' + file + '"\/>');
|
||||
}
|
||||
}
|
||||
|
||||
editor.destroy = pendingInit(function()
|
||||
{
|
||||
|
@ -246,39 +277,67 @@ function Ace2Editor()
|
|||
{
|
||||
var doctype = "<!doctype html>";
|
||||
|
||||
var iframeHTML = ["'" + doctype + "<html><head>'"];
|
||||
var iframeHTML = [];
|
||||
|
||||
iframeHTML.push(doctype);
|
||||
iframeHTML.push("<html><head>");
|
||||
|
||||
// For compatability's sake transform in and out.
|
||||
for (var i = 0, ii = iframeHTML.length; i < ii; i++) {
|
||||
iframeHTML[i] = JSON.stringify(iframeHTML[i]);
|
||||
}
|
||||
plugins.callHook("aceInitInnerdocbodyHead", {
|
||||
iframeHTML: iframeHTML
|
||||
});
|
||||
for (var i = 0, ii = iframeHTML.length; i < ii; i++) {
|
||||
iframeHTML[i] = JSON.parse(iframeHTML[i]);
|
||||
}
|
||||
|
||||
// calls to these functions ($$INCLUDE_...) are replaced when this file is processed
|
||||
// and compressed, putting the compressed code from the named file directly into the
|
||||
// source here.
|
||||
// these lines must conform to a specific format because they are passed by the build script:
|
||||
iframeHTML.push($$INCLUDE_CSS_Q("../static/css/iframe_editor.css"));
|
||||
iframeHTML.push($$INCLUDE_CSS_Q("../static/css/pad.css"));
|
||||
iframeHTML.push($$INCLUDE_CSS_Q("../static/custom/pad.css"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/ace2_common.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/skiplist.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/virtual_lines.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/easysync2.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/cssmanager.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/colorutils.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/undomodule.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/contentcollector.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/changesettracker.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/linestylefilter.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/domline.js"));
|
||||
iframeHTML.push($$INCLUDE_JS_Q("../static/js/ace2_inner.js"));
|
||||
var includedCSS = [];
|
||||
var $$INCLUDE_CSS = function(filename) {includedCSS.push(filename)};
|
||||
$$INCLUDE_CSS("../static/css/iframe_editor.css");
|
||||
$$INCLUDE_CSS("../static/css/pad.css");
|
||||
$$INCLUDE_CSS("../static/custom/pad.css");
|
||||
pushStyleTagsFor(iframeHTML, includedCSS);
|
||||
|
||||
iframeHTML.push('\'\\n<style type="text/css" title="dynamicsyntax"></style>\\n\'');
|
||||
iframeHTML.push('\'</head><body id="innerdocbody" class="syntax" spellcheck="false"> </body></html>\'');
|
||||
var includedJS = [];
|
||||
var $$INCLUDE_JS = function(filename) {includedJS.push(filename)};
|
||||
$$INCLUDE_JS("../static/js/ace2_common.js");
|
||||
$$INCLUDE_JS("../static/js/skiplist.js");
|
||||
$$INCLUDE_JS("../static/js/virtual_lines.js");
|
||||
$$INCLUDE_JS("../static/js/easysync2.js");
|
||||
$$INCLUDE_JS("../static/js/cssmanager.js");
|
||||
$$INCLUDE_JS("../static/js/colorutils.js");
|
||||
$$INCLUDE_JS("../static/js/undomodule.js");
|
||||
$$INCLUDE_JS("../static/js/contentcollector.js");
|
||||
$$INCLUDE_JS("../static/js/changesettracker.js");
|
||||
$$INCLUDE_JS("../static/js/linestylefilter.js");
|
||||
$$INCLUDE_JS("../static/js/domline.js");
|
||||
$$INCLUDE_JS("../static/js/ace2_inner.js");
|
||||
pushScriptTagsFor(iframeHTML, includedJS);
|
||||
|
||||
iframeHTML.push('<style type="text/css" title="dynamicsyntax"></style>');
|
||||
iframeHTML.push('</head><body id="innerdocbody" class="syntax" spellcheck="false"> </body></html>');
|
||||
|
||||
var outerScript = 'editorId = "' + info.id + '"; editorInfo = parent.' + thisFunctionsName + '.registry[editorId]; ' + 'window.onload = function() ' + '{ window.onload = null; setTimeout' + '(function() ' + '{ var iframe = document.createElement("IFRAME"); ' + 'iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); ' + 'iframe.frameBorder = 0; iframe.allowTransparency = true; ' + // for IE
|
||||
'outerdocbody.insertBefore(iframe, outerdocbody.firstChild); ' + 'iframe.ace_outerWin = window; ' + 'readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; ' + 'var doc = iframe.contentWindow.document; doc.open(); var text = (' + iframeHTML.join('+') + ').replace(/\\\\x3c/g, \'<\');doc.write(text); doc.close(); ' + '}, 0); }';
|
||||
'outerdocbody.insertBefore(iframe, outerdocbody.firstChild); ' + 'iframe.ace_outerWin = window; ' + 'readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; ' + 'var doc = iframe.contentWindow.document; doc.open(); var text = (' + JSON.stringify(iframeHTML.join('\n')) + ');doc.write(text); doc.close(); ' + '}, 0); }';
|
||||
|
||||
var outerHTML = [doctype, '<html><head>']
|
||||
|
||||
var includedCSS = [];
|
||||
var $$INCLUDE_CSS = function(filename) {includedCSS.push(filename)};
|
||||
$$INCLUDE_CSS("../static/css/iframe_editor.css");
|
||||
$$INCLUDE_CSS("../static/css/pad.css");
|
||||
$$INCLUDE_CSS("../static/custom/pad.css");
|
||||
pushStyleTagsFor(outerHTML, includedCSS);
|
||||
|
||||
var outerHTML = [doctype, '<html><head>', $$INCLUDE_CSS("../static/css/iframe_editor.css"), $$INCLUDE_CSS("../static/css/pad.css"), $$INCLUDE_CSS("../static/custom/pad.css"),
|
||||
// bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly
|
||||
// (throbs busy while typing)
|
||||
'<link rel="stylesheet" type="text/css" href="data:text/css,"/>', '\x3cscript>\n', outerScript, '\n\x3c/script>', '</head><body id="outerdocbody"><div id="sidediv"><!-- --></div><div id="linemetricsdiv">x</div><div id="overlaysdiv"><!-- --></div></body></html>'];
|
||||
outerHTML.push('<link rel="stylesheet" type="text/css" href="data:text/css,"/>', '\x3cscript>\n', outerScript.replace(/<\//g, '<\\/'), '\n\x3c/script>', '</head><body id="outerdocbody"><div id="sidediv"><!-- --></div><div id="linemetricsdiv">x</div><div id="overlaysdiv"><!-- --></div></body></html>');
|
||||
|
||||
if (!Array.prototype.map) Array.prototype.map = function(fun)
|
||||
{ //needed for IE
|
||||
|
|
Loading…
Reference in New Issue