From f3942fd750aacf91cea810603ef5fd3c260c9539 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Mon, 17 Jun 2024 20:08:40 +0800 Subject: [PATCH] cli: init --- cli.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 cli.ts diff --git a/cli.ts b/cli.ts new file mode 100644 index 0000000..9f40712 --- /dev/null +++ b/cli.ts @@ -0,0 +1,18 @@ +import { SpawnSyncOptionsWithBufferEncoding, SpawnSyncReturns, spawnSync as rawSpawnSync } from "child_process"; + +export function check(result: SpawnSyncReturns) { + if (result.error) + throw result.error; + if (result.status !== 0) { + throw result.stderr; + } + return result; +} + +export function checkedSpawnSync( + command: string, + args: readonly string[], + options: SpawnSyncOptionsWithBufferEncoding, +): SpawnSyncReturns { + return check(rawSpawnSync(command, args, options)); +}