UNPKG

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