PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/jsdoc_toolkit-2.2.1/jsdoc-toolkit/app/lib/JSDOC/JsDoc.js

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