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