puppeteer/tools/docgen/src/docgen.ts

39 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-07-01 11:52:39 +00:00
/**
2024-01-03 10:11:33 +00:00
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
2022-07-01 11:52:39 +00:00
*/
import {ApiModel} from '@microsoft/api-extractor-model';
2022-08-17 13:40:32 +00:00
import {MarkdownDocumenter} from './custom_markdown_documenter.js';
2022-07-01 11:52:39 +00:00
2023-10-12 13:04:29 +00:00
export function docgen(jsonPath: string, outputDir: string): void {
2022-07-01 11:52:39 +00:00
const apiModel = new ApiModel();
apiModel.loadPackage(jsonPath);
const markdownDocumenter: MarkdownDocumenter = new MarkdownDocumenter({
apiModel: apiModel,
documenterConfig: undefined,
outputFolder: outputDir,
});
markdownDocumenter.generateFiles();
2023-10-12 13:04:29 +00:00
}
export function spliceIntoSection(
sectionName: string,
content: string,
sectionContent: string
): string {
const lines = content.split('\n');
const offset =
lines.findIndex(line => {
return line.includes(`<!-- ${sectionName}-start -->`);
}) + 1;
const limit = lines.slice(offset).findIndex(line => {
return line.includes(`<!-- ${sectionName}-end -->`);
});
lines.splice(offset, limit, ...sectionContent.split('\n'));
return lines.join('\n');
}