forked from fugue/regula
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·35 lines (30 loc) · 1.03 KB
/
cli.js
File metadata and controls
executable file
·35 lines (30 loc) · 1.03 KB
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
33
34
35
#!/usr/bin/env node
import { WASI } from "wasi";
import { readFile } from "fs/promises";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const args = process.argv.slice(2);
// Note: preopens "/" is required because regula needs to read IaC files from
// any path the user specifies (including absolute paths like /home/user/terraform/).
// This is expected behavior for a CLI tool that processes user-specified file paths.
const wasi = new WASI({
version: "preview1",
args: ["regula", ...args],
env: process.env,
preopens: { "/": "/" },
returnOnExit: true,
});
try {
const wasmPath = join(__dirname, "regula.wasm");
const wasm = await readFile(wasmPath);
const { instance } = await WebAssembly.instantiate(wasm, wasi.getImportObject());
wasi.start(instance);
} catch (err) {
if (err.code === "ERR_WASI_EXITED") {
process.exit(err.exitCode);
}
console.error("Error:", err.message);
process.exit(1);
}