src/jsdoc/PackerRun.vala
[roojspacker] / src / jsdoc / PackerRun.vala
index d3fe402..22f6f1e 100644 (file)
@@ -20,48 +20,53 @@ namespace JSDOC
        // --------------- <<<<<<< <MAIN HERE....
        
 #if HAVE_OLD_GLIB
-       class PackerRun : Object 
+       public class PackerRun : Object 
 #else
-       class PackerRun : Application   
+       public class PackerRun : Application    
 #endif
        {
-               public static string opt_target = null;
-               public static string opt_debug_target = null;
-//             public static string opt_tmpdir = null;
-               private static string opt_basedir = null;
-               public static string opt_real_basedir = null;
+               public  string opt_target = null;
+               public string opt_debug_target = null;
+//             public  string opt_tmpdir = null;
+               private  string opt_basedir = null;
                
-               public static string opt_doc_target = null;
-               public static string opt_doc_template_dir = null;
+               /**
+               * @cfg baseDir -- prefix the files listed in indexfiles with this.
+               */
+                
+               public  string opt_real_basedir = null; // USE this one it's calcuated based on current path..
                
+               public  string opt_doc_target = null;
+               public  string opt_doc_template_dir = null;
+               public  bool opt_doc_include_private = false;           
                                
                [CCode (array_length = false, array_null_terminated = true)]
-               private static string[]? opt_files = null;
+               private string[]? opt_files = null;
                [CCode (array_length = false, array_null_terminated = true)]
-               private static string[]? opt_files_from = null;
+               private  string[]? opt_files_from = null;
                
                
-               public static bool opt_debug = false;
+               public  bool opt_debug = false;
                
                 /**
                 * @cfg {Boolean} opt_skip_scope (optional) skip Scope parsing and replacement.
                 *    usefull for debugging...
                 */
-               public static bool opt_skip_scope = false;
+               public  bool opt_skip_scope = false;
                
                /**
                 * @cfg {Boolean} opt_keep_whitespace (optional) do not remove white space in output.
                 *    usefull for debugging compressed files.
                 */
                
-               public static bool opt_keep_whitespace = false; 
+               public  bool opt_keep_whitespace = false;       
                
                        /**
                 * @cfg {Boolean} opt_dump_tokens (optional) read the first file and dump the tokens.
                 *    usefull for debugging...
                 */
                
-               public static bool opt_dump_tokens = false;     
+               public  bool opt_dump_tokens = false;   
                
                  
                /**
@@ -69,22 +74,127 @@ namespace JSDOC
                 *    Defaults to false if you set tmpDir, otherwise true.
                 */
                
-               public static bool opt_clean_cache = true;      
+               public  bool opt_clean_cache = true;    
+               
+               // not actually an option yet..
                
-               const OptionEntry[] options = {
+               public  string opt_doc_ext = "html";
                
-                       { "jsfile", 'f', 0, OptionArg.FILENAME_ARRAY, ref opt_files ,"add a file to compile", null },
-                       { "target", 't', 0, OptionArg.STRING, ref opt_target, "Target File to write (eg. roojs.js)", null },
-                       { "debug-target", 'T', 0, OptionArg.STRING, ref opt_debug_target, "Target File to write debug code (eg. roojs-debug.js)", null },
-                       //{ "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use (defaults to /tmp)", null },
-                       { "basedir", 'b', 0, OptionArg.STRING, ref opt_basedir, "Base directory (where the files listed in index files are located.)", null },
+       
+               public PackerRun ()
+               {
+#if !HAVE_OLD_GLIB             
+                       Object(
+                           application_id: "org.roojs.jsdoc.packerrun",
+                               flags: ApplicationFlags.HANDLES_COMMAND_LINE 
+                       );
+#endif         
+               }
+               
+               
+               public void parseArgs(string[] args)
+               {
+                       GLib.OptionEntry[] options       = {
+                               OptionEntry() {
+                                       long_name = "jsfile",
+                                       short_name = 'f',
+                                       flags = 0,
+                                       arg =  OptionArg.FILENAME_ARRAY,
+                                       arg_data = &opt_files,
+                                       description = "add a file to compile",
+                                       arg_description = null
+                               },
+                               OptionEntry() {
+                                       long_name = "target",
+                                       short_name = 't',
+                                       flags = 0,
+                                       arg =  OptionArg.STRING,
+                                       arg_data = &opt_target,
+                                       description = "Target File to write (eg. roojs.js)",
+                                       arg_description = null
+                               },
+                               OptionEntry() {
+                                       long_name = "debug-target",
+                                       short_name = 'T',
+                                       flags = 0,
+                                       arg =  OptionArg.STRING,
+                                       arg_data = &opt_debug_target,
+                                       description = "Target File to write debug code (eg. roojs-debug.js)",
+                                       arg_description = null
+                               },
+                               //{ "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use (defaults to /tmp)", null },
+                               
+                               OptionEntry() {
+                                       long_name = "basedir",
+                                       short_name = 'b',
+                                       flags = 0,
+                                       arg =  OptionArg.STRING,
+                                       arg_data = &opt_basedir,
+                                       description = "Base directory (where the files listed in index files are located.)",
+                                       arg_description = null
+                               }, 
+
+                               OptionEntry() {
+                                       long_name = "index-files",
+                                       short_name = 'i',
+                                       flags = 0,
+                                       arg =  OptionArg.FILENAME_ARRAY,
+                                       arg_data = &opt_files_from,
+                                       description = "files that contain listing of files to compile",
+                                       arg_description = null
+                               }, 
+
+                               OptionEntry() {
+                                       long_name = "keep-whitespace",
+                                       short_name = 'w',
+                                       flags = 0,
+                                       arg =  OptionArg.NONE,
+                                       arg_data = &opt_keep_whitespace,
+                                       description = "Keep whitespace",
+                                       arg_description = null
+                               }, 
+                        
+                               OptionEntry() {
+                                       long_name = "skip-scope",
+                                       short_name = 's',
+                                       flags = 0,
+                                       arg =  OptionArg.NONE,
+                                       arg_data = &opt_skip_scope,
+                                       description = "Skip scope parsing and variable replacement",
+                                       arg_description = null
+                               }, 
+                               OptionEntry() {
+                                       long_name = "debug",
+                                       short_name = 'D',
+                                       flags = 0,
+                                       arg =  OptionArg.NONE,
+                                       arg_data = &opt_debug,
+                                       description = "Show debug messages",
+                                       arg_description = null
+                               }, 
+
+                               OptionEntry() {
+                                       long_name = "dump-tokens",
+                                       short_name = 'k',
+                                       flags = 0,
+                                       arg =  OptionArg.NONE,
+                                       arg_data = &opt_dump_tokens,
+                                       description = "Dump the tokens from a file",
+                                       arg_description = null
+                               }, 
+
+                               OptionEntry() {
+                                       long_name = "clean-cache",
+                                       short_name = 'c',
+                                       flags = 0,
+                                       arg =  OptionArg.NONE,
+                                       arg_data = &opt_clean_cache,
+                                       description = "Clean up the cache after running (slower)",
+                                       arg_description = null
+                               }, 
+
 
-                       { "index-files", 'i', 0, OptionArg.FILENAME_ARRAY, ref opt_files_from ,"files that contain listing of files to compile", null },                 
-                       { "keep-whitespace", 'w', 0, OptionArg.NONE, ref opt_keep_whitespace, "Keep whitespace", null },
-                       { "skip-scope", 's', 0, OptionArg.NONE, ref opt_skip_scope, "Skip scope parsing and variable replacement", null },
-                       { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages", null },
-                       { "dump-tokens", 'k', 0, OptionArg.NONE, ref opt_dump_tokens, "Dump the tokens from a file", null },
-                       { "clean-cache", 'c', 0, OptionArg.NONE, ref opt_clean_cache, "Clean up the cache after running (slower)", null },
                        // fixme -- keepwhite.. cleanup 
                        
                        // documentation options
@@ -93,60 +203,65 @@ namespace JSDOC
                        //       --index-files roojs1/buildSDK/dependancy_core.txt  \
                        //       --index-files roojs1/buildSDK/dependancy_ui.txt  \
                        //       --index-files roojs1/buildSDK/dependancy_bootstrap.txt  \
-                       //       --doc-template-dir\
-                       
-                       
-                       { "doc-target", 'd', 0, OptionArg.STRING, ref opt_doc_target, "Documentation Directory target", null },
-                       { "doc-template-dir", 'p', 0, OptionArg.STRING, ref opt_doc_template_dir, "Documentation Directory target", null },
-                       
-                       
-                       
-                       
-                       { null }
-               };
-               public static int main(string[] args) 
-               {
-                       //foreach(var a in args) {
-                       //      debug("ARG: %s\n", a);
-                       //}
+                       //       --doc-template-dir \
                        
+                               OptionEntry() {
+                                       long_name = "doc-target",
+                                       short_name = 'd',
+                                       flags = 0,
+                                       arg =  OptionArg.STRING,
+                                       arg_data = &opt_doc_target,
+                                       description = "Clean up the cache after running (slower)",
+                                       arg_description = null
+                               }, 
+
+                               OptionEntry() {
+                                       long_name = "doc-template-dir",
+                                       short_name = 'p',
+                                       flags = 0,
+                                       arg =  OptionArg.STRING,
+                                       arg_data = &opt_doc_template_dir,
+                                       description = "Documentation Directory target",
+                                       arg_description = null
+                               },                      
+
+
+                               OptionEntry() {
+                                       long_name = "doc-private",
+                                       short_name = 'P',
+                                       flags = 0,
+                                       arg =  OptionArg.NONE,
+                                       arg_data = &opt_doc_include_private,
+                                       description = "Document Private functions",
+                                       arg_description = null
+                               }
+                       };
                        var opt_context = new OptionContext ("JSDOC Packer");
-                       
-                               try {
-                                       opt_context.set_help_enabled (true);
-                                       opt_context.add_main_entries (options, null);
-                                       if (!opt_context.parse ( ref args)) {
-                                               print("options parse error");
-                                               GLib.Process.exit(Posix.EXIT_FAILURE);
-                                       }
 
-                               
-                                        
-                               
-                               } catch (OptionError e) {
-                                       stdout.printf ("error: %s\n", e.message);
-                                       stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", 
-                                                                args[0], opt_context.get_help(true,null));
+                       try {
+                               opt_context.set_help_enabled (true);
+                               opt_context.add_main_entries (options, null);
+                               if (!opt_context.parse ( ref args)) {
+                                       print("options parse error");
                                        GLib.Process.exit(Posix.EXIT_FAILURE);
-                                        
                                }
-               
-                       new PackerRun(args);
-                       return 0;
-               }
 
 
-       
-               public PackerRun (string[] args)
-               {
-#if !HAVE_OLD_GLIB             
-                       Object(
-                           application_id: "org.roojs.jsdoc.packerrun",
-                               flags: ApplicationFlags.HANDLES_COMMAND_LINE 
-                       );
-#endif                                  
-                        
+                                
+
+                       } catch (OptionError e) {
+                               stdout.printf ("error: %s\n", e.message);
+                               stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", 
+                                                        args[0], opt_context.get_help(true,null));
+                               GLib.Process.exit(Posix.EXIT_FAILURE);
+                                
+                       }
                        
+                                        
+                        
+               }
+               public void  runPack()
+               {       
                        // what's required...
                        if (opt_debug) {
                                GLib.Log.set_handler(null, 
@@ -157,34 +272,26 @@ namespace JSDOC
                        }
                        
                        
-                       // now run the Packer...
-                       var p = new Packer(
-                               
-                       );
+               
   
   
-                       //if (opt_tmpdir == null) {
-                       //      p.cleanup = false;
-                       //} else {
-                       //      p.tmpDir = opt_tmpdir;
-                       //}
-                       
-                       
+                        
                        // set the base directory...
                        var curdir = Environment.get_current_dir() + Path.DIR_SEPARATOR_S;
                        if (opt_basedir == null) {
-                               p.baseDir = curdir;
+
+                               opt_real_basedir = curdir;
                        } else if (opt_basedir[0] == '/') {     
-                               p.baseDir = opt_basedir;
+                               opt_real_basedir  = opt_basedir;
                        } else {
-                               p.baseDir = curdir + opt_basedir;
+                               opt_real_basedir  = curdir + opt_basedir;
                        }
                        // suffix a slash..
-                       if (p.baseDir[p.baseDir.length-1].to_string() != Path.DIR_SEPARATOR_S) {
-                               p.baseDir += Path.DIR_SEPARATOR_S;
+                       if (opt_real_basedir [opt_real_basedir .length-1].to_string() != Path.DIR_SEPARATOR_S) {
+                               opt_real_basedir  += Path.DIR_SEPARATOR_S;
                        }
                        
-                       print("BaseDir = '%s' : opt_basedir ='%s'\n", p.baseDir, opt_basedir);
+                       GLib.debug("real_base_dir  = '%s' : opt_basedir ='%s'\n", opt_real_basedir , opt_basedir);
                        
                        
                        if (opt_files == null && opt_files_from == null) {
@@ -193,6 +300,10 @@ namespace JSDOC
                        }
                        
                        
+                               // now run the Packer...
+                       var p = new Packer(     this );
+                       
+                       
                        if (opt_files != null) {
                         
                                foreach (var  f in opt_files) {
@@ -208,15 +319,23 @@ namespace JSDOC
                                }
                        }  
                        
+                       var run_pack = false;
+                       if (opt_target != null || opt_debug_target != null || opt_dump_tokens) {
                        
-                       
-                       p.pack( opt_target == null ? "" : opt_target ,
-                                       opt_debug_target == null ? "" :  opt_debug_target );
-            
-               if (p.outstr.length > 0 ) {
-                               stdout.printf ("%s", p.outstr);
-                       }
-            
+                               p.pack( opt_target == null ? "" : opt_target ,
+                                               opt_debug_target == null ? "" :  opt_debug_target );
+                       
+                       if (p.outstr.length > 0 ) {
+                                       stdout.printf ("%s", p.outstr);
+                               }
+               }
+               if (opt_doc_target != null) {
+                       //var d = new DocBuilder(p);
+               }
+               
+               
+               
+               
                }        
                
        }