forked from jsdoc/jsdoc.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
about-configuring-jsdoc.html
304 lines (301 loc) · 15.6 KB
/
about-configuring-jsdoc.html
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!DOCTYPE html>
<!-- THIS IS A GENERATED FILE. DO NOT EDIT. -->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="How to configure JSDoc using a configuration file.">
<title>Use JSDoc: Configuring JSDoc with conf.json</title>
<link rel="stylesheet" href="styles/usejsdoc.css">
<link rel="stylesheet" href="styles/prettify.css">
<link rel="stylesheet" href="styles/css3-github-ribbon.css">
<script src="scripts/prettify.js"></script>
<!--[if lt IE 9]>
<script src="scripts/html5shiv.min.js"></script>
<script src="scripts/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<header>
<a href="./index.html">@use JSDoc</a>
</header>
<article>
<h1>Configuring JSDoc with conf.json</h1>
<h2>Table of Contents</h2>
<ul>
<li>
<a href="#configuration-file">Configuration File</a>
</li>
<li>
<a href="#specifying-input-files">Specifying input files</a>
</li>
<li>
<a href="#incorporating-command-line-options-into-the-configuration-file">Incorporating command-line options into the configuration file</a>
</li>
<li>
<a href="#plugins">Plugins</a>
</li>
<li>
<a href="#output-style-configuration">Output style configuration</a>
<ul>
<li>
<a href="#miscellaneous">Miscellaneous</a>
</li>
</ul>
</li>
<li>
<a href="#example-with-all-configuration-options">Example with all configuration options</a>
</li>
<li>
<a href="#related-links">Related Links</a>
</li>
</ul>
<h2 id="configuration-file">Configuration File</h2>
<p>To customise JSDoc's behaviour one can provide a configuration file in JSON format to JSDoc using the <code>-c</code> option, e.g. <code>jsdoc -c /path/to/conf.json</code>.</p>
<p>This file (typically named "conf.json") provides options in JSON format. Have a look at "conf.json.EXAMPLE" in the JSDoc directory as a basic
example. If you do not specify a configuration file, this is what JSDoc will use:</p>
<figure><pre class="prettyprint lang-js"><code>{
"tags": {
"allowUnknownTags": true
},
"source": {
"includePattern": ".+\\.js(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": [],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
}
}
</code></pre>
</figure>
<p>This means:</p>
<ul>
<li>Only files ending in ".js" and ".jsdoc" will be processed (<code>source.includePattern</code>);</li>
<li>Any file starting with an underscore or in a directory starting with an underscore will be
<em>ignored</em> (<code>source.excludePattern</code>);</li>
<li>No plugins are loaded (<code>plugins</code>);</li>
<li>@link tags are rendered as-is (i.e. in plain text as opposed to monospace) (
<code>templates.cleverLinks</code>, <code>templates.monospaceLinks</code>).</li>
</ul>
<p>These options and others will be further explained on this page. A full example is provided at the end.
</p>
<p>Further settings may be added to the file as requested by various plugins or templates (for example, the <a href="plugins-markdown.html">Markdown plugin</a> can be configured by including a "markdown" key).</p>
<h2 id="specifying-input-files">Specifying input files</h2>
<p>The "source" set of options, in combination with paths given to JSDoc on the command-line, determine what files JSDoc generates documentation for.
(Remove the comments before adding this example to your own .json file.)</p>
<figure><pre class="prettyprint lang-js"><code>"source": {
"include": [ /* array of paths to files to generate documentation for */ ],
"exclude": [ /* array of paths to exclude */ ],
"includePattern": ".+\\.js(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
}
</code></pre>
</figure>
<ul>
<li><code>source.include</code>: an optional array of paths that JSDoc should generate documentation for. The paths given to JSDoc on the command line are combined
with these to form the set of files JSDoc will scan. Recall that if a path is a directory, the <code>-r</code> option may be used to recurse into it.</li>
<li><code>source.exclude</code>: an optional array of paths that JSDoc should ignore.</li>
<li><code>source.includePattern</code>: an optional string, interpreted as a regular expression. If present, all files <em>must</em> match this in order to be
scanned by JSDoc. By default this is set to ".+\.js(doc)?$", meaning that only files that end in <code>.js</code> or <code>.jsdoc</code> will
be scanned.</li>
<li><code>source.excludePattern</code>: an optional string, interpreted as a regular expression. If present, any file matching this will be ignored. By default
this is set so that files beginning with an underscore (or anything under a directory beginning with an underscore) is ignored.</li>
</ul>
<p>The order that these options are used in is:</p>
<ol>
<li>Start with all paths given on the command line and in <code>source.include</code> for files (recall that using the <code>-r</code> command-line option will
search within subdirectories).</li>
<li>For each file found in Step 1, if the regular expression <code>source.includePattern</code> is present, the file <em>must</em> match it or it is ignored.</li>
<li>For each file left from Step 2, if the regular expression <code>source.excludePattern</code> is present, any file matching this is ignored.</li>
<li>For each file left from Step 3, if the path is in <code>source.exclude</code> it is ignored.</li>
</ol>
<p>All remaining files after these four steps are parsed by JSDoc.</p>
<p>As an example, suppose I have the following file structure:</p>
<figure><pre class="prettyprint"><code>myProject/
|- a.js
|- b.js
|- c.js
|- _private
| |- a.js
|- lib/
|- a.js
|- ignore.js
|- d.txt
</code></pre>
</figure>
<p>And I set the "source" part of my conf.json like so:</p>
<figure><pre class="prettyprint lang-js"><code>"source": {
"include": [ "myProject/a.js", "myProject/lib", "myProject/_private" ],
"exclude": [ "myProject/lib/ignore.js" ],
"includePattern": ".+\\.js(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
}
</code></pre>
</figure>
<p>If I run JSDoc like this from the file containing the <code>myProject</code> folder:</p>
<figure><pre class="prettyprint"><code>jsdoc myProject/c.js -c /path/to/my/conf.json -r
</code></pre>
</figure>
<p>Then JSDoc will make documentation for the files:</p>
<ul>
<li><code>myProject/a.js</code>
</li>
<li><code>myProject/c.js</code>
</li>
<li><code>myProject/lib/a.js</code>
</li>
</ul>
<p>The reasoning is as follows:</p>
<ol>
<li>Based off <code>source.include</code> and the paths given on the command line, we start off with files
<ul>
<li><code>myProject/c.js</code> (from the command line)</li>
<li><code>myProject/a.js</code> (from <code>source.include</code>)</li>
<li><code>myProject/lib/a.js</code>, <code>myProject/lib/ignore.js</code>, <code>myProject/lib/d.txt</code> (from <code>source.include</code> and using the
<code>-r</code> option)</li>
<li><code>myProject/_private/a.js</code> (from <code>source.include</code>)</li>
</ul>
</li>
<li>Apply <code>source.includePattern</code>, so that we are left with all of the above <em>except</em>
<code>myProject/lib/d.txt</code> (as it does not end in ".js" or ".jsdoc").</li>
<li>Apply <code>source.excludePattern</code>, which will remove <code>myProject/_private/a.js</code>.</li>
<li>Apply <code>source.exclude</code>, which will remove <code>myProject/lib/ignore.js</code>.</li>
</ol>
<h2 id="incorporating-command-line-options-into-the-configuration-file">Incorporating command-line options into the configuration file</h2>
<p>It is possible to put many of JSDoc's <a href="about-commandline.html">command-line options</a> into the configuration file instead of specifying them on
the command-line. To do this, use the longnames of the relevant options in an "opts" section of conf.json with the value being the option's value.</p>
<figure>
<figcaption>Example</figcaption><pre class="prettyprint lang-js"><code>// You must remove the comments before adding these options to your .json file
"opts": {
"template": "templates/default", // same as -t templates/default
"encoding": "utf8", // same as -e utf8
"destination": "./out/", // same as -d ./out/
"recurse": true, // same as -r
"tutorials": "path/to/tutorials", // same as -u path/to/tutorials
"query": "value", // same as -q value
"private": true, // same as -p
"lenient": true, // same as -l
// these can also be included, though you probably wouldn't bother
// putting these in conf.json rather than the command line as they cause
// JSDoc not to produce documentation.
"version": true, // same as --version or -v
"explain": true, // same as -X
"test": true, // same as -T
"help": true, // same as --help or -h
"verbose": true, // same as --verbose, only relevant to tests.
"match": "value", // same as --match value, only relevant to tests.
"nocolor": true // same as --nocolor, only relevant to tests
}
</code></pre>
</figure>
<p>Hence between <code>source.include</code> and <code>opts</code> it's possible to put <em>all</em> of jsdoc's arguments in a configuration file so that
the command-line reduces to:</p>
<pre class="prettyprint"><code>jsdoc -c /path/to/conf.json
</code></pre>
<p>In the case of options being provided on the command line <em>and</em> in conf.json, the command line takes precedence.
</p>
<h2 id="plugins">Plugins</h2>
<p>To enable plugins, add their paths (relative to the JSDoc folder) into the <code>plugins</code> array.</p>
<p>For example, the following will include the Markdown plugin and verbose output plugin:</p>
<figure><pre class="prettyprint"><code>"plugins": [
"plugins/markdown",
"plugins/verboseOutput"
]
</code></pre>
</figure>
<p>See the <a href="about-plugins.html">plugin reference</a> for further information, and look in <code>jsdoc/plugins</code> for the plugins built-in to JSDoc.</p>
<p>The Markdown plugin can be configured by including a "markdown" object into conf.json; see
<a href="plugins-markdown.html">Configuring the Markdown Plugin</a> for further information.</p>
<h2 id="output-style-configuration">Output style configuration</h2>
<p>The options in <code>templates</code> affect how JSDoc's output looks (although custom templates may not be affected by these, depending on how they are
coded).</p>
<figure><pre class="prettyprint lang-js"><code>"templates": {
"cleverLinks": false,
"monospaceLinks": false
}
</code></pre>
</figure>
<p>If <code>templates.monospaceLinks</code> is true, all link texts from the <a href="tags-link.html">@link</a> tag will be rendered in monospace.</p>
<p>If <code>templates.cleverLinks</code> is true, {@link asdf} will be rendered in normal font if "asdf" is a URL, and monospace otherwise. For example,
<code>{@link http://github.com}</code> will render in plain-text but
<code>{@link MyNamespace.myFunction}</code> will be in monospace.</p>
<p>If <code>templates.cleverLinks</code> is true, it is used and <code>templates.monospaceLinks</code> is ignored.</p>
<p>Also, there are {@linkcode ...} and {@linkplain ...} if one wishes to force the link to be rendered in monospace or normal font respectively (see <a href="tags-link.html">@link, @linkcode and @linkplain</a> for further information).</p>
<h3 id="miscellaneous">Miscellaneous</h3>
<p>The <code>tags.allowUnknownTags</code> property determines whether tags unrecognised by JSDoc are permitted. If this is false and JSDoc encounters a tag it does
not recognise (e.g. <code>@foobar</code>), it will throw an error. Otherwise, it will just ignore the tag.</p>
<p>By default, it is true.</p>
<figure><pre class="prettyprint"><code>"tags": {
"allowUnknownTags": true
}
</code></pre>
</figure>
<h2 id="example-with-all-configuration-options">Example with all configuration options</h2>
<p>Here is an example conf.json showing all possible configuration options native to the base JSDoc, along with their default values.</p>
<figure>
<figcaption>A conf.json showcasing all the configuration options to base JSDoc</figcaption><pre class="prettyprint lang-js"><code>// You must remove the comments before adding these options to your .json file
{
"tags": {
"allowUnknownTags": true
},
"source": {
"include": [],
"exclude": [],
"includePattern": ".+\\.js(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": [],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
},
"opts": {
"template": "templates/default", // same as -t templates/default
"encoding": "utf8", // same as -e utf8
"destination": "./out/", // same as -d ./out/
"recurse": true, // same as -r
"tutorials": "path/to/tutorials", // same as -u path/to/tutorials, default "" (no tutorials)
"query": "value", // same as -q value, default "" (no query)
"private": true, // same as -p
"lenient": true, // same as -l
// these can also be included, though you probably wouldn't bother
// putting these in conf.json rather than the command line as they cause
// JSDoc not to produce documentation.
"version": true, // same as --version or -v
"explain": true, // same as -X
"test": true, // same as -T
"help": true, // same as --help or -h
"verbose": true, // same as --verbose, only relevant to tests.
"match": "value", // same as --match value, only relevant to tests.
"nocolor": true // same as --nocolor, only relevant to tests
}
</code></pre>
</figure>
<h2 id="related-links">Related Links</h2>
<ul>
<li>
<a href="about-commandline.html">Command-line arguments to JSDoc</a>
</li>
<li>
<a href="about-plugins.html">About JSDoc plugins</a>
</li>
<li>
<a href="plugins-markdown.html">Using the Markdown plugin</a>
</li>
</ul>
</article>
<footer>
<a class="license-badge" href="http://creativecommons.org/licenses/by-sa/3.0/">
<img alt="Creative Commons License" class="license-badge" src="images/cc-by-sa.svg" width="80" height="15" />
</a>
<br> Copyright © 2011-2014 the
<a href="https://github.com/jsdoc3/jsdoc3.github.com/contributors">contributors</a> to the JSDoc 3 documentation project.
<br> This website is <a href="https://github.com/jsdoc3/jsdoc3.github.com">open source</a> and is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">
Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.
</footer>
<script type="text/javascript">
prettyPrint();
</script>
</body>
</html>