-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mjs
executable file
·32 lines (23 loc) · 897 Bytes
/
build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
/* eslint-env node */
import { readdir } from "node:fs/promises";
import { exec as exec_ } from "node:child_process";
const LOG_WAT_FILE_NAME = true;
// const COMMAND = `npx wat-wasm {WAT}`;
const COMMAND = `wabt/build/wat2wasm --debug-names {WAT}`;
export const exec = (cmd, opts = {}) =>
new Promise((resolve, reject) => {
if (!opts.cwd) opts.cwd = process.cwd();
exec_(cmd, opts, (err, stdout, _stderr) => {
if (err && !opts.ignoreExitCode) return reject(err);
resolve(stdout);
});
});
const [_, __, ...args] = process.argv;
const watFileArg = args[0];
const watFiles = watFileArg ? [watFileArg] : (await readdir('.')).filter(s => s.includes('.wat'));
for (let wat of watFiles) {
if (LOG_WAT_FILE_NAME) console.log(`** ${wat} **`);
const out = (await exec(COMMAND.replace('{WAT}', wat)));
if (out.trim()) console.log(out);
}