JSDOC/Packer.js
[gnome.introspection-doc-generator] / JSDOC / Packer.js
index 66de07b..272a1a2 100644 (file)
@@ -25,7 +25,7 @@ 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.
-    translateJson : "/tmp/translate.json",
+    translateJSON: "/tmp/translate.json",
     
     
 );
@@ -75,7 +75,7 @@ Packer = function(cfg)
     if (!this.target) {
         throw "No Target";
     }
-    if ((typeof(cfg.tmpDir) != 'undefined') && (!cfg.cleanup)) {
+    if (this.tmpDir  != Packer.prototype.tmpDir) && (!cfg.cleanup)) {
         this.cleanup = false; // do not clean up files.. = as tmpdir is set.
     }
  
@@ -102,7 +102,7 @@ Packer.prototype = {
      */
     tmpDir : '/tmp',
     
-    translateJson : '', // json based list of strings in all files.
+    translateJSON : '', // json based list of strings in all files.
    
     /**
      * @prop cleanup {Boolean} (optional) clean up temp files after done - 
@@ -179,14 +179,14 @@ Packer.prototype = {
              
           
         }  
-        if (this.translateJson) {
+        if (this.translateJSON) {
             
                
             print("MERGING LANGUAGE");
             File.write(this.target, "if (typeof(_T) == 'undefined') { _T={};}\n");
             
             
-            File.write(this.translateJson, "");
+            File.write(this.translateJSON, "");
             for(var i=0; i < this.files.length; i++)  {
                 var file = this.files[i];
                 var transfile= this.tmpDir + '/' +file.replace(/\//g, '.') +'.lang.trans';
@@ -196,11 +196,17 @@ Packer.prototype = {
                     if (str.length) {
                         File.append(this.target, str + "\n");
                     }
+                    if (this.cleanup) {
+                        File.remove(transmd5);
+                    }
                 }
                 if (File.exists(transfile)) {
                     var str = File.read(transfile);
                     if (str.length) {
-                        File.append(this.translateJson, str);
+                        File.append(this.translateJSON, str);
+                    }
+                    if (this.cleanup) {
+                        File.remove(transfile);
                     }
                 }
                 
@@ -213,6 +219,8 @@ Packer.prototype = {
         for(var i=0; i < files.length; i++)  {
             
             var minfile = bpath + '/' + this.files.replace(/\//g, '.');
+            
+            
             if (!File.exists(minfile)) {
                 continue;
             }
@@ -221,15 +229,13 @@ Packer.prototype = {
             if (str.length) {
                 File.append(this.target, str + "\n");
             }
-        }
-        
-        
-        //File.append(dout, "\n");// end the function 
-        if (this.cleanup) {
-            
-            
+            if (this.cleanup) {
+                File.remove(minfile);
+            }
             
         }
+        
+         
     
     
     },
@@ -245,15 +251,15 @@ Packer.prototype = {
     pack : function (str,fn,minfile)
     {
     
-        var tr = new  TokenReader();
+        var tr = new  TokenReader(  { keepDocs :true, keepWhite : true,  keepComments : true, sepIdents : true });
         this.timerPrint("START" + fn);
         
         // we can load translation map here...
         
-        var toks = tr.tokenize(str,false); // dont merge xxx + . + yyyy etc.
+        var toks = tr.tokenize(new TextStream(str)); // dont merge xxx + . + yyyy etc.
         
         // at this point we can write a language file...
-        if (this.translate) {
+        if (this.translateJSON) {
             this.writeTranslateFile(fn, minfile, tr.translateMap);
         }
         
@@ -261,12 +267,9 @@ Packer.prototype = {
         
         // and replace if we are generating a different language..
         
-        
-        
-        
         this.timerPrint("Tokenized");
         //return;//
-        var sp = new ScopeParser(new TokenStream(toks, str.length));
+        var sp = new ScopeParser(new TokenStream(toks));
         this.timerPrint("Converted to Parser");
         sp.packer = this;
         sp.buildSymbolTree();
@@ -278,6 +281,8 @@ Packer.prototype = {
         this.timerPrint("Compressed");
         return out;
         
+        
+         
     },
     
     timerPrint: function (str) {
@@ -342,14 +347,17 @@ Packer.prototype = {
     {
         //print("STRING HANDLER");
        // callback when outputing compressed file, 
-        if (!this.translate) {
+        if (!this.translateJSON) {
          //   print("TURNED OFF");
             return tok.outData;
         }
-        if (tok.qc != '"') {
+        if (tok.name == SINGLE_QUOTE) {
             return tok.outData;
         }
         var sval = tok.data.substring(1,tok.data.length-1);
+        // we do not clean up... quoting here!??!!?!?!?!?
+        
+        
         // blank with tabs or spaces..
         //if (!sval.replace(new RegExp("(\\\\n|\\\\t| )+",'g'), '').length) {
        //     return tok.outData;