From 77804673d7bf7f3df455bb42c479203e9455c68d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sat, 14 Jan 2012 16:12:03 -0800 Subject: [PATCH 1/4] Move packaging info into its own file. --- node/utils/Minify.js | 19 ++++++------------ node/utils/tar.json | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 node/utils/tar.json diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 588456fd..330c5810 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -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); } diff --git a/node/utils/tar.json b/node/utils/tar.json new file mode 100644 index 00000000..7cb60694 --- /dev/null +++ b/node/utils/tar.json @@ -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" + ] +} From 9c91f16c71b7f541aa2ea5d9f7e6d797464124fb Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sat, 14 Jan 2012 21:42:47 -0800 Subject: [PATCH 2/4] Improve inlining of editor content. Instead of replacing substrings, write each included file's content into a shared dictionary for lookup later. This eliminates duplication and arguably improves readability. --- node/utils/Minify.js | 42 +++++++++++++----------------------------- static/js/ace.js | 40 ++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 330c5810..719cdaee 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -155,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] = "