Decodal/site/decodal-site/scripts/prepare-wasm-package.mjs

54 lines
1.2 KiB
JavaScript

import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
const packageDir = resolve(import.meta.dirname, '../../../packages/decodal-wasm');
writeFileSync(
resolve(packageDir, '.gitignore'),
'# wasm-pack output is committed for the browser runtime package.\n',
);
writeFileSync(
resolve(packageDir, 'README.md'),
`# decodal-wasm
WebAssembly runtime package for Decodal.
This package exposes the Decodal evaluator to browsers and other JavaScript runtimes that can load WebAssembly modules.
It is generated from the Rust crate in \`crates/decodal-wasm\` with \`wasm-pack\` and is used by the official playground.
Use \`decodal-codemirror\` separately when you need CodeMirror 6 language support.
## Install
\`\`\`sh
npm install decodal-wasm
\`\`\`
JSR:
\`\`\`sh
deno add jsr:@hare/decodal-wasm
\`\`\`
## Usage
\`\`\`js
import init, { evaluateProject } from 'decodal-wasm';
await init();
const result = evaluateProject(JSON.stringify({
entry: 'main.dcdl',
files: {
'main.dcdl': 'Server = { port = Int default 8080; };',
},
}));
console.log(JSON.parse(result));
\`\`\`
The exported functions return JSON strings so callers can handle diagnostics and successful results without depending on Rust data structures.
`,
);