From 90c3004e905975294a3d6e82ab7e97d690d29bff Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 22 Jun 2022 16:45:00 -0400 Subject: [PATCH] fix(striker-ui-api): consolidate system calls into shell module --- striker-ui-api/src/lib/mkfifo.ts | 18 ------------------ striker-ui-api/src/lib/shell.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 18 deletions(-) delete mode 100644 striker-ui-api/src/lib/mkfifo.ts create mode 100644 striker-ui-api/src/lib/shell.ts diff --git a/striker-ui-api/src/lib/mkfifo.ts b/striker-ui-api/src/lib/mkfifo.ts deleted file mode 100644 index 0f5b0a1d..00000000 --- a/striker-ui-api/src/lib/mkfifo.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { spawnSync } from 'child_process'; - -import SERVER_PATHS from './consts/SERVER_PATHS'; - -export const mkfifo = (...args: string[]) => { - const { error, stderr } = spawnSync(SERVER_PATHS.usr.bin.mkfifo.self, args, { - encoding: 'utf-8', - timeout: 3000, - }); - - if (error) { - throw error; - } - - if (stderr) { - throw new Error(stderr); - } -}; diff --git a/striker-ui-api/src/lib/shell.ts b/striker-ui-api/src/lib/shell.ts new file mode 100644 index 00000000..5ffdd9ed --- /dev/null +++ b/striker-ui-api/src/lib/shell.ts @@ -0,0 +1,28 @@ +import { spawnSync } from 'child_process'; + +import SERVER_PATHS from './consts/SERVER_PATHS'; + +const systemCall = ( + ...[command, args = [], options = {}]: Parameters +) => { + const { error, stderr, stdout } = spawnSync(command, args, { + ...options, + encoding: 'utf-8', + }); + + if (error) { + throw error; + } + + if (stderr) { + throw new Error(stderr); + } + + return stdout; +}; + +export const mkfifo = (...args: string[]) => + systemCall(SERVER_PATHS.usr.bin.mkfifo.self, args); + +export const rm = (...args: string[]) => + systemCall(SERVER_PATHS.usr.bin.rm.self, args);