Viewing is open to everyone. Downloading and starring need a GitHub sign-in. Sign in with GitHub

assemble.mjs

v0.1.0-build.85 Latest Commit ede38f5

Size
1.7 KB
Lines
36
Language
javascript
SHA-256
1d5fb996e2b6…
View on GitHub

Sign in with GitHub to download. Each download is recorded with your GitHub username.

1// Assembles dist/ from an Emscripten build directory:
2// ckey-core.mjs Emscripten glue (patched to load ckey.wasm)
3// ckey.wasm the core
4// ckey.mjs, api.mjs, options.mjs, payload.mjs, scanner.mjs, telemetry.mjs
5// ckey.d.ts copied from types/ckey.d.ts
6// Usage: node scripts/assemble.mjs <emscripten build dir>
7import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
8import { dirname, join, resolve } from 'node:path';
9import { fileURLToPath } from 'node:url';
10
11const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
12const build = resolve(process.argv[2] ?? join(root, 'build/wasm'));
13const dist = join(root, 'dist');
14mkdirSync(dist, { recursive: true });
15
16const glue = join(build, 'ckey-core.mjs');
17const wasm = join(build, 'ckey-core.wasm');
18for (const f of [glue, wasm]) {
19 if (!existsSync(f)) {
20 console.error(`missing ${f}; run the Emscripten build first (scripts/build.sh)`);
21 process.exit(1);
22 }
23}
24// The glue names its binary after the build target; the package ships it as
25// ckey.wasm (the name the openckey.org page and loadCKey expect).
26const src = readFileSync(glue, 'utf8');
27const patched = src.replaceAll('ckey-core.wasm', 'ckey.wasm');
28if (patched === src) console.warn('warning: ckey-core.wasm not referenced by the glue; loadCKey passes locateFile anyway');
29writeFileSync(join(dist, 'ckey-core.mjs'), patched);
30copyFileSync(wasm, join(dist, 'ckey.wasm'));
31
32for (const f of readdirSync(join(root, 'js'))) {
33 if (f.endsWith('.mjs')) copyFileSync(join(root, 'js', f), join(dist, f));
34}
35copyFileSync(join(root, 'types/ckey.d.ts'), join(dist, 'ckey.d.ts'));
36console.log(`assembled ${dist}`);