80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
import { readFileSync, 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',
|
|
);
|
|
|
|
const packageJsonPath = resolve(packageDir, 'package.json');
|
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
packageJson.version = '0.1.3';
|
|
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\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('main.dcdl', JSON.stringify({
|
|
'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.
|
|
`,
|
|
);
|
|
|
|
writeFileSync(
|
|
resolve(packageDir, 'jsr.json'),
|
|
JSON.stringify(
|
|
{
|
|
name: '@hare/decodal-wasm',
|
|
version: '0.1.3',
|
|
license: 'MIT',
|
|
exports: './mod.ts',
|
|
publish: {
|
|
include: [
|
|
'README.md',
|
|
'mod.ts',
|
|
'decodal_wasm.js',
|
|
'decodal_wasm.d.ts',
|
|
'decodal_wasm_bg.wasm',
|
|
'package.json',
|
|
],
|
|
},
|
|
},
|
|
null,
|
|
2,
|
|
) + '\n',
|
|
);
|