2022-07-01 11:52:39 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2022 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-10-28 06:49:28 +00:00
|
|
|
import {copyFile, readFile, rm, writeFile} from 'fs/promises';
|
2022-10-05 12:17:03 +00:00
|
|
|
import {join, resolve} from 'path';
|
|
|
|
import {chdir} from 'process';
|
2023-02-15 23:09:31 +00:00
|
|
|
|
2022-07-01 11:52:39 +00:00
|
|
|
import semver from 'semver';
|
2023-02-15 23:09:31 +00:00
|
|
|
|
2022-08-17 13:40:32 +00:00
|
|
|
import {generateDocs} from './internal/custom_markdown_action.js';
|
|
|
|
import {job} from './internal/job.js';
|
2022-08-31 12:42:53 +00:00
|
|
|
import {spawnAndLog} from './internal/util.js';
|
2022-07-01 11:52:39 +00:00
|
|
|
|
2022-10-05 12:17:03 +00:00
|
|
|
chdir(resolve(join(__dirname, '..')));
|
|
|
|
|
2022-07-01 11:52:39 +00:00
|
|
|
function getOffsetAndLimit(
|
|
|
|
sectionName: string,
|
|
|
|
lines: string[]
|
|
|
|
): [offset: number, limit: number] {
|
|
|
|
const offset =
|
|
|
|
lines.findIndex(line => {
|
|
|
|
return line.includes(`<!-- ${sectionName}-start -->`);
|
|
|
|
}) + 1;
|
|
|
|
const limit = lines.slice(offset).findIndex(line => {
|
|
|
|
return line.includes(`<!-- ${sectionName}-end -->`);
|
|
|
|
});
|
|
|
|
return [offset, limit];
|
|
|
|
}
|
|
|
|
|
|
|
|
function spliceIntoSection(
|
|
|
|
sectionName: string,
|
|
|
|
content: string,
|
|
|
|
sectionContent: string
|
|
|
|
): string {
|
|
|
|
const lines = content.split('\n');
|
|
|
|
const [offset, limit] = getOffsetAndLimit(sectionName, lines);
|
|
|
|
lines.splice(offset, limit, ...sectionContent.split('\n'));
|
|
|
|
return lines.join('\n');
|
|
|
|
}
|
|
|
|
|
2022-08-17 13:14:46 +00:00
|
|
|
(async () => {
|
2023-06-28 08:07:14 +00:00
|
|
|
const copyMain = job('Copy main page', async ({inputs, outputs}) => {
|
2022-10-28 06:49:28 +00:00
|
|
|
await copyFile(inputs[0]!, outputs[0]!);
|
2022-08-17 13:14:46 +00:00
|
|
|
})
|
|
|
|
.inputs(['README.md'])
|
|
|
|
.outputs(['docs/index.md'])
|
|
|
|
.build();
|
2022-07-01 11:52:39 +00:00
|
|
|
|
2022-08-17 13:14:46 +00:00
|
|
|
// Chrome Versions
|
2023-06-28 08:07:14 +00:00
|
|
|
const updateSupportedList = job(
|
|
|
|
'Update the Chrome supported list',
|
|
|
|
async ({inputs, outputs}) => {
|
|
|
|
let content = await readFile(inputs[2]!, {encoding: 'utf8'});
|
|
|
|
const versionModulePath = join('..', inputs[0]!);
|
|
|
|
const {versionsPerRelease} = await import(versionModulePath);
|
|
|
|
const versionsArchived = JSON.parse(await readFile(inputs[1]!, 'utf8'));
|
|
|
|
|
|
|
|
// Generate versions
|
|
|
|
const buffer: string[] = [];
|
|
|
|
for (const [chromiumVersion, puppeteerVersion] of versionsPerRelease) {
|
|
|
|
if (puppeteerVersion === 'NEXT') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (versionsArchived.includes(puppeteerVersion.substring(1))) {
|
|
|
|
if (semver.gte(puppeteerVersion, '20.0.0')) {
|
|
|
|
buffer.push(
|
|
|
|
` * [Chrome for Testing](https://goo.gle/chrome-for-testing) ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://pptr.dev/${puppeteerVersion.slice(
|
|
|
|
1
|
|
|
|
)})`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
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')) {
|
2023-05-02 06:53:40 +00:00
|
|
|
buffer.push(
|
2023-06-28 08:07:14 +00:00
|
|
|
` * Chromium ${chromiumVersion} - [Puppeteer ${puppeteerVersion}](https://pptr.dev/${puppeteerVersion.slice(
|
2023-05-02 06:53:40 +00:00
|
|
|
1
|
|
|
|
)})`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
buffer.push(
|
2023-06-28 08:07:14 +00:00
|
|
|
` * Chromium ${chromiumVersion} - Puppeteer ${puppeteerVersion}`
|
2023-05-02 06:53:40 +00:00
|
|
|
);
|
|
|
|
}
|
2022-08-17 13:14:46 +00:00
|
|
|
}
|
2023-06-28 08:07:14 +00:00
|
|
|
content = spliceIntoSection('version', content, buffer.join('\n'));
|
2022-07-01 11:52:39 +00:00
|
|
|
|
2023-06-28 08:07:14 +00:00
|
|
|
await writeFile(outputs[0]!, content);
|
|
|
|
}
|
|
|
|
)
|
2022-08-31 12:42:53 +00:00
|
|
|
.inputs([
|
|
|
|
'versions.js',
|
|
|
|
'website/versionsArchived.json',
|
|
|
|
'docs/chromium-support.md',
|
|
|
|
])
|
2022-08-17 13:14:46 +00:00
|
|
|
.outputs(['docs/chromium-support.md'])
|
|
|
|
.build();
|
2022-07-01 11:52:39 +00:00
|
|
|
|
2023-06-28 08:07:14 +00:00
|
|
|
const copyNgSchematics = job(
|
|
|
|
'Copy @puppeteer/ng-schematics main page',
|
|
|
|
async ({inputs, outputs}) => {
|
|
|
|
await copyFile(inputs[0]!, outputs[0]!);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.inputs(['packages/ng-schematics/README.md'])
|
|
|
|
.outputs(['docs/ng-schematics.md'])
|
|
|
|
.build();
|
|
|
|
|
|
|
|
await Promise.all([copyMain, updateSupportedList, copyNgSchematics]);
|
2022-08-31 12:42:53 +00:00
|
|
|
|
2022-08-17 13:14:46 +00:00
|
|
|
// Generate documentation
|
2023-06-28 08:07:14 +00:00
|
|
|
const puppeteerDocs = job(
|
|
|
|
'Generate Puppeteer API markdown',
|
|
|
|
async ({inputs, outputs}) => {
|
|
|
|
await rm(outputs[0]!, {recursive: true, force: true});
|
|
|
|
generateDocs(inputs[0]!, outputs[0]!);
|
|
|
|
spawnAndLog('prettier', '--ignore-path', 'none', '--write', 'docs');
|
|
|
|
}
|
|
|
|
)
|
2022-10-24 07:07:05 +00:00
|
|
|
.inputs([
|
|
|
|
'docs/puppeteer.api.json',
|
|
|
|
'tools/internal/custom_markdown_documenter.ts',
|
|
|
|
])
|
2022-08-17 13:14:46 +00:00
|
|
|
.outputs(['docs/api'])
|
|
|
|
.build();
|
2023-04-06 12:23:10 +00:00
|
|
|
|
2023-06-28 08:07:14 +00:00
|
|
|
const browsersDocs = job(
|
|
|
|
'Generate @puppeteer/browsers API markdown',
|
|
|
|
async ({inputs, outputs}) => {
|
|
|
|
await rm(outputs[0]!, {recursive: true, force: true});
|
|
|
|
generateDocs(inputs[0]!, outputs[0]!);
|
|
|
|
spawnAndLog('prettier', '--ignore-path', 'none', '--write', 'docs');
|
|
|
|
}
|
|
|
|
)
|
2023-04-06 12:23:10 +00:00
|
|
|
.inputs([
|
|
|
|
'docs/browsers.api.json',
|
|
|
|
'tools/internal/custom_markdown_documenter.ts',
|
|
|
|
])
|
|
|
|
.outputs(['docs/browsers-api'])
|
|
|
|
.build();
|
2023-04-11 12:47:25 +00:00
|
|
|
|
2023-04-26 09:53:02 +00:00
|
|
|
await Promise.all([puppeteerDocs, browsersDocs]);
|
|
|
|
|
2023-06-28 08:07:14 +00:00
|
|
|
await job(
|
|
|
|
'Update main @puppeteer/browsers page',
|
|
|
|
async ({inputs, outputs}) => {
|
|
|
|
const readme = await readFile(inputs[1]!, 'utf-8');
|
|
|
|
const index = await readFile(inputs[0]!, 'utf-8');
|
|
|
|
await writeFile(outputs[0]!, index.replace('# API Reference\n', readme));
|
|
|
|
}
|
|
|
|
)
|
2023-04-11 12:47:25 +00:00
|
|
|
.inputs(['docs/browsers-api/index.md', 'packages/browsers/README.md'])
|
|
|
|
.outputs(['docs/browsers-api/index.md'])
|
|
|
|
.build();
|
2022-08-17 13:14:46 +00:00
|
|
|
})();
|