JSDOC/Packer.js
[gnome.introspection-doc-generator] / JSDOC / Packer.js
index 10cf367..48df366 100644 (file)
@@ -2,7 +2,7 @@
 XObject         = imports.XObject.XObject;
 File            = imports.File.File;
 
-TextStream      = imports.TextStream.TextStream;
+TextStream      = imports.JSDOC.TextStream.TextStream ;
 TokenReader     = imports.TokenReader.TokenReader;
 ScopeParser     = imports.ScopeParser.ScopeParser;
 TokenStream     = imports.TokenStream.TokenStream;
@@ -28,6 +28,8 @@ var x = new  Packer({
     files : [ "/location/of/file1.js", "/location/of/file2.js", ... ],
     target : "/tmp/output.js",
     debugTarget : "/tmp/output.debug.js", // merged file without compression.
+    debugTranslateTarget : "/tmp/output.translate.js", // merged with translation
+                                                       // and no compression
     translateJSON: "/tmp/translate.json",
     
     
@@ -86,16 +88,30 @@ Packer = function(cfg)
     
     var link = false;
     if (cfg.autoBuild) {
+        
+        function dateString(d){
+            function pad(n){return n<10 ? '0'+n : n}
+            return d.getFullYear() +
+                 pad(d.getMonth()+1)+
+                 pad(d.getDate())+'_'+
+                 pad(d.getHours())+
+                 pad(d.getMinutes())+
+                 pad(d.getSeconds());
+        }
+
+        
+        
         var version = 0;
         this.files.forEach(function(f) {
             version = Math.max(File.mtime(f), version);
         });
+        var version  = dateString(new Date(version));
+        
         var dirname = GLib.path_get_dirname(this.files[0]);
         var outname = this.module ? this.module : GLib.path_get_basename(dirname);
         this.target = dirname + '/compiled/' + outname + '-' + version + '.js';
-        link = dirname + '/compiled/' + outname + '.js';
-        if (File.exists(this.target)) {
-            print("Target file already exists");
+         if (File.exists(this.target)) {
+            print("Target file already exists: " + this.target);
             Seed.quit();
         }
         this.prefix = dirname +'/';
@@ -103,17 +119,10 @@ Packer = function(cfg)
         
     }
      
-    
+    print(this.translateJSON);
     this.timer =  new Date() * 1;
     this.packAll();
     
-    if (link) {
-        if (File.exists(link)) {
-            File.remove(link);
-        }
-        var f = Gio.file_new_for_path(this.target);
-        f.create_symbolic_link(link);
-    }
     
     
  
@@ -142,9 +151,16 @@ Packer.prototype = {
      */
     module: false,
     /**
-     * @cfg {String} debugTargettarget to write files debug version to (uncompacted)- must be full path.
+     * @cfg {String} debugTarget target to write files debug version to (uncompacted)- must be full path.
      */
     debugTarget : '', // merged file without compression.
+    /**
+     * @cfg {String} debugTranslateTarget target to write files debug version
+     *            to (uncompacted) but with translation- must be full path.
+     */
+    
+    debugTranslateTarget : '', 
+    
     /**
      * @cfg {String} tmpDir  (optional) where to put the temporary files. 
      *      if you set this, then files will not be cleaned up
@@ -158,6 +174,12 @@ Packer.prototype = {
      *    Defaults to false if you set tmpDir, otherwise true.
      */
     cleanup : true,  
+    /**
+     * @cfg {Boolean} keepWhite (optional) do not remove white space in output.
+     *    usefull for debugging compressed files.
+     */
+    
+    keepWhite: true,
     
     /**
      * @cfg {String} prefix (optional) prefix of directory to be stripped of when
@@ -210,6 +232,9 @@ Packer.prototype = {
         if (this.debugTarget) {
             File.write(this.debugTarget, "");
         }
+        if (this.debugTranslateTarget) {
+            File.write(this.debugTarget, "");
+        }
         
         for(var i=0; i < this.files.length; i++)  {
             var file = this.files[i];
@@ -220,6 +245,8 @@ Packer.prototype = {
                 continue;
             }
            
+            // debug Target
+            
             if (this.debugTarget) {
                 File.append(this.debugTarget, File.read(file));
             }
@@ -241,16 +268,7 @@ Packer.prototype = {
                 print("compare : " + mt + "=>" + ot);
                 if (mt >= ot) {
                     continue;
-                    /*
-                    // then the min'files time is > than original..
-                    var str = File.read(minfile);
-                    print("using MIN FILE  "+ minfile);
-                    if (str.length) {
-                        File.append(outpath, str + "\n");
-                    }
                     
-                    continue;
-                    */
                 }
                 
             }
@@ -340,6 +358,8 @@ Packer.prototype = {
             }
             
         }
+        print("Output file: " + this.target);
+        if (this.debugTarget) print("Output debug file: " + this.debugTarget);
         
          
     
@@ -362,7 +382,8 @@ Packer.prototype = {
             keepWhite : true,  
             keepComments : true, 
             sepIdents : true,
-            collapseWhite : false
+            collapseWhite : false,
+            filename : fn
         });
         this.timerPrint("START" + fn);
         
@@ -396,8 +417,9 @@ Packer.prototype = {
         print(sp.warnings.join("\n"));
         
         
-        //var out = CompressWhite(new TokenStream(toks), this, true); // do not kill whitespace..
-        var out = CompressWhite(new TokenStream(toks), this, false);
+        var out = CompressWhite(new TokenStream(toks), this, this.keepWhite); // do not kill whitespace..
+        
+        
         this.timerPrint("Compressed");
         return out;