Skip to content

Commit af51156

Browse files
authored
Generate documentation with api-extractor (#1071)
This picks up where #984 had left off. This gets us started with generating docs using api-extractor. By no means it's complete - I wanted us to generate the doc and see the output as we incrementally improve the reference docs. Separately, I'm going to be pushing out PRs to suppress many warnings generated by api-extractor (e.g. mostly on missing documentation/annotation). To generate reference doc for v2, run the following command: ``` $ npm i $ npm run build $ npm run docgen:v2 ``` Documents should be generated in `docgen/v2/markdown` folder.
1 parent 1aa1865 commit af51156

File tree

7 files changed

+941
-7
lines changed

7 files changed

+941
-7
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
.vscode/
55
coverage
66
docgen/html
7+
docgen/*/temp
8+
docgen/*/markdown
9+
docgen/*/*.json
10+
docgen/*/*.md
711
firebase-functions-*.tgz
812
integration_test/.firebaserc
913
integration_test/*.log

docgen/api-extractor.base.json

Lines changed: 364 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,364 @@
1+
/**
2+
* Config file for API Extractor. For more info, please visit: https://api-extractor.com
3+
*/
4+
{
5+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
6+
7+
/**
8+
* Optionally specifies another JSON config file that this file extends from. This provides a way for
9+
* standard settings to be shared across multiple projects.
10+
*
11+
* If the path starts with "./" or "../", the path is resolved relative to the folder of the file that contains
12+
* the "extends" field. Otherwise, the first path segment is interpreted as an NPM package name, and will be
13+
* resolved using NodeJS require().
14+
*
15+
* SUPPORTED TOKENS: none
16+
* DEFAULT VALUE: ""
17+
*/
18+
// "extends": "./shared/api-extractor-base.json"
19+
// "extends": "my-package/include/api-extractor-base.json"
20+
21+
/**
22+
* Determines the "<projectFolder>" token that can be used with other config file settings. The project folder
23+
* typically contains the tsconfig.json and package.json config files, but the path is user-defined.
24+
*
25+
* The path is resolved relative to the folder of the config file that contains the setting.
26+
*
27+
* The default value for "projectFolder" is the token "<lookup>", which means the folder is determined by traversing
28+
* parent folders, starting from the folder containing api-extractor.json, and stopping at the first folder
29+
* that contains a tsconfig.json file. If a tsconfig.json file cannot be found in this way, then an error
30+
* will be reported.
31+
*
32+
* SUPPORTED TOKENS: <lookup>
33+
* DEFAULT VALUE: "<lookup>"
34+
*/
35+
"projectFolder": "..",
36+
37+
/**
38+
* (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor
39+
* analyzes the symbols exported by this module.
40+
*
41+
* The file extension must be ".d.ts" and not ".ts".
42+
*
43+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
44+
* prepend a folder token such as "<projectFolder>".
45+
*
46+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
47+
*/
48+
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
49+
50+
/**
51+
* A list of NPM package names whose exports should be treated as part of this package.
52+
*
53+
* For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
54+
* and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
55+
* of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
56+
* imports library2. To avoid this, we can specify:
57+
*
58+
* "bundledPackages": [ "library2" ],
59+
*
60+
* This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
61+
* local files for library1.
62+
*/
63+
"bundledPackages": [],
64+
65+
/**
66+
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
67+
*/
68+
"compiler": {
69+
/**
70+
* Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project.
71+
*
72+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
73+
* prepend a folder token such as "<projectFolder>".
74+
*
75+
* Note: This setting will be ignored if "overrideTsconfig" is used.
76+
*
77+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
78+
* DEFAULT VALUE: "<projectFolder>/tsconfig.json"
79+
*/
80+
"tsconfigFilePath": "<projectFolder>/tsconfig.release.json"
81+
/**
82+
* Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk.
83+
* The object must conform to the TypeScript tsconfig schema:
84+
*
85+
* http://json.schemastore.org/tsconfig
86+
*
87+
* If omitted, then the tsconfig.json file will be read from the "projectFolder".
88+
*
89+
* DEFAULT VALUE: no overrideTsconfig section
90+
*/
91+
// "overrideTsconfig": {
92+
// . . .
93+
// }
94+
/**
95+
* This option causes the compiler to be invoked with the --skipLibCheck option. This option is not recommended
96+
* and may cause API Extractor to produce incomplete or incorrect declarations, but it may be required when
97+
* dependencies contain declarations that are incompatible with the TypeScript engine that API Extractor uses
98+
* for its analysis. Where possible, the underlying issue should be fixed rather than relying on skipLibCheck.
99+
*
100+
* DEFAULT VALUE: false
101+
*/
102+
// "skipLibCheck": true,
103+
},
104+
105+
/**
106+
* Configures how the API report file (*.api.md) will be generated.
107+
*/
108+
"apiReport": {
109+
/**
110+
* (REQUIRED) Whether to generate an API report.
111+
*/
112+
"enabled": true,
113+
114+
/**
115+
* The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce
116+
* a full file path.
117+
*
118+
* The file extension should be ".api.md", and the string should not contain a path separator such as "\" or "/".
119+
*
120+
* SUPPORTED TOKENS: <packageName>, <unscopedPackageName>
121+
* DEFAULT VALUE: "<unscopedPackageName>.api.md"
122+
*/
123+
// "reportFileName": "<unscopedPackageName>.api.md",
124+
125+
/**
126+
* Specifies the folder where the API report file is written. The file name portion is determined by
127+
* the "reportFileName" setting.
128+
*
129+
* The API report file is normally tracked by Git. Changes to it can be used to trigger a branch policy,
130+
* e.g. for an API review.
131+
*
132+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
133+
* prepend a folder token such as "<projectFolder>".
134+
*
135+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
136+
* DEFAULT VALUE: "<projectFolder>/etc/"
137+
*/
138+
"reportFolder": "<projectFolder>/docgen/etc/",
139+
140+
/**
141+
* Specifies the folder where the temporary report file is written. The file name portion is determined by
142+
* the "reportFileName" setting.
143+
*
144+
* After the temporary file is written to disk, it is compared with the file in the "reportFolder".
145+
* If they are different, a production build will fail.
146+
*
147+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
148+
* prepend a folder token such as "<projectFolder>".
149+
*
150+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
151+
* DEFAULT VALUE: "<projectFolder>/temp/"
152+
*/
153+
"reportTempFolder": "<projectFolder>/docgen/temp/"
154+
},
155+
156+
/**
157+
* Configures how the doc model file (*.api.json) will be generated.
158+
*/
159+
"docModel": {
160+
/**
161+
* (REQUIRED) Whether to generate a doc model file.
162+
*/
163+
"enabled": true,
164+
165+
/**
166+
* The output path for the doc model file. The file extension should be ".api.json".
167+
*
168+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
169+
* prepend a folder token such as "<projectFolder>".
170+
*
171+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
172+
* DEFAULT VALUE: "<projectFolder>/temp/<unscopedPackageName>.api.json"
173+
*/
174+
"apiJsonFilePath": "<projectFolder>/docgen/<unscopedPackageName>.api.json"
175+
},
176+
177+
/**
178+
* Configures how the .d.ts rollup file will be generated.
179+
*/
180+
"dtsRollup": {
181+
/**
182+
* (REQUIRED) Whether to generate the .d.ts rollup file.
183+
*/
184+
"enabled": true
185+
186+
/**
187+
* Specifies the output path for a .d.ts rollup file to be generated without any trimming.
188+
* This file will include all declarations that are exported by the main entry point.
189+
*
190+
* If the path is an empty string, then this file will not be written.
191+
*
192+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
193+
* prepend a folder token such as "<projectFolder>".
194+
*
195+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
196+
* DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
197+
*/
198+
// "untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
199+
200+
/**
201+
* Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
202+
* This file will include only declarations that are marked as "@public" or "@beta".
203+
*
204+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
205+
* prepend a folder token such as "<projectFolder>".
206+
*
207+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
208+
* DEFAULT VALUE: ""
209+
*/
210+
// "betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-beta.d.ts",
211+
212+
/**
213+
* Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release.
214+
* This file will include only declarations that are marked as "@public".
215+
*
216+
* If the path is an empty string, then this file will not be written.
217+
*
218+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
219+
* prepend a folder token such as "<projectFolder>".
220+
*
221+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
222+
* DEFAULT VALUE: ""
223+
*/
224+
// "publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts",
225+
226+
/**
227+
* When a declaration is trimmed, by default it will be replaced by a code comment such as
228+
* "Excluded from this release type: exampleMember". Set "omitTrimmingComments" to true to remove the
229+
* declaration completely.
230+
*
231+
* DEFAULT VALUE: false
232+
*/
233+
// "omitTrimmingComments": true
234+
},
235+
236+
/**
237+
* Configures how the tsdoc-metadata.json file will be generated.
238+
*/
239+
"tsdocMetadata": {
240+
/**
241+
* Whether to generate the tsdoc-metadata.json file.
242+
*
243+
* DEFAULT VALUE: true
244+
*/
245+
// "enabled": true,
246+
/**
247+
* Specifies where the TSDoc metadata file should be written.
248+
*
249+
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
250+
* prepend a folder token such as "<projectFolder>".
251+
*
252+
* The default value is "<lookup>", which causes the path to be automatically inferred from the "tsdocMetadata",
253+
* "typings" or "main" fields of the project's package.json. If none of these fields are set, the lookup
254+
* falls back to "tsdoc-metadata.json" in the package folder.
255+
*
256+
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
257+
* DEFAULT VALUE: "<lookup>"
258+
*/
259+
// "tsdocMetadataFilePath": "<projectFolder>/dist/tsdoc-metadata.json"
260+
},
261+
262+
/**
263+
* Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
264+
* will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
265+
* To use the OS's default newline kind, specify "os".
266+
*
267+
* DEFAULT VALUE: "crlf"
268+
*/
269+
// "newlineKind": "crlf",
270+
271+
/**
272+
* Configures how API Extractor reports error and warning messages produced during analysis.
273+
*
274+
* There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages.
275+
*/
276+
"messages": {
277+
/**
278+
* Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing
279+
* the input .d.ts files.
280+
*
281+
* TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551"
282+
*
283+
* DEFAULT VALUE: A single "default" entry with logLevel=warning.
284+
*/
285+
"compilerMessageReporting": {
286+
/**
287+
* Configures the default routing for messages that don't match an explicit rule in this table.
288+
*/
289+
"default": {
290+
/**
291+
* Specifies whether the message should be written to the the tool's output log. Note that
292+
* the "addToApiReportFile" property may supersede this option.
293+
*
294+
* Possible values: "error", "warning", "none"
295+
*
296+
* Errors cause the build to fail and return a nonzero exit code. Warnings cause a production build fail
297+
* and return a nonzero exit code. For a non-production build (e.g. when "api-extractor run" includes
298+
* the "--local" option), the warning is displayed but the build will not fail.
299+
*
300+
* DEFAULT VALUE: "warning"
301+
*/
302+
"logLevel": "warning"
303+
304+
/**
305+
* When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md),
306+
* then the message will be written inside that file; otherwise, the message is instead logged according to
307+
* the "logLevel" option.
308+
*
309+
* DEFAULT VALUE: false
310+
*/
311+
// "addToApiReportFile": false
312+
}
313+
314+
// "TS2551": {
315+
// "logLevel": "warning",
316+
// "addToApiReportFile": true
317+
// },
318+
//
319+
// . . .
320+
},
321+
322+
/**
323+
* Configures handling of messages reported by API Extractor during its analysis.
324+
*
325+
* API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag"
326+
*
327+
* DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings
328+
*/
329+
"extractorMessageReporting": {
330+
"default": {
331+
"logLevel": "warning"
332+
// "addToApiReportFile": false
333+
}
334+
335+
// "ae-extra-release-tag": {
336+
// "logLevel": "warning",
337+
// "addToApiReportFile": true
338+
// },
339+
//
340+
// . . .
341+
},
342+
343+
/**
344+
* Configures handling of messages reported by the TSDoc parser when analyzing code comments.
345+
*
346+
* TSDoc message identifiers start with "tsdoc-". For example: "tsdoc-link-tag-unescaped-text"
347+
*
348+
* DEFAULT VALUE: A single "default" entry with logLevel=warning.
349+
*/
350+
"tsdocMessageReporting": {
351+
"default": {
352+
"logLevel": "warning"
353+
// "addToApiReportFile": false
354+
}
355+
356+
// "tsdoc-link-tag-unescaped-text": {
357+
// "logLevel": "warning",
358+
// "addToApiReportFile": true
359+
// },
360+
//
361+
// . . .
362+
}
363+
}
364+
}

docgen/api-extractor.v1.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"extends": "./api-extractor.base.json",
4+
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
5+
"docModel": {
6+
"enabled": true,
7+
"apiJsonFilePath": "<projectFolder>/docgen/v1/firebase-functions.api.json"
8+
},
9+
"apiReport": {
10+
"enabled": true,
11+
"reportTempFolder": "<projectFolder>/docgen/v1/temp",
12+
"reportFolder": "<projectFolder>/docgen/v1"
13+
}
14+
}

0 commit comments

Comments
 (0)