fix(striker-ui-api): consolidate system calls into shell module

main
Tsu-ba-me 3 years ago
parent bb02d556d4
commit 90c3004e90
  1. 18
      striker-ui-api/src/lib/mkfifo.ts
  2. 28
      striker-ui-api/src/lib/shell.ts

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

@ -0,0 +1,28 @@
import { spawnSync } from 'child_process';
import SERVER_PATHS from './consts/SERVER_PATHS';
const systemCall = (
...[command, args = [], options = {}]: Parameters<typeof spawnSync>
) => {
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);
Loading…
Cancel
Save