-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
162 lines (140 loc) · 4.41 KB
/
index.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
/**
* @module jsdoc-api
* @typicalname jsdoc
*/
import Cache from 'cache-point'
import Explain from './lib/explain.js'
import Render from './lib/render.js'
import arrayify from 'array-back'
import TempFile from './lib/temp-file.js'
TempFile.createTmpDirs()
/**
* @external cache-point
* @see https://github.com/75lb/cache-point
*/
/**
* The [cache-point](https://github.com/75lb/cache-point) instance used when `cache: true` is specified on `.explain()`.
* @type {external:cache-point}
*/
const cache = new Cache({ dir: TempFile.cacheDir })
/**
* @alias module:jsdoc-api
*/
const jsdoc = {
cache,
/**
* Returns a promise for the jsdoc explain output.
*
* @param [options] {module:jsdoc-api~JsdocOptions}
* @fulfil {object[]} - jsdoc explain output
* @returns {Promise}
*/
async explain (options) {
options = new JsdocOptions(options)
const command = new Explain(options, cache)
return command.execute()
},
/**
* Render jsdoc documentation.
*
* @param [options] {module:jsdoc-api~JsdocOptions}
* @prerequisite Requires node v0.12 or above
* @example
* await jsdoc.render({ files: 'lib/*', destination: 'api-docs' })
*/
async render (options) {
options = new JsdocOptions(options)
const command = new Render(options)
return command.execute()
}
}
/**
* The jsdoc options, common for all operations.
* @typicalname options
*/
class JsdocOptions {
constructor (options = {}) {
/**
* One or more filenames to process. Either `files`, `source` or `configure` must be supplied.
* @type {string|string[]}
*/
this.files = arrayify(options.files)
/**
* A string or an array of strings containing source code to process. Either `files`, `source` or `configure` must be supplied.
* @type {string|string[]}
*/
this.source = options.source
/**
* Set to `true` to cache the output - future invocations with the same input will return immediately.
* @type {boolean}
* @default
*/
this.cache = options.cache
/**
* Only display symbols with the given access: "public", "protected", "private" or "undefined", or "all" for all access levels. Default: all except "private".
* @type {string}
*/
this.access = options.access
/**
* The path to the configuration file. Default: path/to/jsdoc/conf.json. Either `files`, `source` or `configure` must be supplied.
* @type {string}
*/
this.configure = options.configure
/**
* The path to the output folder. Use "console" to dump data to the console. Default: ./out/.
* @type {string}
*/
this.destination = options.destination
/**
* Assume this encoding when reading all source files. Default: utf8.
* @type {string}
*/
this.encoding = options.encoding
/**
* Display symbols marked with the @private tag. Equivalent to "--access all". Default: false.
* @type {boolean}
*/
this.private = options.private
/**
* The path to the project's package file. Default: path/to/sourcefiles/package.json
* @type {string}
*/
this.package = options.package
/**
* Treat errors as fatal errors, and treat warnings as errors. Default: false.
* @type {boolean}
*/
this.pedantic = options.pedantic
/**
* A query string to parse and store in jsdoc.env.opts.query. Example: foo=bar&baz=true.
* @type {string}
*/
this.query = options.query
/**
* Recurse into subdirectories when scanning for source files and tutorials.
* @type {boolean}
*/
this.recurse = options.recurse
/**
* The path to the project's README file. Default: path/to/sourcefiles/README.md.
* @type {string}
*/
this.readme = options.readme
/* Warning to avoid a common mistake where dmd templates are passed in.. a jsdoc template must be a filename. */
if (typeof options.template === 'string' && options.template.split(/\r?\n/).length !== 1) {
console.warn('Suspicious `options.template` value - the jsdoc `template` option must be a file path.')
console.warn(options.template)
}
/**
* The path to the template to use. Default: path/to/jsdoc/templates/default.
* @type {string}
*/
this.template = options.template
/**
* Directory in which JSDoc should search for tutorials.
* @type {string}
*/
this.tutorials = options.tutorials
}
}
export default jsdoc