34 lines
858 B
TypeScript
34 lines
858 B
TypeScript
import {
|
|
args,
|
|
execCommandShell,
|
|
exit,
|
|
fetchFileWithCache,
|
|
log,
|
|
} from "https://script.hatter.ink/@50/deno-commons-mod.ts";
|
|
|
|
// JQ WASM URL:
|
|
// https://cdn.hatter.ink/doc/8998_BE8D1CBE6106C77968183F226E2129B5/jq.wasm
|
|
|
|
async function execWasm(
|
|
wasmCommand: string,
|
|
wasmUrl: string,
|
|
wasmArgs?: string[],
|
|
): never {
|
|
const wasmCacheFileMeta = await fetchFileWithCache(wasmUrl);
|
|
const wasmCommandArgs: string[] = [wasmCacheFileMeta.cache_full_path, "--"];
|
|
if (wasmArgs) {
|
|
wasmCommandArgs.push(...wasmArgs);
|
|
}
|
|
log.debug(wasmCommandArgs);
|
|
exit(await execCommandShell(wasmCommand, wasmCommandArgs));
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
// TODO not works? why?
|
|
await execWasm(
|
|
"wasmer",
|
|
"https://cdn.hatter.ink/doc/8998_BE8D1CBE6106C77968183F226E2129B5/jq.wasm",
|
|
args(),
|
|
);
|
|
}
|