PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/jsdoc-toolkit/app/main.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 133 lines | 93 code | 20 blank | 20 comment | 35 complexity | 8cc5c7719ce54d9c02863a23d3a4cf4c MD5 | raw file
  1/**
  2 * @version $Id: main.js 847 2010-07-03 08:03:44Z micmath $
  3 */
  4
  5function main() {
  6	IO.include("lib/JSDOC.js");
  7	IO.includeDir("plugins/");
  8	
  9	// process the options
 10	
 11	// the -c option: options are defined in a configuration file
 12	if (JSDOC.opt.c) {
 13		eval("JSDOC.conf = " + IO.readFile(JSDOC.opt.c));
 14		
 15		LOG.inform("Using configuration file at '"+JSDOC.opt.c+"'.");
 16		
 17		for (var c in JSDOC.conf) {
 18			if (c !== "D" && !defined(JSDOC.opt[c])) { // commandline overrules config file
 19				JSDOC.opt[c] = JSDOC.conf[c];
 20			}
 21		}
 22		
 23		if (typeof JSDOC.conf["_"] != "undefined") {
 24			JSDOC.opt["_"] = JSDOC.opt["_"].concat(JSDOC.conf["_"]);
 25		}
 26		
 27		LOG.inform("With configuration: ");
 28		for (var o in JSDOC.opt) {
 29			LOG.inform("    "+o+": "+JSDOC.opt[o]);
 30		}
 31	}
 32	
 33	// hat tip: jeff from metrocat.org
 34	if (JSDOC.opt.plugins) {
 35	    //  Can't use IO.includeDir because it assumes relative paths
 36		if (SYS.slash != JSDOC.opt.plugins.slice(-1))
 37			JSDOC.opt.plugins += SYS.slash;
 38
 39	    var pluginFiles= IO.ls(JSDOC.opt.plugins);
 40	    var len = pluginFiles.length;
 41	    
 42		for (var i = 0; i < len; ++i) {
 43		    if ('.js'!==pluginFiles[i].slice(-3)) continue;
 44		    load(pluginFiles[i]);
 45        }
 46	}
 47	    
 48	// be verbose
 49	if (JSDOC.opt.v) LOG.verbose = true;
 50	
 51	// send log messages to a file
 52	if (JSDOC.opt.o) LOG.out = IO.open(JSDOC.opt.o);
 53	
 54	// run the unit tests
 55	if (JSDOC.opt.T) {
 56		LOG.inform("JsDoc Toolkit running in test mode at "+new Date()+".");
 57		IO.include("frame/Testrun.js");
 58		IO.include("test.js");
 59	}
 60	else {
 61		// a common error, caused by -t mytemplate, instead of -t=mytemplate
 62		if (typeof JSDOC.opt.t !== 'string') {
 63			LOG.warn("No template given. Might as well read the usage notes.");
 64			JSDOC.usage();
 65			quit();
 66		}
 67		
 68		// a template must be defined and must be a directory path
 69		if (!JSDOC.opt.t && System.getProperty("jsdoc.template.dir")) {
 70			JSDOC.opt.t = System.getProperty("jsdoc.template.dir");
 71		}
 72		if (JSDOC.opt.t && SYS.slash != JSDOC.opt.t.slice(-1)) {
 73			JSDOC.opt.t += SYS.slash;
 74		}
 75		
 76		// verbose messages about the options we were given
 77		LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
 78		LOG.inform("With options: ");
 79		for (var o in JSDOC.opt) {
 80			LOG.inform("    "+o+": "+JSDOC.opt[o]);
 81		}
 82		
 83		// initialize and build a symbolSet from your code
 84		JSDOC.JsDoc();
 85		
 86		// debugger's option: dump the entire symbolSet produced from your code
 87		if (JSDOC.opt.Z) {
 88			LOG.warn("So you want to see the data structure, eh? This might hang if you have circular refs...");
 89			IO.include("frame/Dumper.js");
 90			var symbols = JSDOC.JsDoc.symbolSet.toArray();
 91			for (var i = 0, l = symbols.length; i < l; i++) {
 92				var symbol = symbols[i];
 93				print("// symbol: " + symbol.alias);
 94				print(symbol.serialize());
 95			}
 96		}
 97		else {
 98			if (typeof JSDOC.opt.t != "undefined") {
 99				try {
100					// a file named "publish.js" must exist in the template directory
101					load(JSDOC.opt.t+"publish.js");
102					
103					// and must define a function named "publish"
104					if (!publish) {
105						LOG.warn("No publish() function is defined in that template so nothing to do.");
106					}
107					else {
108						// which will be called with the symbolSet produced from your code
109						publish(JSDOC.JsDoc.symbolSet);
110					}
111				}
112				catch(e) {
113					LOG.warn("Sorry, that doesn't seem to be a valid template: "+JSDOC.opt.t+"publish.js : "+e);
114				}
115			}
116			else {
117				LOG.warn("No template given. Might as well read the usage notes.");
118				JSDOC.usage();
119			}
120		}
121	}
122	
123	// notify of any warnings
124	if (!JSDOC.opt.q && LOG.warnings.length) {
125		print(LOG.warnings.length+" warning"+(LOG.warnings.length != 1? "s":"")+".");
126	}
127	
128	// stop sending log messages to a file
129	if (LOG.out) {
130		LOG.out.flush();
131		LOG.out.close();
132	}
133}