jsdoc.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env node
  2. /* global require: true */
  3. /* eslint strict: ["error", "function"] */
  4. // initialize the environment for Node.js
  5. (function() {
  6. 'use strict';
  7. var fs = require('fs');
  8. var path = require('path');
  9. var env;
  10. var jsdocPath = __dirname;
  11. var pwd = process.cwd();
  12. // Create a custom require method that adds `lib/jsdoc` and `node_modules` to the module
  13. // lookup path. This makes it possible to `require('jsdoc/foo')` from external templates and
  14. // plugins, and within JSDoc itself. It also allows external templates and plugins to
  15. // require JSDoc's module dependencies without installing them locally.
  16. require = require('requizzle')({
  17. requirePaths: {
  18. before: [path.join(__dirname, 'lib')],
  19. after: [path.join(__dirname, 'node_modules')]
  20. },
  21. infect: true
  22. });
  23. // resolve the path if it's a symlink
  24. if ( fs.statSync(jsdocPath).isSymbolicLink() ) {
  25. jsdocPath = path.resolve( path.dirname(jsdocPath), fs.readlinkSync(jsdocPath) );
  26. }
  27. env = require('./lib/jsdoc/env');
  28. env.dirname = jsdocPath;
  29. env.pwd = pwd;
  30. env.args = process.argv.slice(2);
  31. })();
  32. /**
  33. * Data about the environment in which JSDoc is running, including the configuration settings that
  34. * were used to run JSDoc.
  35. *
  36. * @deprecated As of JSDoc 3.4.0. Use `require('jsdoc/env')` to access the `env` object. The global
  37. * `env` object will be removed in a future release.
  38. * @namespace
  39. * @name env
  40. */
  41. global.env = (function() {
  42. 'use strict';
  43. return require('./lib/jsdoc/env');
  44. })();
  45. /**
  46. * Data that must be shared across the entire application.
  47. *
  48. * @deprecated As of JSDoc 3.4.0. Avoid using the `app` object. The global `app` object and the
  49. * `jsdoc/app` module will be removed in a future release.
  50. * @namespace
  51. * @name app
  52. */
  53. global.app = (function() {
  54. 'use strict';
  55. return require('./lib/jsdoc/app');
  56. })();
  57. (function() {
  58. 'use strict';
  59. var env = global.env;
  60. var cli = require('./cli');
  61. function cb(errorCode) {
  62. cli.logFinish();
  63. cli.exit(errorCode || 0);
  64. }
  65. cli.setVersionInfo()
  66. .loadConfig();
  67. if (!env.opts.test) {
  68. cli.configureLogger();
  69. }
  70. cli.logStart();
  71. if (env.opts.debug) {
  72. /**
  73. * Recursively print an object's properties to stdout. This method is safe to use with
  74. * objects that contain circular references.
  75. *
  76. * This method is available only when JSDoc is run with the `--debug` option.
  77. *
  78. * @global
  79. * @name dump
  80. * @private
  81. * @param {...*} obj - Object(s) to print to stdout.
  82. */
  83. global.dump = function() {
  84. console.log(require('./lib/jsdoc/util/dumper').dump(arguments));
  85. };
  86. }
  87. cli.runCommand(cb);
  88. })();