Skip to content

Commit

Permalink
Eagerly log output of regen-apis (#1910)
Browse files Browse the repository at this point in the history
The script is quite slow, so it's better to log the output eagerly so it
doesn't look like things hung.
  • Loading branch information
Eric-Arellano authored Sep 5, 2024
1 parent d47d34e commit 504d679
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions scripts/js/commands/api/regenerateApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ zxMain(async () => {
const args = readArgs();
await validateGitStatus();

const results = new Map<string, string[]>();
for (const pkgName of Pkg.VALID_NAMES) {
if (args.package && pkgName != args.package) {
continue;
Expand All @@ -67,22 +66,15 @@ zxMain(async () => {
);
const maybeDevVersion = await getDevVersion(pkgName);

const result = await processVersions(
await processVersions(
pkgName,
args.skipDownload,
historicalVersions,
currentVersion,
maybeDevVersion,
);
results.set(pkgName, result);
}

console.log("");
results.forEach((result: string[], pkgName: string) => {
console.log(`Regeneration of ${pkgName}:`);
result.forEach((msg) => console.error(msg));
console.log("");
});
await generateHistoricalRedirects();

console.log(`Each regenerated version has been saved as a distinct commit. If the changes are
Expand All @@ -96,37 +88,27 @@ async function processVersions(
historicalVersions: string[],
currentVersion: string,
maybeDevVersion: string | undefined,
): Promise<string[]> {
const results: string[] = [];

): Promise<void> {
for (const historicalVersion of historicalVersions) {
results.push(
await regenerateVersion(
pkgName,
historicalVersion,
skipDownload,
"historical",
),
await regenerateVersion(
pkgName,
historicalVersion,
skipDownload,
"historical",
);
}

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

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

return results;
}

async function regenerateVersion(
pkgName: string,
version: string,
skipDownload: boolean,
typeArgument?: "historical" | "dev",
): Promise<string> {
): Promise<void> {
const command = ["npm", "run", "gen-api", "--", "-p", pkgName, "-v", version];
if (typeArgument) {
command.push(`--${typeArgument}`);
Expand All @@ -139,13 +121,13 @@ async function regenerateVersion(
await $`${command}`;
if ((await gitStatus()) !== "") {
await gitCommit(`Regenerate ${pkgName} ${version}`);
return `✅ ${pkgName} ${version} regenerated correctly`;
console.log(`🚀 ${pkgName} ${version} regenerated correctly`);
} else {
return `☑️ ${pkgName} ${version} is up-to-date`;
console.log(`✅ ${pkgName} ${version} is already up-to-date`);
}
} catch (_) {
await gitRestore(".");
return `❌ ${pkgName} ${version} failed to regenerate`;
console.error(`❌ ${pkgName} ${version} failed to regenerate`);
}
}

Expand Down

0 comments on commit 504d679

Please sign in to comment.