Spaces:
Sleeping
Sleeping
File size: 3,690 Bytes
4cadbaf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
/**
@constructor
@param [opt] Used to override the commandline options. Useful for testing.
@version $Id: JsDoc.js 831 2010-03-09 14:24:56Z micmath $
*/
JSDOC.JsDoc = function(/**object*/ opt) {
if (opt) {
JSDOC.opt = opt;
}
if (JSDOC.opt.h) {
JSDOC.usage();
quit();
}
// defend against options that are not sane
if (JSDOC.opt._.length == 0) {
LOG.warn("No source files to work on. Nothing to do.");
quit();
}
if (JSDOC.opt.t === true || JSDOC.opt.d === true) {
JSDOC.usage();
}
if (typeof JSDOC.opt.d == "string") {
if (!JSDOC.opt.d.charAt(JSDOC.opt.d.length-1).match(/[\\\/]/)) {
JSDOC.opt.d = JSDOC.opt.d+"/";
}
LOG.inform("Output directory set to '"+JSDOC.opt.d+"'.");
IO.mkPath(JSDOC.opt.d);
}
if (JSDOC.opt.e) IO.setEncoding(JSDOC.opt.e);
// the -r option: scan source directories recursively
if (typeof JSDOC.opt.r == "boolean") JSDOC.opt.r = 10;
else if (!isNaN(parseInt(JSDOC.opt.r))) JSDOC.opt.r = parseInt(JSDOC.opt.r);
else JSDOC.opt.r = 1;
// the -D option: define user variables
var D = {};
if (JSDOC.opt.D) {
for (var i = 0; i < JSDOC.opt.D.length; i++) {
var param = JSDOC.opt.D[i];
// remove first and last character if both == "
if (
param.length > 1
&& param.charAt(0) == '"'
&& param.charAt(param.length-1) == '"'
) {
param = param.substr(1, param.length-2);
}
var defineParts = param.split(":");
if (defineParts && defineParts.length > 1) {
for ( var dpIdx = 2; dpIdx < defineParts.length; dpIdx++ ) {
defineParts[1] += ':' + defineParts[dpIdx];
}
D[defineParts[0]] = defineParts[1];
}
}
}
JSDOC.opt.D = D;
// combine any conf file D options with the commandline D options
if (defined(JSDOC.conf)) for (var c in JSDOC.conf.D) {
if (!defined(JSDOC.opt.D[c])) {
JSDOC.opt.D[c] = JSDOC.conf.D[c];
}
}
// Give plugins a chance to initialize
if (defined(JSDOC.PluginManager)) {
JSDOC.PluginManager.run("onInit", JSDOC.opt);
}
JSDOC.opt.srcFiles = JSDOC.JsDoc._getSrcFiles();
JSDOC.JsDoc._parseSrcFiles();
JSDOC.JsDoc.symbolSet = JSDOC.Parser.symbols;
}
/**
Retrieve source file list.
@returns {String[]} The pathnames of the files to be parsed.
*/
JSDOC.JsDoc._getSrcFiles = function() {
JSDOC.JsDoc.srcFiles = [];
var ext = ["js"];
if (JSDOC.opt.x) {
ext = JSDOC.opt.x.split(",").map(function($) {return $.toLowerCase()});
}
for (var i = 0; i < JSDOC.opt._.length; i++) {
JSDOC.JsDoc.srcFiles = JSDOC.JsDoc.srcFiles.concat(
IO.ls(JSDOC.opt._[i], JSDOC.opt.r).filter(
function($) {
var thisExt = $.split(".").pop().toLowerCase();
if (JSDOC.opt.E) {
for(var n = 0; n < JSDOC.opt.E.length; n++) {
if ($.match(new RegExp(JSDOC.opt.E[n]))) {
LOG.inform("Excluding " + $);
return false; // if the file matches the regex then it's excluded.
}
}
}
return (ext.indexOf(thisExt) > -1); // we're only interested in files with certain extensions
}
)
);
}
return JSDOC.JsDoc.srcFiles;
}
JSDOC.JsDoc._parseSrcFiles = function() {
JSDOC.Parser.init();
for (var i = 0, l = JSDOC.JsDoc.srcFiles.length; i < l; i++) {
var srcFile = JSDOC.JsDoc.srcFiles[i];
if (JSDOC.opt.v) LOG.inform("Parsing file: " + srcFile);
try {
var src = IO.readFile(srcFile);
}
catch(e) {
LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
}
var tr = new JSDOC.TokenReader();
var ts = new JSDOC.TokenStream(tr.tokenize(new JSDOC.TextStream(src)));
JSDOC.Parser.parse(ts, srcFile);
}
JSDOC.Parser.finish();
if (JSDOC.PluginManager) {
JSDOC.PluginManager.run("onFinishedParsing", JSDOC.Parser.symbols);
}
}
|