Skip to content

Commit 4a021bd

Browse files
authored
Merge cbf1beb into 1703bb3
2 parents 1703bb3 + cbf1beb commit 4a021bd

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

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

Lines changed: 11 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,7 @@ export abstract class BaseAction extends CommandLineAction {
105115

106116
this._applyInheritDoc(apiModel, apiModel);
107117

108-
return { apiModel, inputFolder, outputFolder, addFileNameSuffix };
118+
return { apiModel, inputFolder, outputFolder, addFileNameSuffix, projectName: this._projectNameParameter.value };
109119
}
110120

111121
// 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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ 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 } = this.buildApiModel();
39+
40+
if (!projectName) {
41+
throw new Error('No project name provided. Use --project.');
42+
}
3943

4044
const markdownDocumenter: MarkdownDocumenter = new MarkdownDocumenter({
4145
apiModel,
4246
documenterConfig: undefined,
4347
outputFolder,
44-
addFileNameSuffix
48+
addFileNameSuffix,
49+
projectName
4550
});
4651
markdownDocumenter.generateFiles();
4752
}

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

Lines changed: 11 additions & 9 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,14 @@ export class MarkdownDocumenter {
165168

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

175180
this._markdownEmitter.emit(stringBuilder, output, {
176181
contextApiItem: apiItem,
@@ -179,8 +184,6 @@ export class MarkdownDocumenter {
179184
}
180185
});
181186

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

186189
if (this._pluginLoader.markdownDocumenterFeature) {
@@ -253,9 +256,8 @@ export class MarkdownDocumenter {
253256
output.push(
254257
new DocHeading({
255258
configuration,
256-
title: `${packageName}${
257-
apiItem.displayName && '/' + apiItem.displayName
258-
}`
259+
title: `${packageName}${apiItem.displayName && '/' + apiItem.displayName
260+
}`
259261
})
260262
);
261263
break;

scripts/docgen/docgen.ts

Lines changed: 4 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,7 @@ async function generateDocs(forDevsite: boolean = false) {
110111

111112
await spawn(
112113
'yarn',
113-
[command, 'markdown', '--input', 'temp', '--output', outputFolder],
114+
[command, 'markdown', '--input', 'temp', '--output', outputFolder, '--project', 'js'],
114115
{ stdio: 'inherit' }
115116
);
116117

@@ -119,7 +120,7 @@ async function generateDocs(forDevsite: boolean = false) {
119120
for (const mdFile of mdFiles) {
120121
const fullPath = join(projectRoot, outputFolder, mdFile);
121122
const content = fs.readFileSync(fullPath, 'utf-8');
122-
fs.writeFileSync(fullPath, GOOGLE3_HEADER + content);
123+
fs.writeFileSync(fullPath, content.replace('\n# ', `\n${GOOGLE3_HEADER}\n# `));
123124
}
124125
}
125126

0 commit comments

Comments
 (0)