chore: use jobs for document generation (#8802)

This commit is contained in:
jrandolf 2022-08-17 15:14:46 +02:00 committed by GitHub
parent bdcb748b98
commit 03c1814e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 57 deletions

View File

@ -1,7 +1,5 @@
---
sidebar_position: 1
---
# Puppeteer

View File

@ -14,13 +14,11 @@
* limitations under the License.
*/
import {readFileSync, writeFileSync} from 'fs';
import {join} from 'path';
import {chdir} from 'process';
import {readFile, writeFile} from 'fs/promises';
import rimraf from 'rimraf';
import semver from 'semver';
import {versionsPerRelease} from '../versions.js';
import versionsArchived from '../website/versionsArchived.json';
import {generateDocs} from './internal/custom_markdown_action';
import {job} from './internal/job';
function getOffsetAndLimit(
sectionName: string,
@ -47,25 +45,25 @@ function spliceIntoSection(
return lines.join('\n');
}
// Change to root directory
chdir(join(__dirname, '..'));
// README
{
const content = readFileSync('README.md', 'utf-8');
(async () => {
job('', async ({inputs, outputs}) => {
const content = await readFile(inputs[0]!, 'utf-8');
const sectionContent = `
---
sidebar_position: 1
---
`;
writeFileSync('docs/index.md', sectionContent + content);
}
await writeFile(outputs[0]!, sectionContent + content);
})
.inputs(['README.md'])
.outputs(['docs/index.md'])
.build();
// Chrome Versions
{
const filename = 'docs/chromium-support.md';
let content = readFileSync(filename, {encoding: 'utf8'});
job('', async ({inputs, outputs}) => {
let content = await readFile(outputs[0]!, {encoding: 'utf8'});
const {versionsPerRelease} = await import(inputs[0]!);
const versionsArchived = JSON.parse(await readFile(inputs[1]!, 'utf8'));
// Generate versions
const buffer: string[] = [];
@ -95,8 +93,18 @@ chdir(join(__dirname, '..'));
}
content = spliceIntoSection('version', content, buffer.join('\n'));
writeFileSync(filename, content);
}
await writeFile(outputs[0]!, content);
})
.inputs(['versions.js', 'website/versionsArchived.json'])
.outputs(['docs/chromium-support.md'])
.build();
// Generate documentation
generateDocs('docs/puppeteer.api.json', 'docs/api');
job('', async ({inputs, outputs}) => {
rimraf.sync(outputs[0]!);
generateDocs(inputs[0]!, outputs[0]!);
})
.inputs(['docs/puppeteer.api.json'])
.outputs(['docs/api'])
.build();
})();

View File

@ -15,8 +15,6 @@
*/
import {ApiModel} from '@microsoft/api-extractor-model';
// eslint-disable-next-line import/extensions
import {MarkdownDocumenter} from './custom_markdown_documenter';
export const generateDocs = (jsonPath: string, outputDir: string): void => {