From ce90ddcf54e16dad72faf348215241bf8c959e50 Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Tue, 29 May 2012 09:26:39 +0300
Subject: [PATCH] restore include.js license header and links to un-minified
 source: issue #1624

---
 resources/static/lib/jschannel.js |  2 +-
 scripts/compress-worker.js        | 22 +++++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/resources/static/lib/jschannel.js b/resources/static/lib/jschannel.js
index ad70c3344..c2a5ee410 100644
--- a/resources/static/lib/jschannel.js
+++ b/resources/static/lib/jschannel.js
@@ -1,4 +1,4 @@
-/**
+/*
  * js_channel is a very lightweight abstraction on top of
  * postMessage which defines message formats and semantics
  * to support interactions more rich than just message passing
diff --git a/scripts/compress-worker.js b/scripts/compress-worker.js
index 4c9616bff..eaa70b16d 100644
--- a/scripts/compress-worker.js
+++ b/scripts/compress-worker.js
@@ -29,15 +29,35 @@ function compressResource(staticPath, name, files, cb) {
     });
   }
 
+  function extract_copyright(code) {
+    var tok = jsp.tokenizer(code), toks, ret = "";
+    toks = tok().comments_before;
+
+    if (toks.length >= 1) {
+      var c = toks[0];
+      // copyrights that we'll include MUST be before code body and have
+      // the form: /** */
+      if (c.value.substr(0, 1) === '*' && c.type === 'comment2') {
+        ret += "/*" + c.value + "*/";
+      }
+    }
+
+    return ret;
+  };
+
   function compress() {
     try {
       var final_code;
       if (/\.js$/.test(name)) {
+        // extract copyright
+        var copyright = extract_copyright(orig_code) || "";
+        if (copyright.length) copyright += "\n\n";
+
         // compress javascript
         var ast = jsp.parse(orig_code); // parse code and get the initial AST
         ast = pro.ast_mangle(ast); // get a new AST with mangled names
         ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
-        final_code = pro.split_lines(pro.gen_code(ast), 32 * 1024); // compressed code here
+        final_code = copyright + pro.split_lines(pro.gen_code(ast), 32 * 1024); // compressed code here
       } else if (/\.css$/.test(name)) {
         // compress css
         var cach_code = cachify_embedded(orig_code);
-- 
GitLab