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 string opt_target = null;
29 public string opt_debug_target = null;
30 // public string opt_tmpdir = null;
31 private string opt_basedir = null;
34 * @cfg baseDir -- prefix the files listed in indexfiles with this.
37 public string opt_real_basedir = null; // USE this one it's calcuated based on current path..
39 public string opt_doc_target = null;
40 public string opt_doc_template_dir = null;
41 public bool opt_doc_include_private = false;
43 [CCode (array_length = false, array_null_terminated = true)]
44 private string[]? opt_files = null;
45 [CCode (array_length = false, array_null_terminated = true)]
46 private string[]? opt_files_from = null;
49 public bool opt_debug = false;
52 * @cfg {Boolean} opt_skip_scope (optional) skip Scope parsing and replacement.
53 * usefull for debugging...
55 public bool opt_skip_scope = false;
58 * @cfg {Boolean} opt_keep_whitespace (optional) do not remove white space in output.
59 * usefull for debugging compressed files.
62 public bool opt_keep_whitespace = false;
65 * @cfg {Boolean} opt_dump_tokens (optional) read the first file and dump the tokens.
66 * usefull for debugging...
69 public bool opt_dump_tokens = false;
73 * @cfg {Boolean} opt_clean_cache (optional) clean up temp files after done -
74 * Defaults to false if you set tmpDir, otherwise true.
77 public bool opt_clean_cache = true;
79 // not actually an option yet..
81 public string opt_doc_ext = "html";
89 application_id: "org.roojs.jsdoc.packerrun",
90 flags: ApplicationFlags.HANDLES_COMMAND_LINE
95 void parseArgs(string[] args)
97 GLib.OptionEntry[] options = {
102 arg = OptionArg.FILENAME_ARRAY,
103 arg_data = &opt_files,
104 description = "add a file to compile",
105 arg_description = null
108 long_name = "target",
111 arg = OptionArg.STRING,
112 arg_data = &opt_target,
113 description = "Target File to write (eg. roojs.js)",
114 arg_description = null
117 long_name = "debug-target",
120 arg = OptionArg.STRING,
121 arg_data = &opt_debug_target,
122 description = "Target File to write debug code (eg. roojs-debug.js)",
123 arg_description = null
125 //{ "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use (defaults to /tmp)", null },
128 long_name = "basedir",
131 arg = OptionArg.STRING,
132 arg_data = &opt_basedir,
133 description = "Base directory (where the files listed in index files are located.)",
134 arg_description = null
138 long_name = "index-files",
141 arg = OptionArg.FILENAME_ARRAY,
142 arg_data = &opt_files_from,
143 description = "files that contain listing of files to compile",
144 arg_description = null
148 long_name = "keep-whitespace",
151 arg = OptionArg.NONE,
152 arg_data = &opt_keep_whitespace,
153 description = "Keep whitespace",
154 arg_description = null
158 long_name = "skip-scope",
161 arg = OptionArg.NONE,
162 arg_data = &opt_skip_scope,
163 description = "Skip scope parsing and variable replacement",
164 arg_description = null
170 arg = OptionArg.NONE,
171 arg_data = &opt_debug,
172 description = "Show debug messages",
173 arg_description = null
177 long_name = "dump-tokens",
180 arg = OptionArg.NONE,
181 arg_data = &opt_dump_tokens,
182 description = "Dump the tokens from a file",
183 arg_description = null
187 long_name = "clean-cache",
190 arg = OptionArg.NONE,
191 arg_data = &opt_clean_cache,
192 description = "Clean up the cache after running (slower)",
193 arg_description = null
197 // fixme -- keepwhite.. cleanup
199 // documentation options
200 // usage: roojspacker --basedir roojs1 \
201 // --doc-target roojs1/docs \
202 // --index-files roojs1/buildSDK/dependancy_core.txt \
203 // --index-files roojs1/buildSDK/dependancy_ui.txt \
204 // --index-files roojs1/buildSDK/dependancy_bootstrap.txt \
205 // --doc-template-dir \
208 long_name = "doc-target",
211 arg = OptionArg.STRING,
212 arg_data = &opt_doc_target,
213 description = "Clean up the cache after running (slower)",
214 arg_description = null
218 long_name = "doc-template-dir",
221 arg = OptionArg.STRING,
222 arg_data = &opt_doc_template_dir,
223 description = "Documentation Directory target",
224 arg_description = null
229 long_name = "doc-private",
232 arg = OptionArg.NONE,
233 arg_data = &opt_doc_include_private,
234 description = "Document Private functions",
235 arg_description = null
238 var opt_context = new OptionContext ("JSDOC Packer");
241 opt_context.set_help_enabled (true);
242 opt_context.add_main_entries (options, null);
243 if (!opt_context.parse ( ref args)) {
244 print("options parse error");
245 GLib.Process.exit(Posix.EXIT_FAILURE);
251 } catch (OptionError e) {
252 stdout.printf ("error: %s\n", e.message);
253 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
254 args[0], opt_context.get_help(true,null));
255 GLib.Process.exit(Posix.EXIT_FAILURE);
264 // what's required...
266 GLib.Log.set_handler(null,
267 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING,
269 print("%s: %s\n", dom, msg);
278 // set the base directory...
279 var curdir = Environment.get_current_dir() + Path.DIR_SEPARATOR_S;
280 if (opt_basedir == null) {
282 opt_real_basedir = curdir;
283 } else if (opt_basedir[0] == '/') {
284 opt_real_basedir = opt_basedir;
286 opt_real_basedir = curdir + opt_basedir;
289 if (opt_real_basedir [opt_real_basedir .length-1].to_string() != Path.DIR_SEPARATOR_S) {
290 opt_real_basedir += Path.DIR_SEPARATOR_S;
293 GLib.debug("real_base_dir = '%s' : opt_basedir ='%s'\n", opt_real_basedir , opt_basedir);
296 if (opt_files == null && opt_files_from == null) {
297 GLib.error("You must list some files with -f or -i to compile - see --help for more details");
298 GLib.Process.exit(1);
302 // now run the Packer...
303 var p = new Packer( this );
306 if (opt_files != null) {
308 foreach (var f in opt_files) {
309 GLib.debug("Adding File %s", f);
313 if (opt_files_from != null) {
315 foreach (var f in opt_files_from) {
316 GLib.debug("Adding File %s", f);
317 p.loadSourceIndex(f);
321 var run_pack = false;
322 if (opt_target != null || opt_debug_target != null || opt_dump_tokens) {
324 p.pack( opt_target == null ? "" : opt_target ,
325 opt_debug_target == null ? "" : opt_debug_target );
327 if (p.outstr.length > 0 ) {
328 stdout.printf ("%s", p.outstr);
331 if (opt_doc_target != null) {
332 //var d = new DocBuilder(p);