JSDOC/Packer.js
[gnome.introspection-doc-generator] / JSDOC / Packer.js
index f7a3246..1bdde2e 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,15 +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';
          if (File.exists(this.target)) {
-            print("Target file already exists");
+            print("Target file already exists: " + this.target);
             Seed.quit();
         }
         this.prefix = dirname +'/';
@@ -134,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
@@ -208,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];
@@ -218,6 +245,8 @@ Packer.prototype = {
                 continue;
             }
            
+            // debug Target
+            
             if (this.debugTarget) {
                 File.append(this.debugTarget, File.read(file));
             }
@@ -239,20 +268,11 @@ 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;
-                    */
                 }
                 
             }
-            
+             
             print("COMPRESSING ");
             //var codeComp = pack(str, 10, 0, 0);
             if (File.exists(minfile)) {
@@ -260,13 +280,15 @@ Packer.prototype = {
             }
             var str = File.read(file);
             var str = this.pack(str, file, minfile);
-            if (str.length) {
-                File.write(minfile, str);
-            }
-            
              
           
-        }  
+        }
+        
+        
+        
+        // if we are translating, write the translations strings at the top
+        // of the file..
+        
         if (this.translateJSON) {
             
                
@@ -277,9 +299,7 @@ Packer.prototype = {
             } else {
                 this.out += out;
             }
-            
-            
-            
+             
             File.write(this.translateJSON, "");
             for(var i=0; i < this.files.length; i++)  {
                 var file = this.files[i];
@@ -338,6 +358,8 @@ Packer.prototype = {
             }
             
         }
+        print("Output file: " + this.target);
+        if (this.debugTarget) print("Output debug file: " + this.debugTarget);
         
          
     
@@ -360,7 +382,8 @@ Packer.prototype = {
             keepWhite : true,  
             keepComments : true, 
             sepIdents : true,
-            collapseWhite : false
+            collapseWhite : false,
+            filename : fn
         });
         this.timerPrint("START" + fn);
         
@@ -394,9 +417,16 @@ Packer.prototype = {
         print(sp.warnings.join("\n"));
         
         
+        
         var out = CompressWhite(new TokenStream(toks), this, this.keepWhite); // do not kill whitespace..
         
+        
         this.timerPrint("Compressed");
+        
+         if (out.length) {
+            File.write(minfile, out);
+        }
+        
         return out;