main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @version $Id: main.js 847 2010-07-03 08:03:44Z 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. // hat tip: jeff from metrocat.org
  26. if (JSDOC.opt.plugins) {
  27. // Can't use IO.includeDir because it assumes relative paths
  28. if (SYS.slash != JSDOC.opt.plugins.slice(-1))
  29. JSDOC.opt.plugins += SYS.slash;
  30. var pluginFiles= IO.ls(JSDOC.opt.plugins);
  31. var len = pluginFiles.length;
  32. for (var i = 0; i < len; ++i) {
  33. if ('.js'!==pluginFiles[i].slice(-3)) continue;
  34. load(pluginFiles[i]);
  35. }
  36. }
  37. // be verbose
  38. if (JSDOC.opt.v) LOG.verbose = true;
  39. // send log messages to a file
  40. if (JSDOC.opt.o) LOG.out = IO.open(JSDOC.opt.o);
  41. // run the unit tests
  42. if (JSDOC.opt.T) {
  43. LOG.inform("JsDoc Toolkit running in test mode at "+new Date()+".");
  44. IO.include("frame/Testrun.js");
  45. IO.include("test.js");
  46. }
  47. else {
  48. // a common error, caused by -t mytemplate, instead of -t=mytemplate
  49. if (typeof JSDOC.opt.t !== 'string') {
  50. LOG.warn("No template given. Might as well read the usage notes.");
  51. JSDOC.usage();
  52. quit();
  53. }
  54. // a template must be defined and must be a directory path
  55. if (!JSDOC.opt.t && System.getProperty("jsdoc.template.dir")) {
  56. JSDOC.opt.t = System.getProperty("jsdoc.template.dir");
  57. }
  58. if (JSDOC.opt.t && SYS.slash != JSDOC.opt.t.slice(-1)) {
  59. JSDOC.opt.t += SYS.slash;
  60. }
  61. // verbose messages about the options we were given
  62. LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
  63. LOG.inform("With options: ");
  64. for (var o in JSDOC.opt) {
  65. LOG.inform(" "+o+": "+JSDOC.opt[o]);
  66. }
  67. // initialize and build a symbolSet from your code
  68. JSDOC.JsDoc();
  69. // debugger's option: dump the entire symbolSet produced from your code
  70. if (JSDOC.opt.Z) {
  71. LOG.warn("So you want to see the data structure, eh? This might hang if you have circular refs...");
  72. IO.include("frame/Dumper.js");
  73. var symbols = JSDOC.JsDoc.symbolSet.toArray();
  74. for (var i = 0, l = symbols.length; i < l; i++) {
  75. var symbol = symbols[i];
  76. print("// symbol: " + symbol.alias);
  77. print(symbol.serialize());
  78. }
  79. }
  80. else {
  81. if (typeof JSDOC.opt.t != "undefined") {
  82. try {
  83. // a file named "publish.js" must exist in the template directory
  84. load(JSDOC.opt.t+"publish.js");
  85. // and must define a function named "publish"
  86. if (!publish) {
  87. LOG.warn("No publish() function is defined in that template so nothing to do.");
  88. }
  89. else {
  90. // which will be called with the symbolSet produced from your code
  91. publish(JSDOC.JsDoc.symbolSet);
  92. }
  93. }
  94. catch(e) {
  95. LOG.warn("Sorry, that doesn't seem to be a valid template: "+JSDOC.opt.t+"publish.js : "+e);
  96. }
  97. }
  98. else {
  99. LOG.warn("No template given. Might as well read the usage notes.");
  100. JSDOC.usage();
  101. }
  102. }
  103. }
  104. // notify of any warnings
  105. if (!JSDOC.opt.q && LOG.warnings.length) {
  106. print(LOG.warnings.length+" warning"+(LOG.warnings.length != 1? "s":"")+".");
  107. }
  108. // stop sending log messages to a file
  109. if (LOG.out) {
  110. LOG.out.flush();
  111. LOG.out.close();
  112. }
  113. }