3 @param [opt] Used to override the commandline options. Useful for testing.
4 @version $Id: JsDoc.js 831 2010-03-09 14:24:56Z micmath $
6 JSDOC
.JsDoc
= function(/**object*/ opt
) {
16 // defend against options that are not sane
17 if (JSDOC
.opt
._
.length
== 0) {
18 LOG
.warn("No source files to work on. Nothing to do.");
21 if (JSDOC
.opt
.t
=== true || JSDOC
.opt
.d
=== true) {
25 if (typeof JSDOC
.opt
.d
== "string") {
26 if (!JSDOC
.opt
.d
.charAt(JSDOC
.opt
.d
.length
-1).match(/[\\\/]/)) {
27 JSDOC
.opt
.d
= JSDOC
.opt
.d
+"/";
29 LOG
.inform("Output directory set to '"+JSDOC
.opt
.d
+"'.");
30 IO
.mkPath(JSDOC
.opt
.d
);
32 if (JSDOC
.opt
.e
) IO
.setEncoding(JSDOC
.opt
.e
);
34 // the -r option: scan source directories recursively
35 if (typeof JSDOC
.opt
.r
== "boolean") JSDOC
.opt
.r
= 10;
36 else if (!isNaN(parseInt(JSDOC
.opt
.r
))) JSDOC
.opt
.r
= parseInt(JSDOC
.opt
.r
);
39 // the -D option: define user variables
42 for (var i
= 0; i
< JSDOC
.opt
.D
.length
; i
++) {
43 var param
= JSDOC
.opt
.D
[i
];
44 // remove first and last character if both == "
47 && param
.charAt(0) == '"'
48 && param
.charAt(param
.length
-1) == '"'
50 param
= param
.substr(1, param
.length
-2);
52 var defineParts
= param
.split(":");
53 if (defineParts
&& defineParts
.length
> 1) {
54 for ( var dpIdx
= 2; dpIdx
< defineParts
.length
; dpIdx
++ ) {
55 defineParts
[1] += ':' + defineParts
[dpIdx
];
57 D
[defineParts
[0]] = defineParts
[1];
62 // combine any conf file D options with the commandline D options
63 if (defined(JSDOC
.conf
)) for (var c
in JSDOC
.conf
.D
) {
64 if (!defined(JSDOC
.opt
.D
[c
])) {
65 JSDOC
.opt
.D
[c
] = JSDOC
.conf
.D
[c
];
69 // Give plugins a chance to initialize
70 if (defined(JSDOC
.PluginManager
)) {
71 JSDOC
.PluginManager
.run("onInit", JSDOC
.opt
);
74 JSDOC
.opt
.srcFiles
= JSDOC
.JsDoc
._getSrcFiles();
75 JSDOC
.JsDoc
._parseSrcFiles();
76 JSDOC
.JsDoc
.symbolSet
= JSDOC
.Parser
.symbols
;
80 Retrieve source file list.
81 @returns {String[]} The pathnames of the files to be parsed.
83 JSDOC
.JsDoc
._getSrcFiles
= function() {
84 JSDOC
.JsDoc
.srcFiles
= [];
88 ext
= JSDOC
.opt
.x
.split(",").map(function($) {return $.toLowerCase()});
91 for (var i
= 0; i
< JSDOC
.opt
._
.length
; i
++) {
92 JSDOC
.JsDoc
.srcFiles
= JSDOC
.JsDoc
.srcFiles
.concat(
93 IO
.ls(JSDOC
.opt
._
[i
], JSDOC
.opt
.r
).filter(
95 var thisExt
= $.split(".").pop().toLowerCase();
98 for(var n
= 0; n
< JSDOC
.opt
.E
.length
; n
++) {
99 if ($.match(new RegExp(JSDOC
.opt
.E
[n
]))) {
100 LOG
.inform("Excluding " + $);
101 return false; // if the file matches the regex then it's excluded.
106 return (ext
.indexOf(thisExt
) > -1); // we're only interested in files with certain extensions
112 return JSDOC
.JsDoc
.srcFiles
;
115 JSDOC
.JsDoc
._parseSrcFiles
= function() {
117 for (var i
= 0, l
= JSDOC
.JsDoc
.srcFiles
.length
; i
< l
; i
++) {
118 var srcFile
= JSDOC
.JsDoc
.srcFiles
[i
];
120 if (JSDOC
.opt
.v
) LOG
.inform("Parsing file: " + srcFile
);
123 var src
= IO
.readFile(srcFile
);
126 LOG
.warn("Can't read source file '"+srcFile
+"': "+e
.message
);
129 var tr
= new JSDOC
.TokenReader();
130 var ts
= new JSDOC
.TokenStream(tr
.tokenize(new JSDOC
.TextStream(src
)));
132 JSDOC
.Parser
.parse(ts
, srcFile
);
135 JSDOC
.Parser
.finish();
137 if (JSDOC
.PluginManager
) {
138 JSDOC
.PluginManager
.run("onFinishedParsing", JSDOC
.Parser
.symbols
);