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);
77                             // we're only interested in files with certain extensions
78                     }
79                 )
80             );
81         }
82         
83         return this.srcFiles;
84     },
85
86     _parseSrcFiles : function() 
87     {
88         Parser.init();
89         
90         for (var i = 0, l = this.srcFiles.length; i < l; i++) {
91             
92             var srcFile = this.srcFiles[i];
93             
94             
95             var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
96             
97             //println(cacheFile);
98             // disabled at present!@!!
99             
100             if (false && !Options.disablecache  && File.exists(cacheFile)) {
101                 // check filetime?
102                 
103                 var c_mt = File.getTimes(cacheFile);
104                 var o_mt = File.getTimes(srcFile);
105                 //println(c_mt.toSource());
106                // println(o_mt.toSource());
107                
108                 // this check does not appear to work according to the doc's - need to check it out.
109                
110                 if (c_mt[0] > o_mt[0]) { // cached time  > original time!
111                     // use the cached mtimes..
112                     var syms =  JSON.parse(File.read(cacheFile));
113                     
114                     throw "Conversion of cache not done yet!";
115                     
116                     for (var sy in syms) {
117                         //println("ADD:" + sy );
118                        Parser.symbols.addSymbol(syms[sy]);
119                     }
120                     continue;
121                 }
122             }
123             
124             var src = ''
125             try {
126                 src = File.read(srcFile);
127             }
128             catch(e) {
129                 LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
130                 continue;
131             }
132
133              
134             var tr = new TokenReader();
135             var ts = new TokenStream(tr.tokenize(src));
136         
137             Parser.parse(ts, srcFile);
138               
139             //var outstr = JSON.stringify(
140             //    Parser.filesSymbols[srcFile]._index
141             //);
142             //File.write(cacheFile, outstr);
143              
144                 
145     //          }
146         }
147         
148         
149         
150         Parser.finish();
151     }
152     
153      
154         
155      
156      
157     
158 };
159   
160
161
162
163
164
165  
166
167
168
169