jsdoc.js 2.7 KB

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