Skip to content

Commit c7d706b

Browse files
committed
Add script to copy screenshots to help site
1 parent 62c1124 commit c7d706b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env -S deno run --allow-read --allow-write
2+
3+
import { ScreenshotContext } from "./presets.ts";
4+
5+
const runLogDir = Deno.args[0];
6+
const helpRepo = Deno.args[1];
7+
8+
if (runLogDir == null || helpRepo == null) {
9+
console.error("Usage: ./update_help_site_screenshots.mts <run_log_dir> <help_repo>");
10+
Deno.exit(1);
11+
}
12+
13+
const runLog = JSON.parse(await Deno.readTextFile(`${runLogDir}/run_log.json`));
14+
if (!(await Deno.stat(helpRepo)).isDirectory) {
15+
console.error(`Help repo "${helpRepo}" is not a directory`);
16+
Deno.exit(1);
17+
}
18+
19+
const pageNameToFileName = {
20+
localized_page_sign_up: "1786056439.png",
21+
localized_auth0_sign_up_with_pt: "1624359167.png",
22+
localized_pt_registry_login: "448045579.png"
23+
};
24+
25+
function getDirForLocale(localeCode: string): string {
26+
return localeCode === "en"
27+
? `${helpRepo}/docs`
28+
: `${helpRepo}/i18n/${localeCode}/docusaurus-plugin-content-docs/current`;
29+
}
30+
31+
for (const screenshot of runLog.screenshotEvents) {
32+
const context: ScreenshotContext = screenshot.context;
33+
const pageName = context.pageName;
34+
const localeCode = context.locale;
35+
if (pageName == null || localeCode == null) {
36+
console.error("Screenshot context is missing pageName or locale:", JSON.stringify(context));
37+
continue;
38+
}
39+
40+
if (pageName in pageNameToFileName) {
41+
const currentFile = `${runLogDir}/${screenshot.fileName}`;
42+
const newFile = `${getDirForLocale(localeCode)}/${pageNameToFileName[pageName as keyof typeof pageNameToFileName]}`;
43+
console.log(`Moving ${currentFile} to ${newFile}`);
44+
await Deno.copyFile(currentFile, newFile);
45+
}
46+
}

0 commit comments

Comments
 (0)