58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const fs = require("fs/promises");
|
|
const path = require("path");
|
|
const { spawnSync } = require("child_process");
|
|
|
|
const ROOT = process.cwd();
|
|
const HTML_DUMPS_DIR = path.join(ROOT, "html-dumps");
|
|
const EXPORTS_DIR = path.join(ROOT, "html-dumps-optimized");
|
|
const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx";
|
|
|
|
async function removeExportsDir(): Promise<void> {
|
|
await fs.rm(EXPORTS_DIR, { recursive: true, force: true });
|
|
}
|
|
|
|
function runStep(
|
|
cmd: string,
|
|
args: string[],
|
|
options: { cwd?: string } = {}
|
|
): void {
|
|
const result = spawnSync(cmd, args, { stdio: "inherit", ...options });
|
|
if (result.status !== 0) {
|
|
throw new Error(
|
|
cmd + " " + args.join(" ") + " failed with code " + result.status
|
|
);
|
|
}
|
|
}
|
|
|
|
async function processWorkflows(): Promise<void> {
|
|
await removeExportsDir();
|
|
|
|
runStep(npxCmd, ["tsx", "scripts/dom-export/exportHtmlDumps.ts"]);
|
|
|
|
const entries = await fs.readdir(HTML_DUMPS_DIR, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
if (!entry.isDirectory()) continue;
|
|
|
|
const exportWorkflowDir = path.join(EXPORTS_DIR, entry.name);
|
|
try {
|
|
await fs.access(exportWorkflowDir);
|
|
} catch {
|
|
continue;
|
|
}
|
|
|
|
runStep(npxCmd, [
|
|
"tsx",
|
|
"scripts/dom-export/buildDomDiffs.ts",
|
|
exportWorkflowDir,
|
|
]);
|
|
}
|
|
}
|
|
|
|
processWorkflows().catch((err: unknown) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|
|
|
|
export {}; |