forked from jsdoc/jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsdoc.js
executable file
·171 lines (149 loc) · 3.56 KB
/
jsdoc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env node
/*global arguments */
/**
* @project jsdoc
* @author Michael Mathews <[email protected]>
* @license See LICENSE.md file included in this distribution.
*/
/**
* Data representing the environment in which this app is running.
*
* @namespace
* @name env
*/
global.env = {
/**
* Running start and finish times.
*
* @memberof env
*/
run: {
start: new Date(),
finish: null
},
/**
* The command-line arguments passed into JSDoc.
*
* @type Array
* @memberof env
*/
args: [],
/**
* The parsed JSON data from the configuration file.
*
* @type Object
* @memberof env
*/
conf: {},
/**
* The absolute path to the base directory of the JSDoc application.
*
* @private
* @type string
* @memberof env
*/
dirname: '.',
/**
* The user's working directory at the time that JSDoc was started.
*
* @private
* @type string
* @memberof env
*/
pwd: null,
/**
* The command-line options, parsed into a key/value hash.
*
* @type Object
* @memberof env
* @example if (global.env.opts.help) { console.log('Helpful message.'); }
*/
opts: {},
/**
* The source files that JSDoc will parse.
* @type Array
* @memberof env
*/
sourceFiles: [],
/**
* The JSDoc version number and revision date.
*
* @type Object
* @memberof env
*/
version: {}
};
// initialize the environment for the current JavaScript VM
(function(args) {
'use strict';
if (args[0] && typeof args[0] === 'object') {
// we should be on Node.js
args = [__dirname, process.cwd()];
}
require('jsdoc/util/runtime').initialize(args);
})( Array.prototype.slice.call(arguments, 0) );
/**
* Data that must be shared across the entire application.
*
* @namespace
* @name app
*/
global.app = {
jsdoc: {
scanner: new (require('jsdoc/src/scanner').Scanner)(),
parser: null,
name: require('jsdoc/name')
}
};
/**
* Recursively print an object's properties to stdout. This method is safe to use with objects that
* contain circular references. In addition, on Mozilla Rhino, this method is safe to use with
* native Java objects.
*
* @global
* @name dump
* @private
* @param {Object} obj - Object(s) to print to stdout.
*/
global.dump = function() {
'use strict';
var doop = require('jsdoc/util/doop').doop;
var _dump = require('jsdoc/util/dumper').dump;
for (var i = 0, l = arguments.length; i < l; i++) {
console.log( _dump(doop(arguments[i])) );
}
};
(function() {
'use strict';
var logger = require('jsdoc/util/logger');
var path = require('jsdoc/path');
var runtime = require('jsdoc/util/runtime');
var cli = require( path.join(global.env.dirname, 'cli') );
cli.setVersionInfo()
.loadConfig();
if (!global.env.opts.test) {
cli.configureLogger();
}
cli.logStart();
function cb(errorCode) {
cli.logFinish();
cli.exit(errorCode || 0);
}
// On Rhino, we use a try/catch block so we can log the Java exception (if available)
if ( runtime.isRhino() ) {
try {
cli.runCommand(cb);
}
catch(e) {
if (e.rhinoException) {
logger.fatal( e.rhinoException.printStackTrace() );
} else {
console.trace(e);
cli.exit(1);
}
}
}
else {
cli.runCommand(cb);
}
})();