/tags/jsdoc_toolkit-2.4.0/jsdoc-toolkit/app/main.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 111 lines · 78 code · 16 blank · 17 comment · 29 complexity · 65257e8d2d1179eaa52fdfed53bc010e MD5 · raw file

  1. /**
  2. * @version $Id: main.js 818 2009-11-08 14:51:41Z micmath $
  3. */
  4. function main() {
  5. IO.include("lib/JSDOC.js");
  6. IO.includeDir("plugins/");
  7. // process the options
  8. // the -c option: options are defined in a configuration file
  9. if (JSDOC.opt.c) {
  10. eval("JSDOC.conf = " + IO.readFile(JSDOC.opt.c));
  11. LOG.inform("Using configuration file at '"+JSDOC.opt.c+"'.");
  12. for (var c in JSDOC.conf) {
  13. if (c !== "D" && !defined(JSDOC.opt[c])) { // commandline overrules config file
  14. JSDOC.opt[c] = JSDOC.conf[c];
  15. }
  16. }
  17. if (typeof JSDOC.conf["_"] != "undefined") {
  18. JSDOC.opt["_"] = JSDOC.opt["_"].concat(JSDOC.conf["_"]);
  19. }
  20. LOG.inform("With configuration: ");
  21. for (var o in JSDOC.opt) {
  22. LOG.inform(" "+o+": "+JSDOC.opt[o]);
  23. }
  24. }
  25. // be verbose
  26. if (JSDOC.opt.v) LOG.verbose = true;
  27. // send log messages to a file
  28. if (JSDOC.opt.o) LOG.out = IO.open(JSDOC.opt.o);
  29. // run the unit tests
  30. if (JSDOC.opt.T) {
  31. LOG.inform("JsDoc Toolkit running in test mode at "+new Date()+".");
  32. IO.include("frame/Testrun.js");
  33. IO.include("test.js");
  34. }
  35. else {
  36. // a template must be defined and must be a directory path
  37. if (!JSDOC.opt.t && System.getProperty("jsdoc.template.dir")) {
  38. JSDOC.opt.t = System.getProperty("jsdoc.template.dir");
  39. }
  40. if (JSDOC.opt.t && SYS.slash != JSDOC.opt.t.slice(-1)) {
  41. JSDOC.opt.t += SYS.slash;
  42. }
  43. // verbose messages about the options we were given
  44. LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
  45. LOG.inform("With options: ");
  46. for (var o in JSDOC.opt) {
  47. LOG.inform(" "+o+": "+JSDOC.opt[o]);
  48. }
  49. // initialize and build a symbolSet from your code
  50. JSDOC.JsDoc();
  51. // debugger's option: dump the entire symbolSet produced from your code
  52. if (JSDOC.opt.Z) {
  53. LOG.warn("So you want to see the data structure, eh? This might hang if you have circular refs...");
  54. IO.include("frame/Dumper.js");
  55. var symbols = JSDOC.JsDoc.symbolSet.toArray();
  56. for (var i = 0, l = symbols.length; i < l; i++) {
  57. var symbol = symbols[i];
  58. print("// symbol: " + symbol.alias);
  59. print(symbol.serialize());
  60. }
  61. }
  62. else {
  63. if (typeof JSDOC.opt.t != "undefined") {
  64. try {
  65. // a file named "publish.js" must exist in the template directory
  66. load(JSDOC.opt.t+"publish.js");
  67. // and must define a function named "publish"
  68. if (!publish) {
  69. LOG.warn("No publish() function is defined in that template so nothing to do.");
  70. }
  71. else {
  72. // which will be called with the symbolSet produced from your code
  73. publish(JSDOC.JsDoc.symbolSet);
  74. }
  75. }
  76. catch(e) {
  77. LOG.warn("Sorry, that doesn't seem to be a valid template: "+JSDOC.opt.t+"publish.js : "+e);
  78. }
  79. }
  80. else {
  81. LOG.warn("No template given. Might as well read the usage notes.");
  82. JSDOC.usage();
  83. }
  84. }
  85. }
  86. // notify of any warnings
  87. if (!JSDOC.opt.q && LOG.warnings.length) {
  88. print(LOG.warnings.length+" warning"+(LOG.warnings.length != 1? "s":"")+".");
  89. }
  90. // stop sending log messages to a file
  91. if (LOG.out) {
  92. LOG.out.flush();
  93. LOG.out.close();
  94. }
  95. }