-
Notifications
You must be signed in to change notification settings - Fork 218
Fix toc.yaml for V2 reference docs #1097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4651241
Add custom script for generating toc for v2 refs.
taeold a26178f
Fix bug where path for section was wrong.
taeold e144f1f
Update path for v2 beta reference docs.
taeold fdeca3f
Add comment that this script is a fork of @firebase/api-documenter.
taeold 2e121c9
Format.
taeold 37e1a75
Revamp toc to include section for all generated docs.
taeold c10c400
Merge branch 'master' into dl-v2-toc
taeold 023a7e3
Don't output empty sections.
taeold fa9acfb
Merge remote-tracking branch 'origin/dl-v2-toc' into dl-v2-toc
taeold 106698f
Add experimental status, shorten title.
taeold bc527fd
Format.
taeold a7c65e9
Merge branch 'master' into dl-v2-toc
taeold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Forked of https://github.com/firebase/firebase-js-sdk/blob/5ce06766303b92fea969c58172a7c1ab8695e21e/repo-scripts/api-documenter/src/toc.ts. | ||
| */ | ||
| import { writeFileSync } from 'fs'; | ||
| import { resolve } from 'path'; | ||
|
|
||
| import yargs from 'yargs'; | ||
| import * as yaml from 'js-yaml'; | ||
| import { FileSystem } from '@rushstack/node-core-library'; | ||
|
|
||
| export interface TocGenerationOptions { | ||
| inputFolder: string; | ||
| outputFolder: string; | ||
| g3Path: string; | ||
| } | ||
|
|
||
| interface TocItem { | ||
| title: string; | ||
| path: string; | ||
| section?: TocItem[]; | ||
| status?: 'experimental'; | ||
| } | ||
|
|
||
| function fileExt(f: string) { | ||
| const parts = f.split('.'); | ||
| if (parts.length < 2) { | ||
| return ''; | ||
| } | ||
| return parts.pop(); | ||
| } | ||
|
|
||
| export function generateToc({ | ||
| inputFolder, | ||
| g3Path, | ||
| outputFolder, | ||
| }: TocGenerationOptions) { | ||
| const asObj = FileSystem.readFolder(inputFolder) | ||
| .filter((f) => fileExt(f) === 'md') | ||
| .reduce((acc, f) => { | ||
| const parts = f.split('.'); | ||
| parts.pop(); // Get rid of file extenion (.md) | ||
|
|
||
| let cursor = acc; | ||
| for (const p of parts) { | ||
| cursor[p] = cursor[p] || {}; | ||
| cursor = cursor[p]; | ||
| } | ||
| return acc; | ||
| }, {} as any); | ||
|
|
||
| function toToc(obj, prefix = ''): TocItem[] { | ||
| const toc: TocItem[] = []; | ||
| for (const key of Object.keys(obj)) { | ||
| const path = prefix?.length ? `${prefix}.${key}` : key; | ||
| const section = toToc(obj[key], path); | ||
| const tic: TocItem = { | ||
| title: key, | ||
| path: `${g3Path}/${path}.md`, | ||
| }; | ||
| if (section.length > 0) { | ||
| tic.section = section; | ||
| } | ||
| toc.push(tic); | ||
| } | ||
| return toc; | ||
| } | ||
|
|
||
| const toc: TocItem[] = [ | ||
| { | ||
| title: 'firebase-functions', | ||
| status: 'experimental', | ||
| path: `${g3Path}/firebase-functions.md`, | ||
| }, | ||
| ...toToc(asObj['firebase-functions'], 'firebase-functions'), | ||
| ]; | ||
|
|
||
| writeFileSync( | ||
| resolve(outputFolder, 'toc.yaml'), | ||
| yaml.dump( | ||
| { toc }, | ||
| { | ||
| quotingType: '"', | ||
| } | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| const { input, output, path } = yargs(process.argv.slice(2)) | ||
| .option('input', { | ||
| alias: 'i', | ||
| describe: 'input folder containing the *.api.json files to be processed.', | ||
| default: './input', | ||
| }) | ||
| .option('output', { | ||
| alias: 'o', | ||
| describe: 'destination for the generated toc content.', | ||
| default: './toc', | ||
| }) | ||
| .option('path', { | ||
| alias: 'p', | ||
| describe: 'specifies the path where the reference docs resides (e.g. g3)', | ||
| default: '/', | ||
| }) | ||
| .help().argv; | ||
|
|
||
| FileSystem.ensureFolder(output); | ||
| generateToc({ inputFolder: input, g3Path: path, outputFolder: output }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.