PageRenderTime 32ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://jsdoc-toolkit.googlecode.com/
JavaScript | 140 lines | 105 code | 20 blank | 15 comment | 35 complexity | 75fdb429dc99b0470e533153a25ed868 MD5 | raw file
  1. /**
  2. @constructor
  3. @param [opt] Used to override the commandline options. Useful for testing.
  4. @version $Id: JsDoc.js 831 2010-03-09 14:24:56Z 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 param = JSDOC.opt.D[i];
  39. // remove first and last character if both == "
  40. if (
  41. param.length > 1
  42. && param.charAt(0) == '"'
  43. && param.charAt(param.length-1) == '"'
  44. ) {
  45. param = param.substr(1, param.length-2);
  46. }
  47. var defineParts = param.split(":");
  48. if (defineParts && defineParts.length > 1) {
  49. for ( var dpIdx = 2; dpIdx < defineParts.length; dpIdx++ ) {
  50. defineParts[1] += ':' + defineParts[dpIdx];
  51. }
  52. D[defineParts[0]] = defineParts[1];
  53. }
  54. }
  55. }
  56. JSDOC.opt.D = D;
  57. // combine any conf file D options with the commandline D options
  58. if (defined(JSDOC.conf)) for (var c in JSDOC.conf.D) {
  59. if (!defined(JSDOC.opt.D[c])) {
  60. JSDOC.opt.D[c] = JSDOC.conf.D[c];
  61. }
  62. }
  63. // Give plugins a chance to initialize
  64. if (defined(JSDOC.PluginManager)) {
  65. JSDOC.PluginManager.run("onInit", JSDOC.opt);
  66. }
  67. JSDOC.opt.srcFiles = JSDOC.JsDoc._getSrcFiles();
  68. JSDOC.JsDoc._parseSrcFiles();
  69. JSDOC.JsDoc.symbolSet = JSDOC.Parser.symbols;
  70. }
  71. /**
  72. Retrieve source file list.
  73. @returns {String[]} The pathnames of the files to be parsed.
  74. */
  75. JSDOC.JsDoc._getSrcFiles = function() {
  76. JSDOC.JsDoc.srcFiles = [];
  77. var ext = ["js"];
  78. if (JSDOC.opt.x) {
  79. ext = JSDOC.opt.x.split(",").map(function($) {return $.toLowerCase()});
  80. }
  81. for (var i = 0; i < JSDOC.opt._.length; i++) {
  82. JSDOC.JsDoc.srcFiles = JSDOC.JsDoc.srcFiles.concat(
  83. IO.ls(JSDOC.opt._[i], JSDOC.opt.r).filter(
  84. function($) {
  85. var thisExt = $.split(".").pop().toLowerCase();
  86. if (JSDOC.opt.E) {
  87. for(var n = 0; n < JSDOC.opt.E.length; n++) {
  88. if ($.match(new RegExp(JSDOC.opt.E[n]))) {
  89. LOG.inform("Excluding " + $);
  90. return false; // if the file matches the regex then it's excluded.
  91. }
  92. }
  93. }
  94. return (ext.indexOf(thisExt) > -1); // we're only interested in files with certain extensions
  95. }
  96. )
  97. );
  98. }
  99. return JSDOC.JsDoc.srcFiles;
  100. }
  101. JSDOC.JsDoc._parseSrcFiles = function() {
  102. JSDOC.Parser.init();
  103. for (var i = 0, l = JSDOC.JsDoc.srcFiles.length; i < l; i++) {
  104. var srcFile = JSDOC.JsDoc.srcFiles[i];
  105. if (JSDOC.opt.v) LOG.inform("Parsing file: " + srcFile);
  106. try {
  107. var src = IO.readFile(srcFile);
  108. }
  109. catch(e) {
  110. LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
  111. }
  112. var tr = new JSDOC.TokenReader();
  113. var ts = new JSDOC.TokenStream(tr.tokenize(new JSDOC.TextStream(src)));
  114. JSDOC.Parser.parse(ts, srcFile);
  115. }
  116. JSDOC.Parser.finish();
  117. if (JSDOC.PluginManager) {
  118. JSDOC.PluginManager.run("onFinishedParsing", JSDOC.Parser.symbols);
  119. }
  120. }