1
1
/**
2
2
* @license
3
- * Copyright 2020 Google LLC
3
+ * Copyright 2021 Google LLC
4
4
*
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
15
15
* limitations under the License.
16
16
*/
17
17
18
- const yaml = require ( 'js-yaml' ) ;
19
- const fs = require ( 'fs' ) ;
18
+ import * as yargs from 'yargs' ;
19
+ import * as fs from 'fs' ;
20
+ import * as path from 'path' ;
21
+ import * as yaml from 'js-yaml' ;
22
+
23
+ interface TocItem {
24
+ title : string ;
25
+ path : string ;
26
+ section ?: TocItem [ ] ;
27
+ }
28
+
29
+ const argv = yargs
30
+ . options ( {
31
+ input : {
32
+ alias : 'i' ,
33
+ type : 'string' ,
34
+ default : 'temp'
35
+ }
36
+ } )
37
+ . help ( ) . argv ;
20
38
21
39
const REF_DOC_DIR = '/docs/reference/js' ;
22
- const REPORT_DIR = './temp' ;
40
+ const REPORT_DIR = path . resolve ( process . cwd ( ) , argv . input ) ;
23
41
24
- const js = {
42
+ const js : TocItem = {
25
43
title : 'firebase' ,
26
44
path : `${ REF_DOC_DIR } /index` ,
27
45
section : [ ]
@@ -38,7 +56,7 @@ for (const fileName of fs.readdirSync(REPORT_DIR)) {
38
56
const entryPointName = entryPoint . canonicalReference
39
57
. replace ( '!' , '' )
40
58
. replace ( '@firebase/' , '' ) ;
41
- const entryPointToc = {
59
+ const entryPointToc : Required < TocItem > = {
42
60
title : entryPointName ,
43
61
path : `${ REF_DOC_DIR } /${ getFileName (
44
62
entryPoint ,
@@ -75,7 +93,11 @@ console.log(
75
93
)
76
94
) ;
77
95
78
- function getFileName ( apiMember , entryPoint , multipleEntryPoints = false ) {
96
+ function getFileName (
97
+ apiMember : any ,
98
+ entryPoint : any ,
99
+ multipleEntryPoints = false
100
+ ) {
79
101
const entryPointName = entryPoint . canonicalReference . replace ( '!' , '' ) ;
80
102
const unscopedName = getUnscopedName ( entryPointName ) ;
81
103
let entryPointPrefix = unscopedName ;
@@ -102,7 +124,7 @@ function getFileName(apiMember, entryPoint, multipleEntryPoints = false) {
102
124
}
103
125
}
104
126
105
- function getUnscopedName ( packageName ) {
127
+ function getUnscopedName ( packageName : string ) {
106
128
const parts = packageName . split ( '/' ) ;
107
129
if ( parts . length === 1 ) {
108
130
return packageName ;
0 commit comments