Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the regen-apis command to regenerate dev versions #788

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions scripts/commands/regenerateApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { readFile, readdir } from "fs/promises";
import yargs from "yargs/yargs";
import { hideBin } from "yargs/helpers";
import { $ } from "zx";
import fs from "fs";

import { Pkg } from "../lib/api/Pkg";
import { zxMain } from "../lib/zx";
import { pathExists } from "../lib/fs";

interface Arguments {
[x: string]: unknown;
Expand Down Expand Up @@ -54,14 +54,17 @@ zxMain(async () => {
continue;
}

const [historicalVersions, currentVersion] = await getPackageVersions(
const [historicalVersions, currentVersion] = await getReleasedVersions(
pkgName,
args.currentApisOnly,
);
const devVersion = await getDevVersion(pkgName);
arnaucasau marked this conversation as resolved.
Show resolved Hide resolved

const result = await processVersions(
pkgName,
historicalVersions,
currentVersion,
devVersion,
);
results.set(pkgName, result);
}
Expand All @@ -82,24 +85,33 @@ async function processVersions(
pkgName: string,
historicalVersions: string[],
currentVersion: string,
devVersion: string | undefined,
): Promise<string[]> {
const results: string[] = [];

for (const historicalVersion of historicalVersions) {
results.push(await regenerateVersion(pkgName, historicalVersion));
results.push(
await regenerateVersion(pkgName, historicalVersion, "historical"),
);
}

results.push(await regenerateVersion(pkgName, currentVersion));

if (devVersion) {
results.push(await regenerateVersion(pkgName, devVersion, "dev"));
}
results.push(await regenerateVersion(pkgName, currentVersion, false));

return results;
}

async function regenerateVersion(
pkgName: string,
version: string,
historical: boolean = true,
typeArgument?: "historical" | "dev",
): Promise<string> {
try {
if (historical) {
await $`npm run gen-api -- -p ${pkgName} -v ${version} --historical`;
if (typeArgument) {
await $`npm run gen-api -- -p ${pkgName} -v ${version} --${typeArgument}`;
} else {
await $`npm run gen-api -- -p ${pkgName} -v ${version}`;
}
Expand All @@ -116,7 +128,18 @@ async function regenerateVersion(
}
}

async function getPackageVersions(
async function getDevVersion(pkgName: string): Promise<string | undefined> {
const devPath = `docs/api/${pkgName}/dev`;

if (await pathExists(devPath)) {
return JSON.parse(await readFile(`${devPath}/_package.json`, "utf-8"))
.version;
}

return undefined;
}

async function getReleasedVersions(
pkgName: string,
currentApisOnly: boolean,
): Promise<[string[], string]> {
Expand Down
Loading