Skip to content

Commit bb223f8

Browse files
committed
create devsite toc
1 parent 8d5e558 commit bb223f8

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"docgen:exp": "ts-node-script scripts/exp/docgen.ts",
5555
"postinstall": "yarn --cwd repo-scripts/changelog-generator build",
5656
"sa": "ts-node-script repo-scripts/size-analysis/cli.ts",
57-
"api-documenter-devsite": "ts-node-script repo-scripts/api-documenter/src/start.ts"
57+
"api-documenter-devsite": "ts-node-script repo-scripts/api-documenter/src/start.ts",
58+
"toc-devsite": "ts-node-script scripts/exp/generate-devsite-toc.ts -i temp"
5859
},
5960
"repository": {
6061
"type": "git",
@@ -87,6 +88,7 @@
8788
"@types/sinon-chai": "3.2.5",
8889
"@types/tmp": "0.2.0",
8990
"@types/yargs": "16.0.0",
91+
"@types/js-yaml": "4.0.0",
9092
"@typescript-eslint/eslint-plugin": "4.11.1",
9193
"@typescript-eslint/eslint-plugin-tslint": "4.11.1",
9294
"@typescript-eslint/parser": "4.11.1",

generate-devsite-toc.js renamed to scripts/exp/generate-devsite-toc.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2020 Google LLC
3+
* Copyright 2021 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -15,13 +15,31 @@
1515
* limitations under the License.
1616
*/
1717

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;
2038

2139
const REF_DOC_DIR = '/docs/reference/js';
22-
const REPORT_DIR = './temp';
40+
const REPORT_DIR = path.resolve(process.cwd(), argv.input);
2341

24-
const js = {
42+
const js: TocItem = {
2543
title: 'firebase',
2644
path: `${REF_DOC_DIR}/index`,
2745
section: []
@@ -38,7 +56,7 @@ for (const fileName of fs.readdirSync(REPORT_DIR)) {
3856
const entryPointName = entryPoint.canonicalReference
3957
.replace('!', '')
4058
.replace('@firebase/', '');
41-
const entryPointToc = {
59+
const entryPointToc: Required<TocItem> = {
4260
title: entryPointName,
4361
path: `${REF_DOC_DIR}/${getFileName(
4462
entryPoint,
@@ -75,7 +93,11 @@ console.log(
7593
)
7694
);
7795

78-
function getFileName(apiMember, entryPoint, multipleEntryPoints = false) {
96+
function getFileName(
97+
apiMember: any,
98+
entryPoint: any,
99+
multipleEntryPoints = false
100+
) {
79101
const entryPointName = entryPoint.canonicalReference.replace('!', '');
80102
const unscopedName = getUnscopedName(entryPointName);
81103
let entryPointPrefix = unscopedName;
@@ -102,7 +124,7 @@ function getFileName(apiMember, entryPoint, multipleEntryPoints = false) {
102124
}
103125
}
104126

105-
function getUnscopedName(packageName) {
127+
function getUnscopedName(packageName: string) {
106128
const parts = packageName.split('/');
107129
if (parts.length === 1) {
108130
return packageName;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,11 @@
27142714
dependencies:
27152715
"@types/istanbul-lib-report" "*"
27162716

2717+
2718+
version "4.0.0"
2719+
resolved "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.0.tgz#d1a11688112091f2c711674df3a65ea2f47b5dfb"
2720+
integrity sha512-4vlpCM5KPCL5CfGmTbpjwVKbISRYhduEJvvUWsH5EB7QInhEj94XPZ3ts/9FPiLZFqYO0xoW4ZL8z2AabTGgJA==
2721+
27172722
"@types/json-schema@*", "@types/json-schema@^7.0.3", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
27182723
version "7.0.7"
27192724
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"

0 commit comments

Comments
 (0)