JSDOC/Packer.js
authoralan <alan@alanfast.akbkhome.com>
Wed, 21 Apr 2010 05:39:15 +0000 (13:39 +0800)
committeralan <alan@alanfast.akbkhome.com>
Wed, 21 Apr 2010 05:39:15 +0000 (13:39 +0800)
JSDOC/Packer.js

index 0ce1ec4..aebd8a3 100644 (file)
@@ -75,8 +75,12 @@ Packer = function(cfg)
     if (!this.target) {
         throw "No Target";
     }
-     
+    if ((typeof(cfg.tmpDir) != 'undefined') && (!cfg.cleanup)) {
+        this.cleanup = false; // do not clean up files.. = as tmpdir is set.
+    }
+    this.tmpFiles = [];
     this.timer =  new Date() * 1;
+    this.packAll();
  
 }
 Packer.prototype = {
@@ -92,23 +96,23 @@ Packer.prototype = {
      * @prop debugTarget {String} target to write files debug version to (uncompacted)- must be full path.
      */
     debugTarget : '', // merged file without compression.
-    
-    workingDir : '/tmp',
+    /**
+     * @prop tmpDir {String} (optional) where to put the temporary files. 
+     *      if you set this, then files will not be cleaned up
+     */
+    tmpDir : '/tmp',
     
     translateJson : '', // json based list of strings in all files.
    
-    tmpFile : false, // list of temporary files - cleaned up at end..
-    
+    tmpFiles : false, // list of temporary files - cleaned up at end..
     /**
-     * Pack the files.
-     * 
-     * @param {String} batch_path location of batched temporary min files.
-     * @param {String} compressed_file eg. roo-all.js
-     * @param {String} debug_file eg. roo-debug.js
-     * 
+     * @prop cleanup {Boolean} (optional) clean up temp files after done - 
+     *    Defaults to false if you set tmpDir, otherwise true.
      */
+    cleanup : true, //
     
-    packFiles : function() {
+    packAll : function()  // do the packing (run from constructor)
+    {
         
         //this.transOrigFile= bpath + '/../lang.en.js'; // needs better naming...
         //File.write(this.transfile, "");
@@ -136,12 +140,14 @@ Packer.prototype = {
             
        
             
-            var minfile = bpath + '/' +files[i].substr(spath.length+1).replace(/\//g, '.');
-            var transfile = bpath + '/' +files[i].substr(spath.length+1).replace(/\//g, '.') +'.lang';        
+            var minfile = this.tmpDir + '/' +files.replace(/\//g, '.');
+            
+            
             // let's see if we have a min file already?
+            // this might happen if tmpDir is set .. 
             if (true && File.exists(minfile)) {
                 var mt = File.mtime(minfile);
-                var ot = File.mtime(files[i]);
+                var ot = File.mtime(files);
                 print("compare : " + mt + "=>" + ot);
                 if (mt >= ot) {
                     continue;
@@ -161,30 +167,17 @@ Packer.prototype = {
             
             print("COMPRESSING ");
             //var codeComp = pack(str, 10, 0, 0);
-            var str = File.read(files[i]);
-            var str = this.pack(str, files[i], minfile);
+            var str = File.read(files);
+            var str = this.pack(str, files, minfile);
             if (str.length) {
-                File.write(minfile, str);   
+                File.write(minfile, str);
+                this.tmpFiles.push(minfile);
             }
             
              
-            
-            //var str = File.read(minfile);
-            //print("using MIN FILE  "+ minfile);
-            //File.append(outpath, str + "\n");
-            //this.timerPrint("Wrote Files");
-            /*
-            if (codeComp.length) {
-                //print(codeComp);
-                
-                File.append(outpath, codeComp+"\n");
-                File.write(minfile, codeComp);
-            }
-            */
-            //print(codeComp);
-           // if (i > 10) return;
+          
         }  
-        if (this.translate) {
+        if (this.translateJson) {
             
                
             print("MERGING LANGUAGE");