@@ -24,7 +24,8 @@ var fs = require('fs'),
2424 formatLint = require ( './lib/lint' ) . formatLint ,
2525 garbageCollect = require ( './lib/garbage_collect' ) ,
2626 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' ) ;
2829
2930/**
3031 * Build a pipeline of comment handlers.
@@ -64,6 +65,19 @@ function expandInputs(indexes, options, callback) {
6465 inputFn ( indexes , options , callback ) ;
6566}
6667
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+
6781/**
6882 * Generate JavaScript documentation as a list of parsed JSDoc
6983 * comments, given a root file as a path.
@@ -114,6 +128,8 @@ function expandInputs(indexes, options, callback) {
114128function build ( indexes , options , callback ) {
115129 options = options || { } ;
116130
131+ expandConfig ( options ) ;
132+
117133 if ( typeof indexes === 'string' ) {
118134 indexes = [ indexes ] ;
119135 }
@@ -122,11 +138,14 @@ function build(indexes, options, callback) {
122138 if ( error ) {
123139 return callback ( error ) ;
124140 }
141+
142+ var result ;
125143 try {
126- callback ( null , buildSync ( inputs , options ) ) ;
144+ result = buildSync ( inputs , options ) ;
127145 } catch ( e ) {
128- callback ( e ) ;
146+ return callback ( e ) ;
129147 }
148+ callback ( null , result ) ;
130149 } ) ;
131150}
132151
@@ -137,6 +156,7 @@ function build(indexes, options, callback) {
137156 *
138157 * @param {Array<string> } indexes files to process
139158 * @param {Object } options options
159+ * @param {string } config path to configuration file to load
140160 * @param {Array<string> } options.external a string regex / glob match pattern
141161 * that defines what external modules will be whitelisted and included in the
142162 * generated documentation.
@@ -172,6 +192,8 @@ function buildSync(indexes, options) {
172192 options = options || { } ;
173193 options . hljs = options . hljs || { } ;
174194
195+ expandConfig ( options ) ;
196+
175197 if ( ! options . access ) {
176198 options . access = [ 'public' , 'undefined' , 'protected' ] ;
177199 }
@@ -259,6 +281,8 @@ function buildSync(indexes, options) {
259281function lint ( indexes , options , callback ) {
260282 options = options || { } ;
261283
284+ expandConfig ( options ) ;
285+
262286 if ( typeof indexes === 'string' ) {
263287 indexes = [ indexes ] ;
264288 }
0 commit comments