-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathabout-configuring-jsdoc.html
252 lines (249 loc) · 14.9 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
<!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 role="banner">
<div class="container">
<h1 class="branding"><a href="./index.html">@use JSDoc</a></h1>
</div>
<!--/.container-->
</header>
<article role="main">
<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>
</li>
<li>
<a href="#tags-and-tag-dictionaries">Tags and tag dictionaries</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,
"dictionaries": ["jsdoc","closure"]
},
"source": {
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"plugins": [],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
}
}
</code></pre></figure>
<p>This means:</p>
<ul>
<li>JSDoc allows you to use unrecognized tags (<code>tags.allowUnknownTags</code>);</li>
<li>Both standard JSDoc tags and <a href="https://developers.google.com/closure/compiler/docs/js-for-compiler#tags">Closure Compiler tags</a> are enabled (
<code>tags.dictionaries</code>);</li>
<li>Only files ending in ".js", ".jsdoc", and ".jsx" 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><code>@link</code> tags are rendered in plain text (<code>templates.cleverLinks</code>, <code>templates.monospaceLinks</code>).</li>
</ul>
<p>These options and others will be further explained on this page.</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.</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. In JSDoc 3.3.0 and later, this array may include subdirectories of the paths
in <code>source.include</code>.</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>Command-line options set in the configuration file</figcaption><pre class="prettyprint lang-js"><code>"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
}
</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, which converts Markdown-formatted text to HTML, and the "summarize" plugin, which autogenerates
a summary for each doclet:</p>
<figure><pre class="prettyprint"><code>"plugins": [
"plugins/markdown",
"plugins/summarize"
]
</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 the appearance and content of generated documentation. Custom templates may not implement all of these options.
See <a href="about-configuring-default-template.html">Configuring JSDoc's Default
Template</a> for additional options that the default template supports.</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-inline-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-inline-link.html">@link, @linkcode and @linkplain</a> for further information).</p>
<h2 id="tags-and-tag-dictionaries">Tags and tag dictionaries</h2>
<p>The options in <code>tags</code> control which JSDoc tags are allowed and how each tag is interpreted.</p>
<figure><pre class="prettyprint lang-js"><code>"tags": {
"allowUnknownTags": true,
"dictionaries": ["jsdoc","closure"]
}
</code></pre></figure>
<p>The <code>tags.allowUnknownTags</code> property affects how JSDoc handles unrecognized tags. If you set this option to <code>false</code>, and JSDoc finds a
tag that it does not recognize (for example, <code>@foo</code>), JSDoc logs a warning. By default, this option is set to <code>true</code>. In JSDoc 3.4.1
and later, you can also set this property to an array of tag names that JSDoc should allow (for example, <code>["foo","bar"]</code>).</p>
<p>The <code>tags.dictionaries</code> property controls which tags JSDoc recognizes, as well as how JSDoc interprets the tags that it recognizes. In JSDoc 3.3.0
and later, there are two built-in tag dictionaries:
</p>
<ul>
<li><code>jsdoc</code>: Core JSDoc tags.</li>
<li><code>closure</code>: <a href="https://developers.google.com/closure/compiler/docs/js-for-compiler#tags">Closure Compiler tags</a>.</li>
</ul>
<p>By default, both dictionaries are enabled. Also, by default, the <code>jsdoc</code> dictionary is listed first; as a result, if the <code>jsdoc</code> dictionary
handles a tag differently than the <code>closure</code> dictionary, the
<code>jsdoc</code> version of the tag takes precedence.</p>
<p>If you are using JSDoc with a Closure Compiler project, and you want to avoid using tags that Closure Compiler does not recognize, change the <code>tags.dictionaries</code> setting to <code>["closure"]</code>. You can also change this setting to <code>["closure","jsdoc"]</code> if you want to allow
core JSDoc tags, but you want to ensure that Closure Compiler-specific tags are interpreted as Closure Compiler would interpret them.</p>
<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 role="contentinfo">
<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>