Merge pull request #331 from cweider/packaging-improvement

Packaging improvement
This commit is contained in:
Peter 'Pita' Martischka 2012-01-15 12:48:41 -08:00
commit a313c2570e
3 changed files with 169 additions and 86 deletions

View File

@ -32,9 +32,8 @@ var gzip = require('gzip');
var server = require('../server'); var server = require('../server');
var os = require('os'); 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 TAR_PATH = path.join(__dirname, 'tar.json');
var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));
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"];
/** /**
* creates the minifed javascript for the given minified name * 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"); res.header("Content-Type","text/javascript");
//choose the js files we need //choose the js files we need
if(jsFilename == "pad.js") var jsFiles = undefined;
{ if (Object.prototype.hasOwnProperty.call(tar, jsFilename)) {
jsFiles = padJS; jsFiles = tar[jsFilename];
} } else {
else if(jsFilename == "timeslider.js")
{
jsFiles = timesliderJS;
}
else
{
throw new Error("there is no profile for creating " + name); throw new Error("there is no profile for creating " + name);
} }
@ -162,50 +155,34 @@ exports.minifyJS = function(req, res, jsFilename)
var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length); var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length);
var quote = item.search("_Q") != -1;
//read the included file //read the included file
fs.readFile(filename, "utf-8", function(err, data) fs.readFile(filename, "utf-8", function(err, data)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//compress the file
if(type == "JS") if(type == "JS")
{ {
embeds[item] = "<script>\n" + compressJS([data])+ "\n\\x3c/script>"; embeds[filename] = compressJS([data]);
} }
else 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(); callback();
}); });
}, function(err) }, function(err)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//replace the include command with the include fileValues["ace.js"] += ';\n'
for(var i in embeds) 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(); callback();

47
node/utils/tar.json Normal file
View File

@ -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"
]
}

View File

@ -196,31 +196,62 @@ function Ace2Editor()
info.ace_replaceRange(start, end, text); 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 if (Ace2Editor.EMBEDED) {
// and compressed, putting the compressed code from the named file directly into the for (var i = 0, ii = files.length; i < ii; i++) {
// source here. var file = files[i];
var $$INCLUDE_CSS = function(fileName) if (Object.prototype.hasOwnProperty.call(Ace2Editor.EMBEDED, file)) {
{ embededFiles.push(file);
return '<link rel="stylesheet" type="text/css" href="' + fileName + '"/>'; } else {
}; remoteFiles.push(file);
var $$INCLUDE_JS = function(fileName) }
{ }
return '\x3cscript type="text/javascript" src="' + fileName + '">\x3c/script>'; } else {
}; remoteFiles = files;
var $$INCLUDE_JS_DEV = $$INCLUDE_JS; }
var $$INCLUDE_CSS_DEV = $$INCLUDE_CSS;
var $$INCLUDE_CSS_Q = function(fileName) return {embeded: embededFiles, remote: remoteFiles};
{ }
return '\'<link rel="stylesheet" type="text/css" href="' + fileName + '"/>\''; function pushScriptTagsFor(buffer, files) {
}; var sorted = sortFilesByEmbeded(files);
var $$INCLUDE_JS_Q = function(fileName) var embededFiles = sorted.embeded;
{ var remoteFiles = sorted.remote;
return '\'\\x3cscript type="text/javascript" src="' + fileName + '">\\x3c/script>\'';
}; if (embededFiles.length > 0) {
var $$INCLUDE_JS_Q_DEV = $$INCLUDE_JS_Q; buffer.push('<script type="text/javascript">');
var $$INCLUDE_CSS_Q_DEV = $$INCLUDE_CSS_Q; 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() editor.destroy = pendingInit(function()
{ {
@ -246,39 +277,67 @@ function Ace2Editor()
{ {
var doctype = "<!doctype html>"; 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", { plugins.callHook("aceInitInnerdocbodyHead", {
iframeHTML: iframeHTML 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: // 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")); var includedCSS = [];
iframeHTML.push($$INCLUDE_CSS_Q("../static/css/pad.css")); var $$INCLUDE_CSS = function(filename) {includedCSS.push(filename)};
iframeHTML.push($$INCLUDE_CSS_Q("../static/custom/pad.css")); $$INCLUDE_CSS("../static/css/iframe_editor.css");
iframeHTML.push($$INCLUDE_JS_Q("../static/js/ace2_common.js")); $$INCLUDE_CSS("../static/css/pad.css");
iframeHTML.push($$INCLUDE_JS_Q("../static/js/skiplist.js")); $$INCLUDE_CSS("../static/custom/pad.css");
iframeHTML.push($$INCLUDE_JS_Q("../static/js/virtual_lines.js")); pushStyleTagsFor(iframeHTML, includedCSS);
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"));
iframeHTML.push('\'\\n<style type="text/css" title="dynamicsyntax"></style>\\n\''); var includedJS = [];
iframeHTML.push('\'</head><body id="innerdocbody" class="syntax" spellcheck="false">&nbsp;</body></html>\''); 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">&nbsp;</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 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 // bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly
// (throbs busy while typing) // (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) if (!Array.prototype.map) Array.prototype.map = function(fun)
{ //needed for IE { //needed for IE