UNPKG

3 kBJavaScriptView Raw
1#!/usr/bin/env node
2/* global arguments, require: true */
3/* eslint strict: [2, "function"] */
4/**
5 * @project jsdoc
6 * @author Michael Mathews <micmath@gmail.com>
7 * @license See LICENSE.md file included in this distribution.
8 */
9
10// initialize the environment for the current JavaScript VM
11(function(args) {
12 'use strict';
13
14 var path;
15
16 if (args[0] && typeof args[0] === 'object') {
17 // we should be on Node.js
18 args = [__dirname, process.cwd()];
19 path = require('path');
20
21 // Create a custom require method that adds `lib/jsdoc` and `node_modules` to the module
22 // lookup path. This makes it possible to `require('jsdoc/foo')` from external templates and
23 // plugins, and within JSDoc itself. It also allows external templates and plugins to
24 // require JSDoc's module dependencies without installing them locally.
25 require = require('requizzle')({
26 requirePaths: {
27 before: [path.join(__dirname, 'lib')],
28 after: [path.join(__dirname, 'node_modules')]
29 },
30 infect: true
31 });
32 }
33
34 require('./lib/jsdoc/util/runtime').initialize(args);
35})( Array.prototype.slice.call(arguments, 0) );
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 */
46global.env = (function() {
47 'use strict';
48 return require('./lib/jsdoc/env');
49})();
50
51/**
52 * Data that must be shared across the entire application.
53 *
54 * @deprecated As of JSDoc 3.4.0. Avoid using the `app` object. The global `app` object and the
55 * `jsdoc/app` module will be removed in a future release.
56 * @namespace
57 * @name app
58 */
59global.app = (function() {
60 'use strict';
61 return require('./lib/jsdoc/app');
62})();
63
64(function() {
65 'use strict';
66
67 var env = global.env;
68 var logger = require('./lib/jsdoc/util/logger');
69 var runtime = require('./lib/jsdoc/util/runtime');
70 var cli = require('./cli');
71
72 function cb(errorCode) {
73 cli.logFinish();
74 cli.exit(errorCode || 0);
75 }
76
77 cli.setVersionInfo()
78 .loadConfig();
79
80 if (!env.opts.test) {
81 cli.configureLogger();
82 }
83
84 cli.logStart();
85
86 if (env.opts.debug) {
87 /**
88 * Recursively print an object's properties to stdout. This method is safe to use with
89 * objects that contain circular references.
90 *
91 * This method is available only when JSDoc is run with the `--debug` option.
92 *
93 * @global
94 * @name dump
95 * @private
96 * @param {...*} obj - Object(s) to print to stdout.
97 */
98 global.dump = function() {
99 console.log(require('./lib/jsdoc/util/dumper').dump(arguments));
100 };
101 }
102
103 cli.runCommand(cb);
104})();