@@ -24,7 +24,8 @@ var fs = require('fs'),
24
24
formatLint = require ( './lib/lint' ) . formatLint ,
25
25
garbageCollect = require ( './lib/garbage_collect' ) ,
26
26
lintComments = require ( './lib/lint' ) . lintComments ,
27
- markdownAST = require ( './lib/output/markdown_ast' ) ;
27
+ markdownAST = require ( './lib/output/markdown_ast' ) ,
28
+ loadConfig = require ( './lib/load_config' ) ;
28
29
29
30
/**
30
31
* Build a pipeline of comment handlers.
@@ -64,6 +65,19 @@ function expandInputs(indexes, options, callback) {
64
65
inputFn ( indexes , options , callback ) ;
65
66
}
66
67
68
+ /**
69
+ * Given an options object, it expands the `config` field
70
+ * if it exists.
71
+ *
72
+ * @param {Object } options - options to process
73
+ * @returns {undefined }
74
+ */
75
+ function expandConfig ( options ) {
76
+ if ( options && typeof options . config === 'string' ) {
77
+ Object . assign ( options , loadConfig ( options . config ) ) ;
78
+ }
79
+ }
80
+
67
81
/**
68
82
* Generate JavaScript documentation as a list of parsed JSDoc
69
83
* comments, given a root file as a path.
@@ -114,6 +128,8 @@ function expandInputs(indexes, options, callback) {
114
128
function build ( indexes , options , callback ) {
115
129
options = options || { } ;
116
130
131
+ expandConfig ( options ) ;
132
+
117
133
if ( typeof indexes === 'string' ) {
118
134
indexes = [ indexes ] ;
119
135
}
@@ -122,11 +138,14 @@ function build(indexes, options, callback) {
122
138
if ( error ) {
123
139
return callback ( error ) ;
124
140
}
141
+
142
+ var result ;
125
143
try {
126
- callback ( null , buildSync ( inputs , options ) ) ;
144
+ result = buildSync ( inputs , options ) ;
127
145
} catch ( e ) {
128
- callback ( e ) ;
146
+ return callback ( e ) ;
129
147
}
148
+ callback ( null , result ) ;
130
149
} ) ;
131
150
}
132
151
@@ -137,6 +156,7 @@ function build(indexes, options, callback) {
137
156
*
138
157
* @param {Array<string> } indexes files to process
139
158
* @param {Object } options options
159
+ * @param {string } config path to configuration file to load
140
160
* @param {Array<string> } options.external a string regex / glob match pattern
141
161
* that defines what external modules will be whitelisted and included in the
142
162
* generated documentation.
@@ -172,6 +192,8 @@ function buildSync(indexes, options) {
172
192
options = options || { } ;
173
193
options . hljs = options . hljs || { } ;
174
194
195
+ expandConfig ( options ) ;
196
+
175
197
if ( ! options . access ) {
176
198
options . access = [ 'public' , 'undefined' , 'protected' ] ;
177
199
}
@@ -259,6 +281,8 @@ function buildSync(indexes, options) {
259
281
function lint ( indexes , options , callback ) {
260
282
options = options || { } ;
261
283
284
+ expandConfig ( options ) ;
285
+
262
286
if ( typeof indexes === 'string' ) {
263
287
indexes = [ indexes ] ;
264
288
}
0 commit comments