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 sidebar_position: 1
--- ---
# Puppeteer # Puppeteer

View File

@ -14,13 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
import {readFileSync, writeFileSync} from 'fs'; import {readFile, writeFile} from 'fs/promises';
import {join} from 'path'; import rimraf from 'rimraf';
import {chdir} from 'process';
import semver from 'semver'; import semver from 'semver';
import {versionsPerRelease} from '../versions.js';
import versionsArchived from '../website/versionsArchived.json';
import {generateDocs} from './internal/custom_markdown_action'; import {generateDocs} from './internal/custom_markdown_action';
import {job} from './internal/job';
function getOffsetAndLimit( function getOffsetAndLimit(
sectionName: string, sectionName: string,
@ -47,56 +45,66 @@ function spliceIntoSection(
return lines.join('\n'); return lines.join('\n');
} }
// Change to root directory (async () => {
chdir(join(__dirname, '..')); job('', async ({inputs, outputs}) => {
const content = await readFile(inputs[0]!, 'utf-8');
const sectionContent = `
---
sidebar_position: 1
---
`;
await writeFile(outputs[0]!, sectionContent + content);
})
.inputs(['README.md'])
.outputs(['docs/index.md'])
.build();
// README // Chrome Versions
{ job('', async ({inputs, outputs}) => {
const content = readFileSync('README.md', 'utf-8'); let content = await readFile(outputs[0]!, {encoding: 'utf8'});
const sectionContent = ` const {versionsPerRelease} = await import(inputs[0]!);
--- const versionsArchived = JSON.parse(await readFile(inputs[1]!, 'utf8'));
sidebar_position: 1
---
`; // Generate versions
writeFileSync('docs/index.md', sectionContent + content); const buffer: string[] = [];
} for (const [chromiumVersion, puppeteerVersion] of versionsPerRelease) {
if (puppeteerVersion === 'NEXT') {
// Chrome Versions continue;
{ }
const filename = 'docs/chromium-support.md'; if (versionsArchived.includes(puppeteerVersion.substring(1))) {
let content = readFileSync(filename, {encoding: 'utf8'}); buffer.push(
` * Chromium ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://github.com/puppeteer/puppeteer/blob/${puppeteerVersion}/docs/api/index.md)`
// Generate versions );
const buffer: string[] = []; } else if (semver.lt(puppeteerVersion, '15.0.0')) {
for (const [chromiumVersion, puppeteerVersion] of versionsPerRelease) { buffer.push(
if (puppeteerVersion === 'NEXT') { ` * Chromium ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://github.com/puppeteer/puppeteer/blob/${puppeteerVersion}/docs/api.md)`
continue; );
} else if (semver.gte(puppeteerVersion, '15.3.0')) {
buffer.push(
` * Chromium ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://pptr.dev/${puppeteerVersion.slice(
1
)})`
);
} else {
buffer.push(
` * Chromium ${chromiumVersion} - Puppeteer ${puppeteerVersion}`
);
}
} }
if (versionsArchived.includes(puppeteerVersion.substring(1))) { content = spliceIntoSection('version', content, buffer.join('\n'));
buffer.push(
` * Chromium ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://github.com/puppeteer/puppeteer/blob/${puppeteerVersion}/docs/api/index.md)`
);
} else if (semver.lt(puppeteerVersion, '15.0.0')) {
buffer.push(
` * Chromium ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://github.com/puppeteer/puppeteer/blob/${puppeteerVersion}/docs/api.md)`
);
} else if (semver.gte(puppeteerVersion, '15.3.0')) {
buffer.push(
` * Chromium ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://pptr.dev/${puppeteerVersion.slice(
1
)})`
);
} else {
buffer.push(
` * Chromium ${chromiumVersion} - Puppeteer ${puppeteerVersion}`
);
}
}
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 // 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'; import {ApiModel} from '@microsoft/api-extractor-model';
// eslint-disable-next-line import/extensions
import {MarkdownDocumenter} from './custom_markdown_documenter'; import {MarkdownDocumenter} from './custom_markdown_documenter';
export const generateDocs = (jsonPath: string, outputDir: string): void => { export const generateDocs = (jsonPath: string, outputDir: string): void => {