@@ -25,10 +25,16 @@ const yaml = require('js-yaml');
25
25
26
26
const repoPath = path . resolve ( `${ __dirname } /..` ) ;
27
27
28
+ const defaultSources = [
29
+ `${ repoPath } /lib/firebase-namespace.d.ts` ,
30
+ `${ repoPath } /lib/firebase-namespace-api.d.ts` ,
31
+ `${ repoPath } /lib/**/*.d.ts` ,
32
+ ] ;
33
+
28
34
// Command-line options.
29
35
const { source : sourceFile } = yargs
30
36
. option ( 'source' , {
31
- default : ` ${ repoPath } /src/*.d.ts` ,
37
+ default : defaultSources . join ( ' ' ) ,
32
38
describe : 'Typescript source file(s)' ,
33
39
type : 'string'
34
40
} )
@@ -51,6 +57,17 @@ const firestoreHeader = `<section class="tsd-panel-group tsd-member-group ">
51
57
<ul>` ;
52
58
const firestoreFooter = '\n </ul>\n</section>\n' ;
53
59
60
+ const databaseExcludes = [ 'enableLogging' ] ;
61
+ const databaseHtmlPath = `${ docPath } /admin.database.html` ;
62
+ const databaseHeader = `<section class="tsd-panel-group tsd-member-group ">
63
+ <h2>Type aliases</h2>
64
+ <div class="tsd-panel">
65
+ <p>Following types are defined in the <code>@firebase/database</code> package
66
+ and re-exported from this namespace for convenience.</p>
67
+ </div>
68
+ <ul>` ;
69
+ const databaseFooter = '\n </ul>\n</section>\n' ;
70
+
54
71
/**
55
72
* Strips path prefix and returns only filename.
56
73
* @param {string } path
@@ -99,7 +116,7 @@ function fixLinks(file) {
99
116
. replace ( / ( m o d u l e s | i n t e r f a c e s | c l a s s e s | e n u m s ) \/ / g, '' ) ;
100
117
let caseFixedLinks = flattenedLinks ;
101
118
for ( const lower in lowerToUpperLookup ) {
102
- const re = new RegExp ( lower , 'g' ) ;
119
+ const re = new RegExp ( '\\b' + lower , 'g' ) ;
103
120
caseFixedLinks = caseFixedLinks . replace ( re , lowerToUpperLookup [ lower ] ) ;
104
121
}
105
122
return fs . writeFile ( file , caseFixedLinks ) ;
@@ -119,7 +136,7 @@ function generateTempHomeMdFile(tocRaw, homeRaw) {
119
136
const { toc } = yaml . safeLoad ( tocRaw ) ;
120
137
let tocPageLines = [ homeRaw , '# API Reference' ] ;
121
138
toc . forEach ( group => {
122
- tocPageLines . push ( `\n## [${ group . title } ](${ stripPath ( group . path ) } )` ) ;
139
+ tocPageLines . push ( `\n## [${ group . title } ](${ stripPath ( group . path ) } .html )` ) ;
123
140
const section = group . section || [ ] ;
124
141
section . forEach ( item => {
125
142
tocPageLines . push ( `- [${ item . title } ](${ stripPath ( item . path ) } .html)` ) ;
@@ -150,13 +167,13 @@ function checkForMissingFilesAndFixFilenameCase() {
150
167
// Preferred filename for devsite should be capitalized and taken from
151
168
// toc.yaml.
152
169
const tocFilePath = `${ docPath } /${ filename } .html` ;
153
- // Generated filename from Typedoc will be lowercase.
154
- const generatedFilePath = `${ docPath } /${ filename . toLowerCase ( ) } .html` ;
170
+ // Generated filename from Typedoc will be lowercase and won't have the admin prefix .
171
+ const generatedFilePath = `${ docPath } /${ filename . toLowerCase ( ) . replace ( 'admin.' , '' ) } .html` ;
155
172
return fs . exists ( generatedFilePath ) . then ( exists => {
156
173
if ( exists ) {
157
174
// Store in a lookup table for link fixing.
158
175
lowerToUpperLookup [
159
- `${ filename . toLowerCase ( ) } .html`
176
+ `${ filename . toLowerCase ( ) . replace ( 'admin.' , '' ) } .html`
160
177
] = `${ filename } .html` ;
161
178
return fs . rename ( generatedFilePath , tocFilePath ) ;
162
179
} else {
@@ -167,6 +184,7 @@ function checkForMissingFilesAndFixFilenameCase() {
167
184
}
168
185
} ) ;
169
186
} ) ;
187
+
170
188
return Promise . all ( fileCheckPromises ) . then ( ( ) => filenames ) ;
171
189
}
172
190
@@ -253,15 +271,16 @@ function fixAllLinks(htmlFiles) {
253
271
* Updates the auto-generated Firestore API references page, by appending
254
272
* the specified HTML content block.
255
273
*
274
+ * @param {string } htmlPath Path of the HTML file to update.
256
275
* @param {string } contentBlock The HTML content block to be added to the Firestore docs.
257
276
*/
258
- function updateFirestoreHtml ( contentBlock ) {
259
- const dom = new jsdom . JSDOM ( fs . readFileSync ( firestoreHtmlPath ) ) ;
277
+ function updateHtml ( htmlPath , contentBlock ) {
278
+ const dom = new jsdom . JSDOM ( fs . readFileSync ( htmlPath ) ) ;
260
279
const contentNode = dom . window . document . body . querySelector ( '.col-12' ) ;
261
280
262
281
const newSection = new jsdom . JSDOM ( contentBlock ) ;
263
282
contentNode . appendChild ( newSection . window . document . body . firstChild ) ;
264
- fs . writeFileSync ( firestoreHtmlPath , dom . window . document . documentElement . outerHTML ) ;
283
+ fs . writeFileSync ( htmlPath , dom . window . document . documentElement . outerHTML ) ;
265
284
}
266
285
267
286
/**
@@ -272,7 +291,7 @@ function updateFirestoreHtml(contentBlock) {
272
291
*/
273
292
function addFirestoreTypeAliases ( ) {
274
293
return new Promise ( ( resolve , reject ) => {
275
- const fileStream = fs . createReadStream ( `${ repoPath } /src /index.d.ts` ) ;
294
+ const fileStream = fs . createReadStream ( `${ repoPath } /lib/firestore /index.d.ts` ) ;
276
295
fileStream . on ( 'error' , ( err ) => {
277
296
reject ( err ) ;
278
297
} ) ;
@@ -297,7 +316,49 @@ function addFirestoreTypeAliases() {
297
316
lineReader . on ( 'close' , ( ) => {
298
317
try {
299
318
contentBlock += firestoreFooter ;
300
- updateFirestoreHtml ( contentBlock ) ;
319
+ updateHtml ( firestoreHtmlPath , contentBlock ) ;
320
+ resolve ( ) ;
321
+ } catch ( err ) {
322
+ reject ( err ) ;
323
+ }
324
+ } ) ;
325
+ } ) ;
326
+ }
327
+
328
+ /**
329
+ * Adds RTDB type aliases to the auto-generated API docs. These are the
330
+ * types that are imported from the @firebase/database package, and
331
+ * then re-exported from the admin.database namespace. Typedoc currently
332
+ * does not handle these correctly, so we need this solution instead.
333
+ */
334
+ function addDatabaseTypeAliases ( ) {
335
+ return new Promise ( ( resolve , reject ) => {
336
+ const fileStream = fs . createReadStream ( `${ repoPath } /lib/database/index.d.ts` ) ;
337
+ fileStream . on ( 'error' , ( err ) => {
338
+ reject ( err ) ;
339
+ } ) ;
340
+ const lineReader = readline . createInterface ( {
341
+ input : fileStream ,
342
+ } ) ;
343
+
344
+ let contentBlock = databaseHeader ;
345
+ lineReader . on ( 'line' , ( line ) => {
346
+ line = line . trim ( ) ;
347
+ if ( line . startsWith ( 'export import' ) && line . indexOf ( 'rtdb.' ) >= 0 ) {
348
+ const typeName = line . split ( ' ' ) [ 2 ] ;
349
+ if ( databaseExcludes . indexOf ( typeName ) === - 1 ) {
350
+ contentBlock += `
351
+ <li>
352
+ <a href="/docs/reference/js/firebase.database.${ typeName } .html">${ typeName } </a>
353
+ </li>` ;
354
+ }
355
+ }
356
+ } ) ;
357
+
358
+ lineReader . on ( 'close' , ( ) => {
359
+ try {
360
+ contentBlock += databaseFooter ;
361
+ updateHtml ( databaseHtmlPath , contentBlock ) ;
301
362
resolve ( ) ;
302
363
} catch ( err ) {
303
364
reject ( err ) ;
@@ -349,6 +410,8 @@ Promise.all([
349
410
moveFilesToRoot ( 'enums' ) ,
350
411
] ) ;
351
412
} )
413
+ // Rename the globals file to be the top-level admin doc.
414
+ . then ( ( ) => fs . rename ( `${ docPath } /globals.html` , `${ docPath } /admin.html` ) )
352
415
// Check for files listed in TOC that are missing and warn if so.
353
416
// Not blocking.
354
417
. then ( checkForMissingFilesAndFixFilenameCase )
@@ -366,6 +429,7 @@ Promise.all([
366
429
// Add local variable include line to index.html (to access current SDK
367
430
// version number).
368
431
. then ( addFirestoreTypeAliases )
432
+ . then ( addDatabaseTypeAliases )
369
433
. then ( ( ) => {
370
434
fs . readFile ( `${ docPath } /index.html` , 'utf8' ) . then ( data => {
371
435
// String to include devsite local variables.
0 commit comments