From bf54587a3e2ad9c2c186828f2a5682b91ee2cc00 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 17 Dec 2021 09:29:23 +0100 Subject: shared/ typescript types dir server-commands --- shared/server-commands/cli/cli-command.ts | 27 +++++++++++++++++++++++++++ shared/server-commands/cli/index.ts | 1 + 2 files changed, 28 insertions(+) create mode 100644 shared/server-commands/cli/cli-command.ts create mode 100644 shared/server-commands/cli/index.ts (limited to 'shared/server-commands/cli') diff --git a/shared/server-commands/cli/cli-command.ts b/shared/server-commands/cli/cli-command.ts new file mode 100644 index 000000000..ab9738174 --- /dev/null +++ b/shared/server-commands/cli/cli-command.ts @@ -0,0 +1,27 @@ +import { exec } from 'child_process' +import { AbstractCommand } from '../shared' + +export class CLICommand extends AbstractCommand { + + static exec (command: string) { + return new Promise((res, rej) => { + exec(command, (err, stdout, _stderr) => { + if (err) return rej(err) + + return res(stdout) + }) + }) + } + + getEnv () { + return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}` + } + + async execWithEnv (command: string, configOverride?: any) { + const prefix = configOverride + ? `NODE_CONFIG='${JSON.stringify(configOverride)}'` + : '' + + return CLICommand.exec(`${prefix} ${this.getEnv()} ${command}`) + } +} diff --git a/shared/server-commands/cli/index.ts b/shared/server-commands/cli/index.ts new file mode 100644 index 000000000..91b5abfbe --- /dev/null +++ b/shared/server-commands/cli/index.ts @@ -0,0 +1 @@ +export * from './cli-command' -- cgit v1.2.3