Files
openclaw/scripts/check-control-ui-precompressed-assets.mts
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

43 lines
1.5 KiB
TypeScript

#!/usr/bin/env node
// Verifies each generated Control UI sidecar encodes the final emitted asset bytes.
import fs from "node:fs";
import path from "node:path";
import { brotliDecompressSync, gunzipSync } from "node:zlib";
import { resolveRepoRoot } from "./lib/repo-root.mjs";
const repoRoot: string = resolveRepoRoot(import.meta.url);
const assetsDir = path.join(repoRoot, "dist", "control-ui", "assets");
const errors = [];
let checked = 0;
for (const entry of fs.readdirSync(assetsDir, { withFileTypes: true })) {
if (!entry.isFile()) {
continue;
}
const suffix = entry.name.endsWith(".br") ? ".br" : entry.name.endsWith(".gz") ? ".gz" : null;
if (!suffix) {
continue;
}
const sidecarPath = path.join(assetsDir, entry.name);
const sourcePath = sidecarPath.slice(0, -suffix.length);
try {
const encoded = fs.readFileSync(sidecarPath);
const decoded = suffix === ".br" ? brotliDecompressSync(encoded) : gunzipSync(encoded);
const source = fs.readFileSync(sourcePath);
if (!decoded.equals(source)) {
errors.push(`${entry.name}: decoded bytes differ from ${path.basename(sourcePath)}`);
}
} catch (error) {
errors.push(`${entry.name}: ${error instanceof Error ? error.message : String(error)}`);
}
checked += 1;
}
if (checked === 0) {
errors.push("no precompressed Control UI assets found");
}
if (errors.length > 0) {
throw new Error(`Control UI precompressed asset verification failed:\n${errors.join("\n")}`);
}
process.stdout.write(`verified ${checked} finalized Control UI sidecars\n`);