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);