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