1 //<script type="text/javascript">
3 This is the main container for the JSDOC application.
8 XObject = imports.XObject.XObject;
9 File = imports.File.File;
11 Options = imports.Options.Options;
12 Parser = imports.Parser.Parser;
14 TokenReader = imports.TokenReader.TokenReader;
15 TokenStream = imports.TokenStream.TokenStream;
16 Symbol = imports.Symbol.Symbol;
17 /****************** INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
19 // should not realy be here -- or anywhere...??
32 build : function (opts)
35 XObject.extend(Options, opts);
42 Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
43 Options.LOG.inform("With options: ");
45 if (!File.isDirectory(Options.cacheDirectory)) {
46 File.mkdir(Options.cacheDirectory)
49 Options.srcFiles = this._getSrcFiles();
50 this._parseSrcFiles();
51 this.symbolSet = Parser.symbols;
53 // this currently uses the concept of publish.js...
62 _getSrcFiles : function()
68 ext = Options.ext.split(",").map(function($) {return $.toLowerCase()});
71 for (var i = 0; i < Options.src.length; i++) {
72 this.srcFiles = this.srcFiles.concat(
74 File.list(Options.src[i] ).filter(
76 var thisExt = $.split(".").pop().toLowerCase();
77 return (ext.indexOf(thisExt) > -1); // || thisExt in JSDOC.handlers);
78 // we're only interested in files with certain extensions
87 _parseSrcFiles : function()
91 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
93 var srcFile = this.srcFiles[i];
96 var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
99 // disabled at present!@!!
101 if (false && !Options.disablecache && File.exists(cacheFile)) {
104 var c_mt = File.getTimes(cacheFile);
105 var o_mt = File.getTimes(srcFile);
106 //println(c_mt.toSource());
107 // println(o_mt.toSource());
109 // this check does not appear to work according to the doc's - need to check it out.
111 if (c_mt[0] > o_mt[0]) { // cached time > original time!
112 // use the cached mtimes..
113 var syms = JSON.parse(File.read(cacheFile));
115 throw "Conversion of cache not done yet!";
117 for (var sy in syms) {
118 //println("ADD:" + sy );
119 Parser.symbols.addSymbol(syms[sy]);
127 src = File.read(srcFile);
130 LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
135 var tr = new TokenReader();
136 var ts = new TokenStream(tr.tokenize(src));
138 Parser.parse(ts, srcFile);
140 //var outstr = JSON.stringify(
141 // Parser.filesSymbols[srcFile]._index
143 //File.write(cacheFile, outstr);
156 publish : function() {
160 publish.conf = { // trailing slash expected for dirs
163 templatesDir: JSDOC.opt.t + "/",
164 symbolsDir: "symbols/",
165 srcDir: "symbols/src/"
168 publish.conf.outDir = (JSDOC.opt.d.length > 0 ? JSDOC.opt.d : "/tmp/jsdoc/");
173 if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
174 Link.prototype._makeSrcLink = function(srcFilePath) {
175 return "<"+srcFilePath+">";
179 println(publish.conf.outDir);
181 if (!File.exists(publish.conf.outDir))
182 File.mkdir(publish.conf.outDir);
183 if (!File.exists(publish.conf.outDir+"symbols"))
184 File.mkdir(publish.conf.outDir+"symbols");
185 if (!File.exists(publish.conf.outDir+"symbols/src"))
186 File.mkdir(publish.conf.outDir+"symbols/src");
188 IO.copyFile (publish.conf.templatesDir+"static/default.css", publish.conf.outDir, "default.css");
189 IO.copyFile (publish.conf.templatesDir+"static/doc.js", publish.conf.outDir, "doc.js");
190 IO.copyFile (publish.conf.templatesDir+"static/page.js", publish.conf.outDir, "page.js");
193 //IO.mkPath((publish.conf.outDir+"symbols/src").split("/"));
195 // used to check the details of things being linked to
196 Link.symbolSet = symbolSet;
199 var classTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"class.tmpl");
200 var classesTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allclasses.tmpl");
209 classTemplate.symbolSet = symbolSet;
212 function hasNoParent($) {return ($.memberOf == "")}
213 function isaFile($) {return ($.is("FILE"))}
214 function isaClass($) { return ($.is("CONSTRUCTOR") || $.isNamespace); }
216 var symbols = symbolSet.toArray();
218 var files = JSDOC.opt.srcFiles;
219 for (var i = 0, l = files.length; i < l; i++) {
221 var srcDir = publish.conf.outDir + "symbols/src/";
222 makeSrcFile(file, srcDir);
225 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
228 publish.classesIndex = classesTemplate.process(classes); // kept in memory
230 IO.makeDir(publish.conf.outDir+"json");
232 for (var i = 0, l = classes.length; i < l; i++) {
233 var symbol = classes[i];
236 output = classTemplate.process(symbol);
237 println("write " + publish.conf.outDir+"symbols/" +symbol.alias+publish.conf.ext);
238 IO.saveFile(publish.conf.outDir+"symbols/", symbol.alias+publish.conf.ext, output);
240 IO.saveFile(publish.conf.outDir+"json/", symbol.alias+'.json' , publish.jsonRender(symbol));
245 // regenrate the index with different relative links
247 publish.classesIndex = classesTemplate.process(classes);
250 var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"index.tmpl");
252 catch(e) { print(e.message); quit(); }
254 var classesIndex = classesindexTemplate.process(classes);
255 IO.saveFile(publish.conf.outDir, "index"+publish.conf.ext, classesIndex);
256 classesindexTemplate = classesIndex = classes = null;
259 var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl");
261 catch(e) { print(e.message); quit(); }
263 var documentedFiles = symbols.filter(isaFile);
266 for (var i = 0; i < files.length; i++) {
267 allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
270 for (var i = 0; i < documentedFiles.length; i++) {
271 var offset = files.indexOf(documentedFiles[i].alias);
272 allFiles[offset] = documentedFiles[i];
275 allFiles = allFiles.sort(makeSortby("name"));
277 var filesIndex = fileindexTemplate.process(allFiles);
278 IO.saveFile(publish.conf.outDir, "files"+publish.conf.ext, filesIndex);
279 fileindexTemplate = filesIndex = files = null;