JSDOC/BuildDocs.js
[gnome.introspection-doc-generator] / JSDOC / BuildDocs.js
1 //<script type="text/javascript">
2 /**
3         This is the main container for the JSDOC application.
4         @namespace
5 */
6
7
8 XObject = import.XObject.XObject;
9 File = import.File.File;
10
11 Options = import.Options.Options;
12 Parser   = import.Parser.Parser;
13
14 /******************    INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
15
16 // should not realy be here -- or anywhere...??
17
18
19
20
21
22 BuildDocs = {
23     
24     VERSION : "2.0.0",
25     
26     
27     srcFiles : [],
28     
29     build : function (opts)
30     {
31         
32         XObject.extend(Options, opts);
33          
34         Options.init();
35         
36     
37          
38         
39         Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
40         Options.LOG.inform("With options: ");
41         
42         if (!File.isDirectory(Options.cacheDirectory)) {   
43             File.mkdir(Options.cacheDirectory)
44         }
45         
46         Options.srcFiles = this._getSrcFiles();
47         this._parseSrcFiles();
48         this.symbolSet = Parser.symbols;
49          
50              
51         
52          
53         
54         
55     },
56     
57     
58     _getSrcFiles : function() 
59     {
60         this.srcFiles = [];
61         
62         var ext = ["js"];
63         if (JSDOC.opt.x) {
64             ext = JSDOC.opt.x.split(",").map(function($) {return $.toLowerCase()});
65         }
66         
67         for (var i = 0; i < JSDOC.opt._.length; i++) {
68             this.srcFiles = this.srcFiles.concat(
69                 IO.ls(JSDOC.opt._[i], JSDOC.opt.r).filter(
70                     function($) {
71                         var thisExt = $.split(".").pop().toLowerCase();
72                         return (ext.indexOf(thisExt) > -1 || thisExt in JSDOC.handlers); // we're only interested in files with certain extensions
73                     }
74                 )
75             );
76         }
77         
78         return this.srcFiles;
79     },
80
81     _parseSrcFiles : function() 
82     {
83         Parser.init();
84         
85         for (var i = 0, l = this.srcFiles.length; i < l; i++) {
86             
87             var srcFile = this.srcFiles[i];
88             
89             
90             var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
91             
92             //println(cacheFile);
93             
94             if (!Options.disablecache  && File.exists(cacheFile)) {
95                 // check filetime?
96                 
97                 var c_mt = File.getTimes(cacheFile);
98                 var o_mt = File.getTimes(srcFile);
99                 //println(c_mt.toSource());
100                // println(o_mt.toSource());
101                
102                 // this check does not appear to work according to the doc's - need to check it out.
103                
104                 if (c_mt[0] > o_mt[0]) { // cached time  > original time!
105                     // use the cached mtimes..
106                     var syms =  JSON.parse(File.read(cacheFile));
107                     
108                     throw "Conversion of cache not done yet!";
109                     
110                     for (var sy in syms) {
111                         //println("ADD:" + sy );
112                        Parser.symbols.addSymbol(syms[sy]);
113                     }
114                     continue;
115                 }
116             }
117             
118             var src = ''
119             try {
120                 src = File.read(srcFile);
121             }
122             catch(e) {
123                 LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
124                 continue;
125             }
126
127             // Check to see if there is a handler for this file type
128     //          var ext = FilePath.fileExtension(srcFile);
129     //          if (JSDOC.handlers[ext]) {
130     //                  LOG.inform(" Using external handler for '" + ext + "'");
131     // 
132     //                  symbols = symbols.concat(JSDOC.handlers[ext].handle(srcFile, src));
133     //                  symbols.handler = JSDOC.handlers[ext];
134     //          }
135     //          else {
136                 // The default (JSDOC) handler
137                 var tr = new JSDOC.TokenReader();
138                 var ts = new JSDOC.TokenStream(tr.tokenize(src));
139         
140                 JSDOC.Parser.parse(ts, srcFile);
141                  //  println("Symbols: " + JSDOC.Parser.symbols.keys().toSource());
142                 var outstr = JSDOC.prettyDump(JSDOC.toQDump(JSDOC.Parser.filesSymbols[JSDOC.Symbol.srcFile]._index,'{','}'))            
143             
144             //if (outstr.length > 3) {
145                 // dont cache crap..
146                 File.write(cacheFile, outstr);
147             //}
148                 
149     //          }
150         }
151         
152         
153         
154         JSDOC.Parser.finish();
155     }
156     
157      
158         
159      
160      
161     
162 };
163   
164
165
166
167
168
169  
170
171
172
173