PageRenderTime 87ms CodeModel.GetById 60ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/jsdoc_toolkit-1.4.0/app/run.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 153 lines | 131 code | 19 blank | 3 comment | 44 complexity | e157b19172014f759d45018a4bd9ac74 MD5 | raw file
  1var VERBOSE = false;
  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("jsdoc.dir")||System.getProperty("user.dir"))+Packages.java.io.File.separator;
 10
 11/** Load required libraries. */
 12function require(lib) {
 13	var libDirs = ['', __DIR__, __DIR__+'app/', __DIR__+'../'];
 14	var libErrors = [];
 15	for(var i = 0; i < libDirs.length; i++) {
 16		try {
 17			var file = new Packages.java.io.File(libDirs[i]+lib);
 18			if(!file.exists()) {
 19				libErrors.push('Could not find: ['+(libDirs[i]+lib)+']');
 20			}
 21			else {
 22				if (VERBOSE) print("Loading: ["+(libDirs[i]+lib)+"] ...");
 23				load(libDirs[i]+lib);
 24				return;
 25			}
 26		}
 27		catch (e) {
 28			libErrors.push('Error loading: ['+(libDirs[i]+lib)+']');
 29		}
 30	}
 31	for(var i=0; i < libErrors.length; i++) {
 32		print("ERROR: ["+libErrors[i]+"]");
 33	}
 34	quit();
 35}
 36
 37require("app/JsDoc.js");
 38require("app/Util.js");
 39
 40JsDoc.opt = Util.getOptions(arguments, {d:'directory', t:'template', r:'recurse', x:'ext', p:'private', a:'allfunctions', A:'Allfunctions', e:'encoding', o:'out', h:'help', 'D[]':'define'});
 41VERBOSE = JsDoc.opt.v;
 42
 43require("app/JsIO.js");
 44require("app/Symbol.js");
 45require("app/JsToke.js");
 46require("app/JsParse.js");
 47require("app/DocTag.js");
 48require("app/Doclet.js");
 49require("app/DocFile.js");
 50require("app/JsPlate.js");
 51
 52/** The main function. Called automatically. */
 53function Main() {
 54	if (JsDoc.opt.o) LOG.out = IO.open(JsDoc.opt.o, true);
 55	if (!JsDoc.opt.e) JsDoc.opt.e = "utf-8";
 56	IO.setEncoding(JsDoc.opt.e);
 57	
 58	if (JsDoc.opt.c) {
 59		eval('conf = '+IO.readFile(JsDoc.opt.c));
 60		
 61		for (var c in conf) {
 62			if (c !== "D") {
 63				JsDoc.opt[c] = conf[c];
 64			}
 65		}
 66	}
 67	if (JsDoc.opt.h || JsDoc.opt._.length == 0 || JsDoc.opt.t === true) JsDoc.usage();
 68	
 69	var ext = ["js"];
 70	if (JsDoc.opt.x) ext = JsDoc.opt.x.split(",").map(function(x) {return x.toLowerCase()});
 71
 72	if (typeof(JsDoc.opt.r) == "boolean") JsDoc.opt.r = 10;
 73	else if (!isNaN(parseInt(JsDoc.opt.r))) JsDoc.opt.r = parseInt(JsDoc.opt.r);
 74	else JsDoc.opt.r = 1;
 75		
 76	if (JsDoc.opt.d === true || JsDoc.opt.t === true) { // like when a user enters: -d mydir
 77		LOG.warn("Option malformed.");
 78		JsDoc.usage();
 79	}
 80	else if (!JsDoc.opt.d) {
 81		JsDoc.opt.d = "js_docs_out";
 82	}
 83
 84	JsDoc.opt.d += (JsDoc.opt.d.indexOf(IO.FileSeparator) == JsDoc.opt.d.length-1)?
 85		"" : IO.FileSeparator;
 86	LOG.inform("Creating output directory: "+JsDoc.opt.d);
 87	IO.makeDir(JsDoc.opt.d);
 88	
 89	LOG.inform("Scanning for source files: recursion set to "+JsDoc.opt.r+" subdir"+((JsDoc.opt.r==1)?"":"s")+".");
 90	function isJs(element, index, array) {
 91		var thisExt = element.split(".").pop().toLowerCase();
 92		return (ext.indexOf(thisExt) > -1); // we're only interested in files with certain extensions
 93	}
 94	var srcFiles = [];
 95	for (var d = 0; d < JsDoc.opt._.length; d++) {
 96		if (!IO.exists(JsDoc.opt._[d])) {
 97			LOG.warn("src file doesn't exist, skipping: "+JsDoc.opt._[d]);
 98		}
 99		else {
100			srcFiles = srcFiles.concat(
101				IO.ls(JsDoc.opt._[d], JsDoc.opt.r).filter(isJs)
102			);
103		}
104	}
105	
106	if (srcFiles.length == 0 ) {
107		LOG.warn("No valid files found to parse. Nothing to do.");
108	}
109	else {
110		LOG.inform(srcFiles.length+" source file"+((srcFiles ==1)?"":"s")+" found:\n\t"+srcFiles.join("\n\t"));
111		var fileGroup = JsDoc.parse(srcFiles, JsDoc.opt);
112		
113		var D = {};
114		if (JsDoc.opt.D) {
115			for (var i = 0; i < JsDoc.opt.D.length; i++) {
116				var defineParts = JsDoc.opt.D[i].split(":", 2);
117				D[defineParts[0]] = defineParts[1];
118			}
119			JsDoc.opt.D = D;
120		}
121		else {
122			JsDoc.opt.D = {};
123		}
124	
125		// combine any conf file D options with the commandline D options
126		if (typeof conf != "undefined") for (var c in conf.D) {
127			if (typeof JsDoc.opt.D[c] == "undefined") {
128				JsDoc.opt.D[c] = conf.D[c];
129			}
130		}
131		
132		if (JsDoc.opt.t && IO.exists(JsDoc.opt.t)) {
133			JsDoc.opt.t += (JsDoc.opt.t.indexOf(IO.FileSeparator)==JsDoc.opt.t.length-1)?
134				"" : IO.FileSeparator;
135			LOG.inform("Loading template: "+JsDoc.opt.t+"publish.js");
136			require(JsDoc.opt.t+"publish.js");
137			
138			LOG.inform("Publishing all files...");
139			publish(fileGroup, JsDoc.opt);
140			LOG.inform("Finished.");
141		}
142		else {
143			LOG.warn("Use the -t option to specify a template for formatting.");
144			LOG.warn("Dumping results to stdout.");
145			require("app/Dumper.js");
146			print(Dumper.dump(fileGroup));
147		}
148	}
149	if (LOG.out) LOG.out.close();
150	if (LOG.warnings.length > 0) print(LOG.warnings.length+" warnings.");
151}
152
153Main();