vice city online: the bare online core
This commit is contained in:
commit
2f98475c19
256 changed files with 144219 additions and 0 deletions
40
tools/stage-site.ts
Normal file
40
tools/stage-site.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Builds build/site: the web build at / and exactly the game files the manifest lists at /data/,
|
||||
// under lower-case names (the browser asks for lower-case paths, a Linux server is case-sensitive).
|
||||
// Usage: bun tools/stage-site.ts <dist dir> <game dir> [out dir]
|
||||
import { join, dirname } from "node:path";
|
||||
import { readdirSync, mkdirSync, copyFileSync, existsSync, statSync, rmSync, cpSync } from "node:fs";
|
||||
|
||||
const [dist, gameDir, out = "build/site"] = process.argv.slice(2);
|
||||
if (!dist || !gameDir) throw new Error("usage: bun tools/stage-site.ts <dist dir> <game dir> [out dir]");
|
||||
|
||||
function resolveCase(root: string, rel: string): string | null {
|
||||
let dir = root;
|
||||
for (const part of rel.split("/").filter(Boolean)) {
|
||||
const hit = readdirSync(dir).find((n) => n.toLowerCase() === part.toLowerCase());
|
||||
if (!hit) return null;
|
||||
dir = join(dir, hit);
|
||||
}
|
||||
return existsSync(dir) && statSync(dir).isFile() ? dir : null;
|
||||
}
|
||||
|
||||
rmSync(out, { recursive: true, force: true });
|
||||
cpSync(dist, out, { recursive: true });
|
||||
|
||||
const manifestPath = join(gameDir, "manifest.json");
|
||||
const manifest = await Bun.file(manifestPath).json();
|
||||
mkdirSync(join(out, "data"), { recursive: true });
|
||||
copyFileSync(manifestPath, join(out, "data", "manifest.json"));
|
||||
copyFileSync(join(gameDir, "eager.bin"), join(out, "data", "eager.bin"));
|
||||
|
||||
let bytes = 0, count = 0, missing: string[] = [];
|
||||
for (const f of [...manifest.files, ...manifest.ranged] as { path: string }[]) {
|
||||
const src = resolveCase(gameDir, f.path);
|
||||
if (!src) { missing.push(f.path); continue; }
|
||||
const dst = join(out, "data", f.path.toLowerCase());
|
||||
mkdirSync(dirname(dst), { recursive: true });
|
||||
copyFileSync(src, dst);
|
||||
bytes += statSync(dst).size;
|
||||
count++;
|
||||
}
|
||||
console.log(`${count} files, ${(bytes / 1048576).toFixed(0)} MB staged in ${out}`);
|
||||
if (missing.length) { console.error("missing:", missing.slice(0, 10)); process.exit(1); }
|
||||
Loading…
Add table
Add a link
Reference in a new issue