JSDOC/BuildDocs.js
[gnome.introspection-doc-generator] / JSDOC / Options.js
index 5f7aa89..7fac06f 100644 (file)
@@ -2,19 +2,29 @@
 /**
  * Options management...
  */
-XObject = import.XObject.XObject;
-File = import.File.File;
+XObject = imports.XObject.XObject;
+File = imports.File.File;
 
 Options = {
 
+    // generic stuff...
+    "--help"          : 'Show help',   // was h
+    "help": false,   // was h;se
+    
+    
+    // configurable settings.. - 
+    "usage" : "Usage seed jsdocbuild.js OPTIONS \n",
+    
+    
     // options get defined like this..
     "--src"           :  "source directory (either absolute - starts with "/" or relative " + 
-                        "- without, in which case it's added to baseDir"
+                        "- without, in which case it's added to baseDir",
+    "--exclude-src"       : 'Ex',   
     "--baseDir"       :  'Base Directory (root directory of code)',
     "--target"        :  'Target Directory (where html files go)',
     "--cacheDirectory": 'Cached Files Directory',
     "--conf"          : 'Read From a Configuration file',       // was c. - configuration file.. - parsed with JSON.parse
-    "--template"      : 'Template Directory',   // was t.
+    "--templateDir"      : 'Template Directory',   // was t.
     // "recurse": false,   // was r. - not supported..
     "--ext"           :  'Extension of code files to read (normally js)',   // was x.
     "--publishExt"    : 'Extension of html files to write (normally html)',
@@ -26,7 +36,7 @@ Options = {
     //"suppress": '',  // was s ??? used?
     "--outputSource" : 'Output the Source code to symbols/src/* (boolean)',
     //"testmode": '',  // was t
-    "--help"          : 'Show help',   // was h
+    
     "--verbose"       : 'Show verbose messages',   // was v
     //"disablecache": '',   // was C -- not needed? - see if cacheDirectory was set..
     //"define" : [],   // was D.
@@ -35,11 +45,12 @@ Options = {
     
     // and now the defaults.. (which type can be infered from..)
     "src" : [],
+    "exclude-src" : [],
     "baseDir" :  '',  // base directory - 
     "target" : '',   // was d. ?? source directory (needed to put temporary files..)
     "cacheDirectory" : '',
     "conf" : '',       // was c. - configuration file.. - parsed with JSON.parse
-    "template": '',   // was t.
+    "templateDir": '',   // was t.
     // "recurse": false,   // was r. - not supported..
     "ext": 'js',   // was x.
     "publishExt" : 'html',
@@ -51,11 +62,16 @@ Options = {
     "suppress": '',  // was s ??? used?
     "outputSource" : true,
     "testmode": '',  // was t
-    "help": false,   // was h;se
+    
     "verbose": '',   // was v
     "disablecache": '',   // was C
     "define" : [],   // was D.
     "handler" : [],  // was H -- not supported..
+    
+    
+    "version" : "1.0",
+    "copyright" : "LGPL",
+    
     LOG : {
         warn : function(str) {
             print("Warn: " +str );
@@ -71,48 +87,84 @@ Options = {
     },
     init : function()
     {
+        
+        if (this.help) {
+            this.showHelp();
+          
+        }
+        
+        // the reset of this is specific to JSDOC - and can not be moved to a generic handler..
+        
+         
         this.LOG.verbose = this.verbose;
         
+        if (!this.baseDir) { // should we set this to cwd?
+            throw {
+                name: "ArgumentError", 
+                message: "No baseDir specified" 
+            };
+        }
         
+        // this is most likely to come from the command line..
         if (this.conf) {
-            XObject.extend(this, JSON.parse(File.read(this.conf)));;
+            var conf = this.conf[0] == '/' ? this.conf : this.baseDir + '/' + this.conf;
+        
+            XObject.extend(this, JSON.parse(File.read(conf)));;
         }
         // help ?? -- usage..
-        
+       
         if (!this.src.length) {
             throw {
                 name: "ArgumentError", 
                 message: "No source directories specified" 
             };
         }
-        if (!this.template) {
+        // append full path to source directories.
+        var _this= this;
+        var src = this.src;
+        this.src = [];
+        src.forEach(function(v, i) {
+            if (!v.length || v[0] != '/') {
+                v = _this.baseDir + (v.length ?  '/' + v : '');
+            }
+            if (!File.isDirectory(v)) {
+                throw {
+                    name: "ArgumentError", 
+                    message: "invalid Source Directory : " +  v
+                };
+            }
+            _this.src.push(v);
+        });
+        
+        
+        if (!this.templateDir) {
             throw {
                 name: "ArgumentError", 
-                message: "No template specified" 
+                message: "No templateDir Directory specified" 
             };
         }
-         
+        if (this.templateDir[0] !='/') {
+            this.templateDir = this.baseDir + '/' + this.templateDir;
+        }
+        
+        
         if (!this.target) {
             throw {
                 name: "ArgumentError", 
                 message: "No directory specified" 
             };
         }
-        f (!this.baseDir) {
-            throw {
-                name: "ArgumentError", 
-                message: "No baseDir specified" 
-            };
-        }
+        
+        //print(JSON.stringify(this, null,4));
         
         // should cacheDirectory be a subdirectory of target??
         // if not set..
-        if (!this.cacheDirectory) {
-            throw {
-                name: "ArgumentError", 
-                message: "No cacheDirectory specified" 
-            };
-        }
+        //if (!this.cacheDirectory) {
+        //    throw {
+        //        name: "ArgumentError", 
+        //        message: "No cacheDirectory specified" 
+        //    };
+        // }
         
     },
     /** 
@@ -126,11 +178,6 @@ Options = {
         args.shift(); //seed
         args.shift(); // pack.js
         
-        
-        
-        
-        
-
         for(var i =0; i < args.length;i++) {
             if (args[i].substring(0,2) != '--') {
                 
@@ -139,8 +186,8 @@ Options = {
                     message: "Unknown argument: " + args[i] 
                 };
             }
-            var a = arg[i].substring(2);
-            if (typeof(argTypes[arg[i]]) == 'undefined') {
+            var a = args[i].substring(2);
+            if (typeof(this[args[i]]) == 'undefined') {
                 throw {
                     name: "ArgumentError", 
                     message: "Unknown argument: " + args[i] 
@@ -182,5 +229,18 @@ Options = {
         }
         
         
+    },
+    
+    
+    showHelp: function()
+    {
+        print(this.usage);
+        for(var i in this) {
+            if (i.substring(0,2) != '--') {
+                continue;
+            }
+            print( i + '  ARG  : ' + this[i]);
+            throw "DONE";
+        }
     }
 }
\ No newline at end of file