4 THIS IS THE ENTRY POINT...
7 -- in theory this code can be used as a library... but this is the standard command line version...
10 valac --vapidir=/usr/share/vala/vapi
11 --vapidir=/usr/share/vala/vapi
12 --vapidir=/usr/share/vala-0.30/vapi
14 JSDOC/Lang.vala JSDOC/TextStream.vala JSDOC/TokenReader.vala JSDOC/Token.vala JSDOC/TokenStream.vala JSDOC/Packer.vala
15 JSDOC/Collapse.vala JSDOC/ScopeParser.vala JSDOC/Scope.vala JSDOC/Identifier.vala JSDOC/CompressWhite.vala
16 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
21 JSDOC.PackerRun _PackerRun;
25 // --------------- <<<<<<< <MAIN HERE....
28 public class PackerRun : Object
30 public class PackerRun : Application
33 public string opt_target = null;
34 public string opt_debug_target = null;
35 // public string opt_tmpdir = null;
36 private string opt_basedir = null;
39 * @cfg baseDir -- prefix the files listed in indexfiles with this.
42 public string opt_real_basedir = null; // USE this one it's calcuated based on current path..
44 public string opt_doc_target = null;
45 public string opt_doc_template_dir = null;
46 public bool opt_doc_include_private = false;
47 public bool opt_doc_dump_tree = false;
49 [CCode (array_length = false, array_null_terminated = true)]
50 private string[]? opt_files = null;
51 [CCode (array_length = false, array_null_terminated = true)]
52 private string[]? opt_files_from = null;
55 public bool opt_debug = false;
58 * @cfg {Boolean} opt_skip_scope (optional) skip Scope parsing and replacement.
59 * usefull for debugging...
61 public bool opt_skip_scope = false;
64 * @cfg {Boolean} opt_keep_whitespace (optional) do not remove white space in output.
65 * usefull for debugging compressed files.
68 public bool opt_keep_whitespace = false;
71 * @cfg {Boolean} opt_dump_tokens (optional) read the first file and dump the tokens.
72 * usefull for debugging...
75 public bool opt_dump_tokens = false;
79 * @cfg {Boolean} opt_clean_cache (optional) clean up temp files after done -
80 * Defaults to false if you set tmpDir, otherwise true.
83 public bool opt_clean_cache = true;
85 // not actually an option yet..
87 public string opt_doc_ext = "html";
89 public static PackerRun singleton()
91 if (_PackerRun == null) {
92 _PackerRun = new PackerRun();
101 application_id: "org.roojs.jsdoc.packerrun",
102 flags: ApplicationFlags.HANDLES_COMMAND_LINE
110 public void parseArgs(string[] args)
112 GLib.OptionEntry[] options = {
114 long_name = "jsfile",
117 arg = OptionArg.FILENAME_ARRAY,
118 arg_data = &opt_files,
119 description = "add a file to compile",
120 arg_description = null
123 long_name = "target",
126 arg = OptionArg.STRING,
127 arg_data = &opt_target,
128 description = "Target File to write (eg. roojs.js)",
129 arg_description = null
132 long_name = "debug-target",
135 arg = OptionArg.STRING,
136 arg_data = &opt_debug_target,
137 description = "Target File to write debug code (eg. roojs-debug.js)",
138 arg_description = null
140 //{ "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use (defaults to /tmp)", null },
143 long_name = "tmpdir",
146 arg = OptionArg.STRING,
147 arg_data = &opt_tmpdir,
148 description = "Temporary Directory - used by documentation tool?",
149 arg_description = null
154 long_name = "basedir",
157 arg = OptionArg.STRING,
158 arg_data = &opt_basedir,
159 description = "Base directory (where the files listed in index files are located.)",
160 arg_description = null
164 long_name = "index-files",
167 arg = OptionArg.FILENAME_ARRAY,
168 arg_data = &opt_files_from,
169 description = "files that contain listing of files to compile",
170 arg_description = null
174 long_name = "keep-whitespace",
177 arg = OptionArg.NONE,
178 arg_data = &opt_keep_whitespace,
179 description = "Keep whitespace",
180 arg_description = null
184 long_name = "skip-scope",
187 arg = OptionArg.NONE,
188 arg_data = &opt_skip_scope,
189 description = "Skip scope parsing and variable replacement",
190 arg_description = null
196 arg = OptionArg.NONE,
197 arg_data = &opt_debug,
198 description = "Show debug messages",
199 arg_description = null
203 long_name = "dump-tokens",
206 arg = OptionArg.NONE,
207 arg_data = &opt_dump_tokens,
208 description = "Dump the tokens from a file",
209 arg_description = null
213 long_name = "clean-cache",
216 arg = OptionArg.NONE,
217 arg_data = &opt_clean_cache,
218 description = "Clean up the cache after running (slower)",
219 arg_description = null
223 // fixme -- keepwhite.. cleanup
225 // documentation options
226 // usage: roojspacker --basedir roojs1 \
227 // --doc-target roojs1/docs \
228 // --index-files roojs1/buildSDK/dependancy_core.txt \
229 // --index-files roojs1/buildSDK/dependancy_ui.txt \
230 // --index-files roojs1/buildSDK/dependancy_bootstrap.txt \
231 // --doc-template-dir \
234 long_name = "doc-target",
237 arg = OptionArg.STRING,
238 arg_data = &opt_doc_target,
239 description = "Target location for documentation",
240 arg_description = null
244 long_name = "doc-template-dir",
247 arg = OptionArg.STRING,
248 arg_data = &opt_doc_template_dir,
249 description = "Template directory for documentation",
250 arg_description = null
255 long_name = "doc-dump-tree",
258 arg = OptionArg.NONE,
259 arg_data = &opt_doc_dump_tree,
260 description = "Dump the documenation json tree",
261 arg_description = null
265 long_name = "doc-private",
268 arg = OptionArg.NONE,
269 arg_data = &opt_doc_include_private,
270 description = "Document Private functions",
271 arg_description = null
274 var opt_context = new OptionContext ("JSDOC Packer");
277 opt_context.set_help_enabled (true);
278 opt_context.add_main_entries (options, null);
279 if (!opt_context.parse ( ref args)) {
280 print("options parse error");
281 GLib.Process.exit(Posix.EXIT_FAILURE);
287 } catch (OptionError e) {
288 stdout.printf ("error: %s\n", e.message);
289 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
290 args[0], opt_context.get_help(true,null));
291 GLib.Process.exit(Posix.EXIT_FAILURE);
298 public void runPack()
300 // what's required...
302 GLib.Log.set_handler(null,
303 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING,
305 print("%s: %s\n", dom, msg);
312 // set the base directory...
313 var curdir = Environment.get_current_dir() + Path.DIR_SEPARATOR_S;
314 if (opt_basedir == null) {
316 opt_real_basedir = curdir;
317 } else if (opt_basedir[0] == '/') {
318 opt_real_basedir = opt_basedir;
320 opt_real_basedir = curdir + opt_basedir;
323 if (opt_real_basedir [opt_real_basedir .length-1].to_string() != Path.DIR_SEPARATOR_S) {
324 opt_real_basedir += Path.DIR_SEPARATOR_S;
327 GLib.debug("real_base_dir = '%s' : opt_basedir ='%s'\n", opt_real_basedir , opt_basedir);
330 if (opt_files == null && opt_files_from == null) {
331 GLib.error("You must list some files with -f or -i to compile - see --help for more details");
332 GLib.Process.exit(1);
336 // initialize the Packer (does not parse anything..)
337 var p = new Packer( this );
340 if (opt_files != null) {
342 foreach (var f in opt_files) {
343 GLib.debug("Adding File %s", f);
344 p.loadFile(f); // just adds to list of files to parse (no parsing yet..)
347 if (opt_files_from != null) {
349 foreach (var f in opt_files_from) {
350 GLib.debug("Adding File %s", f);
351 p.loadSourceIndex(f);
355 var run_pack = false;
356 if (opt_target != null || opt_debug_target != null || opt_dump_tokens) {
357 // do the actual packing...
358 p.pack( opt_target == null ? "" : opt_target ,
359 opt_debug_target == null ? "" : opt_debug_target );
361 if (p.outstr.length > 0 ) {
362 stdout.printf ("%s", p.outstr);
366 if (opt_doc_target != null) {
368 opt_doc_target = opt_doc_target.has_suffix("/") ?
369 opt_doc_target.substring(0, opt_doc_target.length-1) : opt_doc_target;
370 var d = new JSDOC.DocBuilder(p);
373 GLib.error("either select output target or doc output target");