Files
zip-js/scripts/build-examples.mjs
zeekay a86165b198 feat: hello + validate-email + policy-eval examples
Three end-to-end examples mirroring zip-rs:
 - hello       — minimal name → greeting handler (1.5 KB built)
 - validate-email — port of the canonical validate fixture, byte-equivalent
                    JSON output to base/plugins/extbench/fixtures/goja-js (1.9 KB)
 - policy-eval — realistic IAM/gateway authz decision handler (2.0 KB)

Built JS is committed so test harnesses + downstream consumers don't
depend on the toolchain. scripts/build-example.mjs is the monorepo
build driver (aliases @hanzo/zip to the local dist); end users use
the published npx zip-js build instead.

scripts/verify-examples.mjs loads each built bundle into a fresh V8
context and asserts byte-for-byte JSON output matches the canonical
reference strings — the same shape extbench compares.
2026-05-18 22:04:15 -07:00

45 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
/**
* Build every example in `examples/`.
*/
import { promises as fs } from "node:fs";
import path from "node:path";
import url from "node:url";
import { spawn } from "node:child_process";
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const examplesDir = path.resolve(__dirname, "..", "examples");
const buildOne = path.resolve(__dirname, "build-example.mjs");
async function listExamples() {
const entries = await fs.readdir(examplesDir, { withFileTypes: true });
const out = [];
for (const e of entries) {
if (!e.isDirectory()) continue;
const full = path.join(examplesDir, e.name);
try {
await fs.access(path.join(full, "extension.json"));
out.push(full);
} catch {
// Not an example dir.
}
}
out.sort();
return out;
}
function run(cmd, args) {
return new Promise((resolve, reject) => {
const p = spawn(cmd, args, { stdio: "inherit" });
p.on("error", reject);
p.on("exit", (code) => (code === 0 ? resolve() : reject(new Error(`exit ${code}`))));
});
}
const examples = await listExamples();
for (const dir of examples) {
await run(process.execPath, [buildOne, dir]);
}