summaryrefslogtreecommitdiff
path: root/utils/run.ts
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2025-05-10 16:57:03 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2025-05-10 16:57:03 -0700
commitfa8f3f9465e87d499f7d6428323f496a884b7818 (patch)
treeab477dfa52ef30282029c4f136bf605cb24d67a9 /utils/run.ts
downloadci-fa8f3f9465e87d499f7d6428323f496a884b7818.tar.gz
ci-fa8f3f9465e87d499f7d6428323f496a884b7818.zip
initial commit
Diffstat (limited to 'utils/run.ts')
-rw-r--r--utils/run.ts21
1 files changed, 21 insertions, 0 deletions
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<string> => {
+ 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;
+};