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
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> |
| 7 | import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; |
| 8 | import { dirname, join, resolve } from 'node:path'; |
| 9 | import { fileURLToPath } from 'node:url'; |
| 10 | |
| 11 | const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); |
| 12 | const build = resolve(process.argv[2] ?? join(root, 'build/wasm')); |
| 13 | const dist = join(root, 'dist'); |
| 14 | mkdirSync(dist, { recursive: true }); |
| 15 | |
| 16 | const glue = join(build, 'ckey-core.mjs'); |
| 17 | const wasm = join(build, 'ckey-core.wasm'); |
| 18 | for (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). |
| 26 | const src = readFileSync(glue, 'utf8'); |
| 27 | const patched = src.replaceAll('ckey-core.wasm', 'ckey.wasm'); |
| 28 | if (patched === src) console.warn('warning: ckey-core.wasm not referenced by the glue; loadCKey passes locateFile anyway'); |
| 29 | writeFileSync(join(dist, 'ckey-core.mjs'), patched); |
| 30 | copyFileSync(wasm, join(dist, 'ckey.wasm')); |
| 31 | |
| 32 | for (const f of readdirSync(join(root, 'js'))) { |
| 33 | if (f.endsWith('.mjs')) copyFileSync(join(root, 'js', f), join(dist, f)); |
| 34 | } |
| 35 | copyFileSync(join(root, 'types/ckey.d.ts'), join(dist, 'ckey.d.ts')); |
| 36 | console.log(`assembled ${dist}`); |