Skip to content

Update api-documenter to work with new devsite changes #6449

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
merged 4 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions repo-scripts/api-documenter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @firebase/api-documenter

## 0.2.0
### Minor Changes

- [#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.
## 0.1.2
### Patch Changes

Expand Down
2 changes: 1 addition & 1 deletion repo-scripts/api-documenter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firebase/api-documenter",
"version": "0.1.2",
"version": "0.2.0",
"description": "Read JSON files from api-extractor, generate documentation pages",
"repository": {
"directory": "repo-scripts/documenter",
Expand Down
18 changes: 17 additions & 1 deletion repo-scripts/api-documenter/src/cli/BaseAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ export interface IBuildApiModelResult {
inputFolder: string;
outputFolder: string;
addFileNameSuffix: boolean;
projectName?: string;
}

export abstract class BaseAction extends CommandLineAction {
private _inputFolderParameter!: CommandLineStringParameter;
private _outputFolderParameter!: CommandLineStringParameter;
private _fileNameSuffixParameter!: CommandLineFlagParameter;
private _projectNameParameter!: CommandLineStringParameter;

protected onDefineParameters(): void {
// override
Expand Down Expand Up @@ -79,6 +81,14 @@ export abstract class BaseAction extends CommandLineAction {
`This is to avoid name conflict in case packageA also has, for example, an entry point with the same name in lowercase.` +
`This option is specifically designed for the Admin SDK where such case occurs.`
});

this._projectNameParameter = this.defineStringParameter({
parameterLongName: '--project',
argumentName: 'PROJECT',
description:
`Name of the project (js, admin, functions, etc.). This will be ` +
`used in the devsite header path to the _project.yaml file.`
});
}

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

this._applyInheritDoc(apiModel, apiModel);

return { apiModel, inputFolder, outputFolder, addFileNameSuffix };
return {
apiModel,
inputFolder,
outputFolder,
addFileNameSuffix,
projectName: this._projectNameParameter.value
};
}

// TODO: This is a temporary workaround. The long term plan is for API Extractor's DocCommentEnhancer
Expand Down
10 changes: 8 additions & 2 deletions repo-scripts/api-documenter/src/cli/MarkdownAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ export class MarkdownAction extends BaseAction {

protected async onExecute(): Promise<void> {
// override
const { apiModel, outputFolder, addFileNameSuffix } = this.buildApiModel();
const { apiModel, outputFolder, addFileNameSuffix, projectName } =
this.buildApiModel();

if (!projectName) {
throw new Error('No project name provided. Use --project.');
}

const markdownDocumenter: MarkdownDocumenter = new MarkdownDocumenter({
apiModel,
documenterConfig: undefined,
outputFolder,
addFileNameSuffix
addFileNameSuffix,
projectName
});
markdownDocumenter.generateFiles();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface IMarkdownDocumenterOptions {
documenterConfig: DocumenterConfig | undefined;
outputFolder: string;
addFileNameSuffix: boolean;
projectName: string;
}

/**
Expand All @@ -106,12 +107,14 @@ export class MarkdownDocumenter {
private readonly _outputFolder: string;
private readonly _pluginLoader: PluginLoader;
private readonly _addFileNameSuffix: boolean;
private readonly _projectName: string;

public constructor(options: IMarkdownDocumenterOptions) {
this._apiModel = options.apiModel;
this._documenterConfig = options.documenterConfig;
this._outputFolder = options.outputFolder;
this._addFileNameSuffix = options.addFileNameSuffix;
this._projectName = options.projectName;
this._tsdocConfiguration = CustomDocNodes.configuration;
this._markdownEmitter = new CustomMarkdownEmitter(this._apiModel);

Expand Down Expand Up @@ -165,12 +168,13 @@ export class MarkdownDocumenter {

// devsite headers
stringBuilder.append(
'{% extends "_internal/templates/reference.html" %}\n'
`Project: /docs/reference/${this._projectName}/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference
`
);
stringBuilder.append(
`{% block title %}${headingNode.title}{% endblock title %}\n`
);
stringBuilder.append('{% block body %}\n');

stringBuilder.append(`# ${headingNode.title}\n`);

this._markdownEmitter.emit(stringBuilder, output, {
contextApiItem: apiItem,
Expand All @@ -179,8 +183,6 @@ export class MarkdownDocumenter {
}
});

stringBuilder.append('{% endblock body %}\n');

let pageContent: string = stringBuilder.toString();

if (this._pluginLoader.markdownDocumenterFeature) {
Expand Down
19 changes: 16 additions & 3 deletions scripts/docgen/docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import * as yargs from 'yargs';
* Add to devsite files to alert anyone trying to make a documentation fix
* to the generated files.
*/
const GOOGLE3_HEADER = `{% comment %}
const GOOGLE3_HEADER = `
{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
Expand Down Expand Up @@ -110,7 +111,16 @@ async function generateDocs(forDevsite: boolean = false) {

await spawn(
'yarn',
[command, 'markdown', '--input', 'temp', '--output', outputFolder],
[
command,
'markdown',
'--input',
'temp',
'--output',
outputFolder,
'--project',
'js'
],
{ stdio: 'inherit' }
);

Expand All @@ -119,7 +129,10 @@ async function generateDocs(forDevsite: boolean = false) {
for (const mdFile of mdFiles) {
const fullPath = join(projectRoot, outputFolder, mdFile);
const content = fs.readFileSync(fullPath, 'utf-8');
fs.writeFileSync(fullPath, GOOGLE3_HEADER + content);
fs.writeFileSync(
fullPath,
content.replace('\n# ', `\n${GOOGLE3_HEADER}\n# `)
);
}
}

Expand Down