|
| 1 | +/** |
| 2 | + @overview |
| 3 | + @date $Date$ |
| 4 | + @version $Revision$ |
| 5 | + @location $HeadURL$ |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + This is the main container for the JSDOC application. |
| 10 | +*/ |
| 11 | + |
| 12 | +var parser = exports.optionsParser = new (require("args").Parser)(); |
| 13 | +var jsdoc = require("./jsdocs/js-doc"); |
| 14 | + |
| 15 | +var version = "3.0.0"; |
| 16 | +parser.usage("jsdocs [OPTIONS] <SRC_DIR> <SRC_FILE> ..."); |
| 17 | +parser.help("[OPTIONS]"); |
| 18 | +parser.option("-d", "--directory", "destination") |
| 19 | + .help("Output to this directory (defaults to \"out\").") |
| 20 | + .def("out") |
| 21 | + .set(); |
| 22 | +parser.option("-t", "--template", "template") |
| 23 | + .help("Relative path to the template used for formating the output.") |
| 24 | + .set(); |
| 25 | +parser.option("-a", "--all", "allfunctions") |
| 26 | + .help("Include all functions, even undocumented ones.") |
| 27 | + .bool(); |
| 28 | +parser.option("--include-anoymus", "ignoreAnonymous") |
| 29 | + .help("Include all functions, even anonymus ones.") |
| 30 | + .def(true) |
| 31 | + .set(false); |
| 32 | +parser.option("--explain", "explain") |
| 33 | + .help("Explain ??") // TODO: put better help message |
| 34 | + .def(false) |
| 35 | + .set(true); |
| 36 | +parser.option("--underscore-is-not-private", "treatUnderscoredAsPrivate") |
| 37 | + .help("Don't treat properties starting with underscore as privates.") |
| 38 | + .def(true) |
| 39 | + .set(false); |
| 40 | +parser.option("-c", "--config", "conf") |
| 41 | + .help("Load a configuration file.") |
| 42 | + .set(); |
| 43 | +parser.option("-D", "--define", "define") |
| 44 | + .help("-D=\"myVar:My value\" or --define=\"myVar:'My value'\"\n" + |
| 45 | + "Multiple. Define a variable, available in JsDoc as JSDOC.opt.D.myVar.") |
| 46 | + .set(); |
| 47 | +parser.option("-e", "--encoding", "encoding") |
| 48 | + .help("-e=<ENCODING> or --encoding=<ENCODING>\n" + |
| 49 | + "Use this encoding to read and write files.") |
| 50 | + .def("utf-8") |
| 51 | + .set(); |
| 52 | +parser.option("-E", "--exclude", "exclude") |
| 53 | + .help("-E=\"REGEX\" or --exclude=\"REGEX\"\n" + |
| 54 | + "Multiple. Exclude files based on the supplied regex.") |
| 55 | + .def([]) |
| 56 | + .action(collection); |
| 57 | +parser.option("-n", "--nocode", "ignoreCode") |
| 58 | + .help("Ignore all code, only document comments with @name tags.") |
| 59 | + .def(false) |
| 60 | + .set(true); |
| 61 | +parser.option("-o", "--out", "out") |
| 62 | + .help("Print log messages to a file (defaults to stdout).") |
| 63 | + .set(); |
| 64 | +parser.option("-p", "--private", "includePrivates") |
| 65 | + .help("Include symbols tagged as private, underscored and inner symbols.") |
| 66 | + .def(false) |
| 67 | + .set(true); |
| 68 | +parser.option("-q", "--quiet", "quiet") |
| 69 | + .help("Do not output any messages, not even warnings.") |
| 70 | + .def(false) |
| 71 | + .set(true); |
| 72 | +parser.option("-r", "--recurse", "recurse") |
| 73 | + .help("Descend into src directories.") |
| 74 | + .integer() |
| 75 | + .def(1) |
| 76 | + .set(); |
| 77 | +parser.option("-s", "--suppress", "includeSource") |
| 78 | + .help("Suppress source code output.") |
| 79 | + .def(false) |
| 80 | + .set(true); |
| 81 | +parser.option("-S", "--securemodules", "securemodules") |
| 82 | + .help("Use Secure Modules mode to parse source code.") |
| 83 | + .def(false) |
| 84 | + .set(true); |
| 85 | +parser.option("-T", "--test", "test") |
| 86 | + .help("Run all unit tests and exit.") |
| 87 | + .action(function() { |
| 88 | + print("run tests"); |
| 89 | + }); |
| 90 | +parser.option("-u", "--unique", "destination") |
| 91 | + .help("Force file names to be unique, but not based on symbol names.") |
| 92 | + .def(false) |
| 93 | + .set(true); |
| 94 | +parser.option("-v", "--verbose", "verbose") |
| 95 | + .help("Provide verbose feedback about what is happening.") |
| 96 | + .def(false) |
| 97 | + .set(true); |
| 98 | +parser.option("-x", "--ext", "extensions") |
| 99 | + .help("-x=<EXT>[,EXT]... or --ext=<EXT>[,EXT]...\n" + |
| 100 | + "Scan source files with the given extensions separated by \":\" (defaults to .js)") |
| 101 | + .def([".js"]) |
| 102 | + .action(collection); |
| 103 | +parser.option("--version", "version") |
| 104 | + .help("print jsdoc-toolkit version number and exit.") |
| 105 | + .action(function() { |
| 106 | + this.print(version); |
| 107 | + this.exit(); |
| 108 | + }); |
| 109 | +parser.option("-h", "--help") |
| 110 | + .action(parser.printHelp); |
| 111 | + |
| 112 | +exports.main = function main(args) { |
| 113 | + var options = exports.options = parser.parse(args); |
| 114 | + if (options.args.length > 1) { |
| 115 | + parser.printHelp(options); |
| 116 | + parser.exit(options); |
| 117 | + } else { |
| 118 | + collection(options, "src", options.args[0]); |
| 119 | + jsdoc.doc(options); |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +/** |
| 124 | + utility function used by arguments parser that splits |
| 125 | + arguments into subarguments. |
| 126 | + @param {Object} options object containing options that parser will return |
| 127 | + @param {String} name options name that being parsed |
| 128 | + @param {String} value value that being parsed |
| 129 | +*/ |
| 130 | +function collection(options, name, value) { |
| 131 | + options[name] = value.split(","); |
| 132 | +} |
| 133 | + |
| 134 | +if (require.main === module.id) exports.main(args) |
| 135 | +/** |
| 136 | + @requires Opt |
| 137 | + |
| 138 | +if (typeof arguments == "undefined") arguments = []; |
| 139 | +JSDOC.opt = Opt.get( |
| 140 | + arguments, |
| 141 | + { |
| 142 | + a: "allfunctions", |
| 143 | + c: "conf", |
| 144 | + d: "directory", |
| 145 | + "D[]": "define", |
| 146 | + e: "encoding", |
| 147 | + "E[]": "exclude", |
| 148 | + h: "help", |
| 149 | + n: "nocode", |
| 150 | + o: "out", |
| 151 | + p: "private", |
| 152 | + q: "quiet", |
| 153 | + r: "recurse", |
| 154 | + S: "securemodules", |
| 155 | + s: "suppress", |
| 156 | + t: "template", |
| 157 | + T: "testmode", |
| 158 | + u: "unique", |
| 159 | + v: "verbose", |
| 160 | + x: "ext" |
| 161 | + } |
| 162 | +); |
| 163 | + |
| 164 | + |
0 commit comments