From fa8f3f9465e87d499f7d6428323f496a884b7818 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Sat, 10 May 2025 16:57:03 -0700 Subject: initial commit --- utils/run.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 utils/run.ts (limited to 'utils/run.ts') diff --git a/utils/run.ts b/utils/run.ts new file mode 100644 index 0000000..f3ce3d3 --- /dev/null +++ b/utils/run.ts @@ -0,0 +1,21 @@ +export const getStdout = async ( + cmd: string[] | string, + options: Deno.CommandOptions = {}, +): Promise => { + const [exec, ...args] = (typeof cmd === "string") ? cmd.split(" ") : cmd; + const command = new Deno.Command(exec, { + args, + stdout: "piped", + stderr: "piped", + ...options, + }); + + const { code, stdout, stderr } = await command.output(); + + const stdoutText = new TextDecoder().decode(stdout); + const stderrText = new TextDecoder().decode(stderr); + + if (code !== 0) throw new Error(`Command failed: ${cmd}\n${stderrText}`); + + return stdoutText; +}; -- cgit v1.2.3-70-g09d2