PageRenderTime 26ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/jsdoc_toolkit-1.3.3/examples/run.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 71 lines | 60 code | 10 blank | 1 comment | 16 complexity | ca2d5f9083fd64b058365f68b1c2aa20 MD5 | raw file
 1//// load required libraries
 2try {
 3	importClass(java.lang.System);
 4}
 5catch (e) {
 6	throw "RuntimeException: The class java.lang.System is required to run this script.";
 7}
 8
 9var __DIR__ = System.getProperty("user.dir")+Packages.java.io.File.separator;
10
11function require(lib) {
12	try {
13		var file = new Packages.java.io.File(__DIR__+lib);
14		if(!file.exists()) throw "missing file.";
15		load(__DIR__+lib);
16	}
17	catch (e) {
18		print("Can't find required file '"+lib+"' in directory '"+__DIR__+"'.\nDo you need to change your working directory to jsdoc-toolkit?");
19		quit();
20	}
21}
22
23require("app/JsDoc.js");
24require("app/Util.js");
25require("app/JsIO.js");
26require("app/Symbol.js");
27require("app/JsToke.js");
28require("app/JsParse.js");
29require("app/DocTag.js");
30require("app/Doclet.js");
31require("app/DocFile.js");
32require("app/Dumper.js");
33
34function Main() {
35	if (JsDoc.opt.h || JsDoc.opt._.length == 0 || JsDoc.opt.t == "") JsDoc.usage();
36
37	if (typeof(JsDoc.opt.r) == "boolean") JsDoc.opt.r=10;
38	else if (!isNaN(parseInt(JsDoc.opt.r))) JsDoc.opt.r = parseInt(JsDoc.opt.r);
39	else JsDoc.opt.r = 1;
40		
41	if (JsDoc.opt.d === true || JsDoc.opt.t === true) { // like when a user enters: -d mydir
42		LOG.warn("-d JsDoc.option malformed.");
43		JsDoc.usage();
44	}
45	else if (!JsDoc.opt.d) {
46		JsDoc.opt.d = "js_docs_out";
47	}
48	JsDoc.opt.d += (JsDoc.opt.d.indexOf(IO.FileSeparator)==JsDoc.opt.d.length-1)?
49		"" : IO.FileSeparator;
50	LOG.inform("Creating output directory: "+JsDoc.opt.d);
51	IO.makeDir(JsDoc.opt.d);
52	
53	LOG.inform("Scanning for source files: recursion set to "+JsDoc.opt.r+" subdir"+((JsDoc.opt.r==1)?"":"s")+".");
54	function isJs(element, index, array) {
55		return /\.js$/i.test(element); // we're only interested in .js files
56	}
57	var srcFiles = [];
58	for (var d = 0; d < JsDoc.opt._.length; d++) {
59		srcFiles = srcFiles.concat(
60			IO.ls(JsDoc.opt._[d], JsDoc.opt.r).filter(isJs)
61		);
62	}
63	
64	LOG.inform(srcFiles.length+" source file"+((srcFiles ==1)?"":"s")+" found:\n\t"+srcFiles.join("\n\t"));
65	var jsdoc = JsDoc.parse(srcFiles, JsDoc.opt);
66	
67	print(Dumper.dump(jsdoc.files));
68}
69
70JsDoc.opt = Util.getOptions(arguments, {d:"directory", t:"template", r:"recurse", v:"verbose", h:"help", a:"allfunctions"});
71Main();