4 -- in theory this code can be used as a library... but this is the standard command line version...
7 valac --vapidir=/usr/share/vala/vapi
8 --vapidir=/usr/share/vala/vapi
9 --vapidir=/usr/share/vala-0.30/vapi
11 JSDOC/Lang.vala JSDOC/TextStream.vala JSDOC/TokenReader.vala JSDOC/Token.vala JSDOC/TokenStream.vala JSDOC/Packer.vala
12 JSDOC/Collapse.vala JSDOC/ScopeParser.vala JSDOC/Scope.vala JSDOC/Identifier.vala JSDOC/CompressWhite.vala
13 JSDOC/PackerRun.vala --pkg glib-2.0 --pkg gee-1.0 --pkg gio-2.0 --pkg posix -o /tmp/jspack --target-glib=2.32 -X -lm
20 // --------------- <<<<<<< <MAIN HERE....
23 class PackerRun : Object
25 class PackerRun : Application
28 public static string opt_target = null;
29 public static string opt_debug_target = null;
30 // public static string opt_tmpdir = null;
31 public static string opt_basedir = null;
33 [CCode (array_length = false, array_null_terminated = true)]
34 private static string[]? opt_files = null;
35 [CCode (array_length = false, array_null_terminated = true)]
36 private static string[]? opt_files_from = null;
37 public static bool opt_debug = false;
38 public static bool opt_skip_scope = false;
40 public static bool opt_keep_whitespace = false;
41 public static bool opt_dump_tokens = false;
42 public static bool opt_clean_cache = true;
44 const OptionEntry[] options = {
46 { "jsfile", 'f', 0, OptionArg.FILENAME_ARRAY, ref opt_files ,"add a file to compile", null },
47 { "target", 't', 0, OptionArg.STRING, ref opt_target, "Target File to write (eg. roojs.js)", null },
48 { "debug-target", 'T', 0, OptionArg.STRING, ref opt_debug_target, "Target File to write debug code (eg. roojs-debug.js)", null },
49 //{ "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use (defaults to /tmp)", null },
50 { "basedir", 'b', 0, OptionArg.STRING, ref opt_basedir, "Base directory (where the files listed in index files are located.)", null },
52 { "index-files", 'i', 0, OptionArg.FILENAME_ARRAY, ref opt_files_from ,"files that contain listing of files to compile", null },
53 { "keep-whitespace", 'w', 0, OptionArg.NONE, ref opt_keep_whitespace, "Keep whitespace", null },
54 { "skip-scope", 's', 0, OptionArg.NONE, ref opt_skip_scope, "Skip scope parsing and variable replacement", null },
55 { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages", null },
56 { "dump-tokens", 'k', 0, OptionArg.NONE, ref opt_dump_tokens, "Dump the tokens from a file", null },
57 { "clean-cache", 'c', 0, OptionArg.NONE, ref opt_clean_cache, "Clean up the cache after running (slower)", null },
58 // fixme -- keepwhite.. cleanup
60 // documentation options
61 // usage: roojspacker --basedir roojs1 \
62 // --doc-target roojs1/docs \
63 // --index-files roojs1/buildSDK/dependancy_core.txt \
64 // --index-files roojs1/buildSDK/dependancy_ui.txt \
65 // --index-files roojs1/buildSDK/dependancy_bootstrap.txt \
66 // --doc-template-dir\
69 { "doc-target", 'd', 0, OptionArg.STRING, ref opt_target, "Documentation Directory target", null },
70 { "doc-template-dir", 'p', 0, OptionArg.STRING, ref opt_target, "Documentation Directory target", null },
77 public static int main(string[] args)
79 //foreach(var a in args) {
80 // debug("ARG: %s\n", a);
83 var opt_context = new OptionContext ("JSDOC Packer");
86 opt_context.set_help_enabled (true);
87 opt_context.add_main_entries (options, null);
88 if (!opt_context.parse ( ref args)) {
89 print("options parse error");
90 GLib.Process.exit(Posix.EXIT_FAILURE);
96 } catch (OptionError e) {
97 stdout.printf ("error: %s\n", e.message);
98 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
99 args[0], opt_context.get_help(true,null));
100 GLib.Process.exit(Posix.EXIT_FAILURE);
110 public PackerRun (string[] args)
114 application_id: "org.roojs.jsdoc.packerrun",
115 flags: ApplicationFlags.HANDLES_COMMAND_LINE
120 // what's required...
122 GLib.Log.set_handler(null,
123 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING,
125 print("%s: %s\n", dom, msg);
129 // now run the Packer...
133 p.keepWhite = opt_keep_whitespace;
134 p.skipScope = opt_skip_scope;
135 p.dumpTokens = opt_dump_tokens;
136 p.cleanup = opt_clean_cache;
137 //if (opt_tmpdir == null) {
138 // p.cleanup = false;
140 // p.tmpDir = opt_tmpdir;
144 // set the base directory...
145 var curdir = Environment.get_current_dir() + Path.DIR_SEPARATOR_S;
146 if (opt_basedir == null) {
148 } else if (opt_basedir[0] == '/') {
149 p.baseDir = opt_basedir;
151 p.baseDir = curdir + opt_basedir;
154 if (p.baseDir[p.baseDir.length-1].to_string() != Path.DIR_SEPARATOR_S) {
155 p.baseDir += Path.DIR_SEPARATOR_S;
158 print("BaseDir = '%s' : opt_basedir ='%s'\n", p.baseDir, opt_basedir);
161 if (opt_files == null && opt_files_from == null) {
162 GLib.error("You must list some files with -f or -i to compile - see --help for more details");
163 GLib.Process.exit(1);
167 if (opt_files != null) {
169 foreach (var f in opt_files) {
170 GLib.debug("Adding File %s", f);
174 if (opt_files_from != null) {
176 foreach (var f in opt_files_from) {
177 GLib.debug("Adding File %s", f);
178 p.loadSourceIndex(f);
184 p.pack( opt_target == null ? "" : opt_target ,
185 opt_debug_target == null ? "" : opt_debug_target );
187 if (p.outstr.length > 0 ) {
188 stdout.printf ("%s", p.outstr);