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;
48 [CCode (array_length = false, array_null_terminated = true)]
49 private string[]? opt_files = null;
50 [CCode (array_length = false, array_null_terminated = true)]
51 private string[]? opt_files_from = null;
54 public bool opt_debug = false;
57 * @cfg {Boolean} opt_skip_scope (optional) skip Scope parsing and replacement.
58 * usefull for debugging...
60 public bool opt_skip_scope = false;
63 * @cfg {Boolean} opt_keep_whitespace (optional) do not remove white space in output.
64 * usefull for debugging compressed files.
67 public bool opt_keep_whitespace = false;
70 * @cfg {Boolean} opt_dump_tokens (optional) read the first file and dump the tokens.
71 * usefull for debugging...
74 public bool opt_dump_tokens = false;
78 * @cfg {Boolean} opt_clean_cache (optional) clean up temp files after done -
79 * Defaults to false if you set tmpDir, otherwise true.
82 public bool opt_clean_cache = true;
84 // not actually an option yet..
86 public string opt_doc_ext = "html";
88 public static PackerRun singleton()
90 if (_PackerRun == null) {
91 _PackerRun = new PackerRun();
100 application_id: "org.roojs.jsdoc.packerrun",
101 flags: ApplicationFlags.HANDLES_COMMAND_LINE
109 public void parseArgs(string[] args)
111 GLib.OptionEntry[] options = {
113 long_name = "jsfile",
116 arg = OptionArg.FILENAME_ARRAY,
117 arg_data = &opt_files,
118 description = "add a file to compile",
119 arg_description = null
122 long_name = "target",
125 arg = OptionArg.STRING,
126 arg_data = &opt_target,
127 description = "Target File to write (eg. roojs.js)",
128 arg_description = null
131 long_name = "debug-target",
134 arg = OptionArg.STRING,
135 arg_data = &opt_debug_target,
136 description = "Target File to write debug code (eg. roojs-debug.js)",
137 arg_description = null
139 //{ "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use (defaults to /tmp)", null },
142 long_name = "tmpdir",
145 arg = OptionArg.STRING,
146 arg_data = &opt_tmpdir,
147 description = "Temporary Directory - used by documentation tool?",
148 arg_description = null
153 long_name = "basedir",
156 arg = OptionArg.STRING,
157 arg_data = &opt_basedir,
158 description = "Base directory (where the files listed in index files are located.)",
159 arg_description = null
163 long_name = "index-files",
166 arg = OptionArg.FILENAME_ARRAY,
167 arg_data = &opt_files_from,
168 description = "files that contain listing of files to compile",
169 arg_description = null
173 long_name = "keep-whitespace",
176 arg = OptionArg.NONE,
177 arg_data = &opt_keep_whitespace,
178 description = "Keep whitespace",
179 arg_description = null
183 long_name = "skip-scope",
186 arg = OptionArg.NONE,
187 arg_data = &opt_skip_scope,
188 description = "Skip scope parsing and variable replacement",
189 arg_description = null
195 arg = OptionArg.NONE,
196 arg_data = &opt_debug,
197 description = "Show debug messages",
198 arg_description = null
202 long_name = "dump-tokens",
205 arg = OptionArg.NONE,
206 arg_data = &opt_dump_tokens,
207 description = "Dump the tokens from a file",
208 arg_description = null
212 long_name = "clean-cache",
215 arg = OptionArg.NONE,
216 arg_data = &opt_clean_cache,
217 description = "Clean up the cache after running (slower)",
218 arg_description = null
222 // fixme -- keepwhite.. cleanup
224 // documentation options
225 // usage: roojspacker --basedir roojs1 \
226 // --doc-target roojs1/docs \
227 // --index-files roojs1/buildSDK/dependancy_core.txt \
228 // --index-files roojs1/buildSDK/dependancy_ui.txt \
229 // --index-files roojs1/buildSDK/dependancy_bootstrap.txt \
230 // --doc-template-dir \
233 long_name = "doc-target",
236 arg = OptionArg.STRING,
237 arg_data = &opt_doc_target,
238 description = "Target location for documetnation",
239 arg_description = null
243 long_name = "doc-template-dir",
246 arg = OptionArg.STRING,
247 arg_data = &opt_doc_template_dir,
248 description = "Template directory for documentation",
249 arg_description = null
254 long_name = "doc-private",
257 arg = OptionArg.NONE,
258 arg_data = &opt_doc_include_private,
259 description = "Document Private functions",
260 arg_description = null
263 var opt_context = new OptionContext ("JSDOC Packer");
266 opt_context.set_help_enabled (true);
267 opt_context.add_main_entries (options, null);
268 if (!opt_context.parse ( ref args)) {
269 print("options parse error");
270 GLib.Process.exit(Posix.EXIT_FAILURE);
276 } catch (OptionError e) {
277 stdout.printf ("error: %s\n", e.message);
278 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
279 args[0], opt_context.get_help(true,null));
280 GLib.Process.exit(Posix.EXIT_FAILURE);
287 public void runPack()
289 // what's required...
291 GLib.Log.set_handler(null,
292 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING,
294 print("%s: %s\n", dom, msg);
301 // set the base directory...
302 var curdir = Environment.get_current_dir() + Path.DIR_SEPARATOR_S;
303 if (opt_basedir == null) {
305 opt_real_basedir = curdir;
306 } else if (opt_basedir[0] == '/') {
307 opt_real_basedir = opt_basedir;
309 opt_real_basedir = curdir + opt_basedir;
312 if (opt_real_basedir [opt_real_basedir .length-1].to_string() != Path.DIR_SEPARATOR_S) {
313 opt_real_basedir += Path.DIR_SEPARATOR_S;
316 GLib.debug("real_base_dir = '%s' : opt_basedir ='%s'\n", opt_real_basedir , opt_basedir);
319 if (opt_files == null && opt_files_from == null) {
320 GLib.error("You must list some files with -f or -i to compile - see --help for more details");
321 GLib.Process.exit(1);
325 // initialize the Packer (does not parse anything..)
326 var p = new Packer( this );
329 if (opt_files != null) {
331 foreach (var f in opt_files) {
332 GLib.debug("Adding File %s", f);
333 p.loadFile(f); // just adds to list of files to parse (no parsing yet..)
336 if (opt_files_from != null) {
338 foreach (var f in opt_files_from) {
339 GLib.debug("Adding File %s", f);
340 p.loadSourceIndex(f);
344 var run_pack = false;
345 if (opt_target != null || opt_debug_target != null || opt_dump_tokens) {
346 // do the actual packing...
347 p.pack( opt_target == null ? "" : opt_target ,
348 opt_debug_target == null ? "" : opt_debug_target );
350 if (p.outstr.length > 0 ) {
351 stdout.printf ("%s", p.outstr);
355 if (opt_doc_target != null) {
357 opt_doc_target = opt_doc_target.has_suffix("/") ?
358 opt_doc_target.substring(0, opt_doc_target.length-1) : opt_doc_target;
359 var d = new JSDOC.DocBuilder(p);
362 GLib.error("either select output target or doc output target");