Skip to content

Commit e4eda86

Browse files
authored
Update api-documenter to work with new devsite changes (#6449)
1 parent 1a15c7d commit e4eda86

File tree

6 files changed

+55
-14
lines changed

6 files changed

+55
-14
lines changed

repo-scripts/api-documenter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# @firebase/api-documenter
22

3+
## 0.2.0
4+
### Minor Changes
5+
6+
- [#6449](https://github.com/firebase/firebase-js-sdk/pull/6449) Updates to work with devsite changes. Added a required `--project` flag for generating markdown docs.
37
## 0.1.2
48
### Patch Changes
59

repo-scripts/api-documenter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@firebase/api-documenter",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"description": "Read JSON files from api-extractor, generate documentation pages",
55
"repository": {
66
"directory": "repo-scripts/documenter",

repo-scripts/api-documenter/src/cli/BaseAction.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ export interface IBuildApiModelResult {
4141
inputFolder: string;
4242
outputFolder: string;
4343
addFileNameSuffix: boolean;
44+
projectName?: string;
4445
}
4546

4647
export abstract class BaseAction extends CommandLineAction {
4748
private _inputFolderParameter!: CommandLineStringParameter;
4849
private _outputFolderParameter!: CommandLineStringParameter;
4950
private _fileNameSuffixParameter!: CommandLineFlagParameter;
51+
private _projectNameParameter!: CommandLineStringParameter;
5052

5153
protected onDefineParameters(): void {
5254
// override
@@ -79,6 +81,14 @@ export abstract class BaseAction extends CommandLineAction {
7981
`This is to avoid name conflict in case packageA also has, for example, an entry point with the same name in lowercase.` +
8082
`This option is specifically designed for the Admin SDK where such case occurs.`
8183
});
84+
85+
this._projectNameParameter = this.defineStringParameter({
86+
parameterLongName: '--project',
87+
argumentName: 'PROJECT',
88+
description:
89+
`Name of the project (js, admin, functions, etc.). This will be ` +
90+
`used in the devsite header path to the _project.yaml file.`
91+
});
8292
}
8393

8494
protected buildApiModel(): IBuildApiModelResult {
@@ -105,7 +115,13 @@ export abstract class BaseAction extends CommandLineAction {
105115

106116
this._applyInheritDoc(apiModel, apiModel);
107117

108-
return { apiModel, inputFolder, outputFolder, addFileNameSuffix };
118+
return {
119+
apiModel,
120+
inputFolder,
121+
outputFolder,
122+
addFileNameSuffix,
123+
projectName: this._projectNameParameter.value
124+
};
109125
}
110126

111127
// TODO: This is a temporary workaround. The long term plan is for API Extractor's DocCommentEnhancer

repo-scripts/api-documenter/src/cli/MarkdownAction.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ export class MarkdownAction extends BaseAction {
3535

3636
protected async onExecute(): Promise<void> {
3737
// override
38-
const { apiModel, outputFolder, addFileNameSuffix } = this.buildApiModel();
38+
const { apiModel, outputFolder, addFileNameSuffix, projectName } =
39+
this.buildApiModel();
40+
41+
if (!projectName) {
42+
throw new Error('No project name provided. Use --project.');
43+
}
3944

4045
const markdownDocumenter: MarkdownDocumenter = new MarkdownDocumenter({
4146
apiModel,
4247
documenterConfig: undefined,
4348
outputFolder,
44-
addFileNameSuffix
49+
addFileNameSuffix,
50+
projectName
4551
});
4652
markdownDocumenter.generateFiles();
4753
}

repo-scripts/api-documenter/src/documenters/MarkdownDocumenter.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface IMarkdownDocumenterOptions {
9292
documenterConfig: DocumenterConfig | undefined;
9393
outputFolder: string;
9494
addFileNameSuffix: boolean;
95+
projectName: string;
9596
}
9697

9798
/**
@@ -106,12 +107,14 @@ export class MarkdownDocumenter {
106107
private readonly _outputFolder: string;
107108
private readonly _pluginLoader: PluginLoader;
108109
private readonly _addFileNameSuffix: boolean;
110+
private readonly _projectName: string;
109111

110112
public constructor(options: IMarkdownDocumenterOptions) {
111113
this._apiModel = options.apiModel;
112114
this._documenterConfig = options.documenterConfig;
113115
this._outputFolder = options.outputFolder;
114116
this._addFileNameSuffix = options.addFileNameSuffix;
117+
this._projectName = options.projectName;
115118
this._tsdocConfiguration = CustomDocNodes.configuration;
116119
this._markdownEmitter = new CustomMarkdownEmitter(this._apiModel);
117120

@@ -165,12 +168,13 @@ export class MarkdownDocumenter {
165168

166169
// devsite headers
167170
stringBuilder.append(
168-
'{% extends "_internal/templates/reference.html" %}\n'
171+
`Project: /docs/reference/${this._projectName}/_project.yaml
172+
Book: /docs/reference/_book.yaml
173+
page_type: reference
174+
`
169175
);
170-
stringBuilder.append(
171-
`{% block title %}${headingNode.title}{% endblock title %}\n`
172-
);
173-
stringBuilder.append('{% block body %}\n');
176+
177+
stringBuilder.append(`# ${headingNode.title}\n`);
174178

175179
this._markdownEmitter.emit(stringBuilder, output, {
176180
contextApiItem: apiItem,
@@ -179,8 +183,6 @@ export class MarkdownDocumenter {
179183
}
180184
});
181185

182-
stringBuilder.append('{% endblock body %}\n');
183-
184186
let pageContent: string = stringBuilder.toString();
185187

186188
if (this._pluginLoader.markdownDocumenterFeature) {

scripts/docgen/docgen.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import * as yargs from 'yargs';
2727
* Add to devsite files to alert anyone trying to make a documentation fix
2828
* to the generated files.
2929
*/
30-
const GOOGLE3_HEADER = `{% comment %}
30+
const GOOGLE3_HEADER = `
31+
{% comment %}
3132
DO NOT EDIT THIS FILE!
3233
This is generated by the JS SDK team, and any local changes will be
3334
overwritten. Changes should be made in the source code at
@@ -110,7 +111,16 @@ async function generateDocs(forDevsite: boolean = false) {
110111

111112
await spawn(
112113
'yarn',
113-
[command, 'markdown', '--input', 'temp', '--output', outputFolder],
114+
[
115+
command,
116+
'markdown',
117+
'--input',
118+
'temp',
119+
'--output',
120+
outputFolder,
121+
'--project',
122+
'js'
123+
],
114124
{ stdio: 'inherit' }
115125
);
116126

@@ -119,7 +129,10 @@ async function generateDocs(forDevsite: boolean = false) {
119129
for (const mdFile of mdFiles) {
120130
const fullPath = join(projectRoot, outputFolder, mdFile);
121131
const content = fs.readFileSync(fullPath, 'utf-8');
122-
fs.writeFileSync(fullPath, GOOGLE3_HEADER + content);
132+
fs.writeFileSync(
133+
fullPath,
134+
content.replace('\n# ', `\n${GOOGLE3_HEADER}\n# `)
135+
);
123136
}
124137
}
125138

0 commit comments

Comments
 (0)