JSDOC/TokenReader.js
[gnome.introspection-doc-generator] / pack.js
diff --git a/pack.js b/pack.js
old mode 100755 (executable)
new mode 100644 (file)
index c27db7e..e064aad
--- a/pack.js
+++ b/pack.js
 #!/usr/bin/seed
 //<script type="text/javascript">
 /**
- * Simple packer example
- *
+ * packer command line
+ * 
+ * -o Output
+ * -O Output debug file here.
+ * -t Translate json file.
+ * -w Cache / working dir.
+ * -f File to read with a list of source paths / or class names.
+ * -C no cleanup (use with -w if you need are using a cache directory.)
+ * -p prefix for translation md5 generator (directory that files are in, and is removed 
+ *    from path when generating an md5 for the translated name.
+ * -k keepWhite - keeps the white space in the output files.
+
+ * 
+ * -m module name used with autoBuild to force a module name.
+ * -a autoBuild - puts target in INPUTDIR/compiled/MODULE-TIMESTAMP.js and enables translastion* 
  * compresses files listed as arguments and outputs result
  */
-TextStream      = imports['JSDOC/TextStream.js'].TextStream;
-TokenReader     = imports['JSDOC/TokenReader.js'].TokenReader;
-ScopeParser     = imports['JSDOC/ScopeParser.js'].ScopeParser;
-TokenStream     = imports['JSDOC/TokenStream.js'].TokenStream;
-CompressWhite   = imports['JSDOC/CompressWhite.js'].CompressWhite;
-File = imports.File.File;
  
-function pack(str)
-{
-    
-    var tr = new  TokenReader(  { keepDocs :true, keepWhite : true,  keepComments : true });
-    var toks = tr.tokenize(new TextStream(str) ); // dont merge xxx + . + yyyy etc.
-    var ts = new   TokenStream(toks);
-    ts.dump();
-    var sp = new  ScopeParser(ts);
-    sp.buildSymbolTree();
-    sp.mungeSymboltree();
-    print(sp.warnings.join("\n"));
-    var out =  CompressWhite(sp.ts);
-    return out;
-    
-}
+const File            = imports.File.File;
+const Packer          = imports.JSDOC.Packer.Packer;
 
 
-var args = Array.prototype.slice.call(Seed.argv);
+  
+
+var args = Array.prototype.slice.call(typeof(Seed) != 'undefined' ? Seed.argv : ARGV);
 args.shift(); //seed
 args.shift(); // pack.js
-var files = [];
-var outfn = '';
-if (!args.length) {
-    print( "no files selected");
-    Seed.quit();
+var cfg = {
+    files : [],
+    target : false,
+    srcfiles : [],
+    autoBuild : false,
+    keepWhite : false
 }
+
+
 for(var i =0; i < args.length;i++) {
     if (args[i] == '-o') {
-        outfn = args[i+1];
+        cfg.target = args[i+1];
+        i++;
+        continue;
+    }
+    if (args[i] == '-O') {
+        cfg.debugTarget = args[i+1];
+        i++;
+        continue;
+    }
+    if (args[i] == '-t') {
+        cfg.translateJSON = args[i+1];
+        i++;
+        continue;
+    }
+    if (args[i] == '-w') {
+        cfg.tmpDir = args[i+1];
+        i++;
+        continue;
+    }
+    if (args[i] == '-p') {
+        cfg.prefix = args[i+1];
         i++;
         continue;
     }
-    files.push(args[i]);
+    if (args[i] == '-C') {
+        cfg.cleanup = false;
+        continue;
+    }
+    if (args[i] == '-f') {
+        cfg.srcfiles.push(args[i+1]);
+        i++;
+        continue;
+    }
+    if (args[i] == '-m') {
+        cfg.module = args[i+1];
+        i++;
+        continue;
+    }
+    if (args[i] == '-a') {
+        cfg.autoBuild = true
+        continue;
+    }
+    if (args[i] == '-k') {
+        cfg.keepWhite = true
+        continue;
+    }
+    if (cfg.files.indexOf(args[i]) > -1) {
+        continue; // remove dupes.
+    }
+    cfg.files.push(args[i]);
 }
-print(files.join(', '));
-if (!files.length) {
-    throw "no files selected";
+print(JSON.stringify(args,null,4));
+var pack;
+try {
+    pack = new Packer(cfg)
+} catch (e) {
+    print("ERROR " + e.toString());
+    throw e;
 }
-var out = '';
-files.forEach(function(f) {
-    out = pack(File.read(f)) + "\n";
-});
-if (outfn) {
-    File.write(outfn, out);
-    Seed.quit();
+if (!pack.target) {
+    print(pack.out);
 }
-print(out);
-