You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.2 KiB
27 lines
1.2 KiB
#!/usr/bin/env node
|
|
// Writes the ZIP samples of the page (src/lib/dkc/testing/zip.ts), as the
|
|
// ZipSink of src/lib/inspector/zipsink.ts writes them, into a directory for
|
|
// scripts/zip-go-read.go, and prints their index as JSON: the name, the file
|
|
// and the SHA-256 of each. The samples are deterministic: zipsink.test.ts
|
|
// writes them again and requires the same SHA-256. Node runs the TypeScript
|
|
// sources directly (type stripping, Node 22.6+):
|
|
//
|
|
// node scripts/zip-ts-samples.mjs DIR > zip-samples.json
|
|
|
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { sha256, toHex } from '../src/lib/dkc/bytes.ts';
|
|
import { writeZip, zipSamples } from '../src/lib/dkc/testing/zip.ts';
|
|
|
|
const dir = process.argv[2];
|
|
if (dir === undefined) throw new Error('usage: node scripts/zip-ts-samples.mjs DIR');
|
|
mkdirSync(dir, { recursive: true });
|
|
const samples = [];
|
|
for (const [i, s] of zipSamples().entries()) {
|
|
const { bytes } = await writeZip(s);
|
|
const file = `${i}.zip`;
|
|
writeFileSync(join(dir, file), bytes);
|
|
samples.push({ name: s.name, file, sha256: toHex(await sha256(bytes)) });
|
|
}
|
|
process.stdout.write(`${JSON.stringify({ generator: 'scripts/zip-ts-samples.mjs', samples }, null, 1)}\n`);
|