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,25 +45,25 @@ 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');
// README
{
const content = readFileSync('README.md', 'utf-8');
const sectionContent = ` const sectionContent = `
--- ---
sidebar_position: 1 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 // Chrome Versions
{ job('', async ({inputs, outputs}) => {
const filename = 'docs/chromium-support.md'; let content = await readFile(outputs[0]!, {encoding: 'utf8'});
let content = readFileSync(filename, {encoding: 'utf8'}); const {versionsPerRelease} = await import(inputs[0]!);
const versionsArchived = JSON.parse(await readFile(inputs[1]!, 'utf8'));
// Generate versions // Generate versions
const buffer: string[] = []; const buffer: string[] = [];
@ -95,8 +93,18 @@ chdir(join(__dirname, '..'));
} }
content = spliceIntoSection('version', content, buffer.join('\n')); 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 => {