]>
Commit | Line | Data |
---|---|---|
fdbda9e3 | 1 | import { exec } from 'child_process' |
329619b3 | 2 | import { AbstractCommand } from '../shared' |
fdbda9e3 | 3 | |
e8bd7ce7 | 4 | export class CLICommand extends AbstractCommand { |
fdbda9e3 | 5 | |
329619b3 C |
6 | static exec (command: string) { |
7 | return new Promise<string>((res, rej) => { | |
8 | exec(command, (err, stdout, _stderr) => { | |
9 | if (err) return rej(err) | |
fdbda9e3 | 10 | |
329619b3 C |
11 | return res(stdout) |
12 | }) | |
fdbda9e3 | 13 | }) |
329619b3 | 14 | } |
fdbda9e3 | 15 | |
329619b3 C |
16 | getEnv () { |
17 | return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}` | |
18 | } | |
19 | ||
e1ab52d7 | 20 | async execWithEnv (command: string, configOverride?: any) { |
21 | const prefix = configOverride | |
22 | ? `NODE_CONFIG='${JSON.stringify(configOverride)}'` | |
23 | : '' | |
24 | ||
25 | return CLICommand.exec(`${prefix} ${this.getEnv()} ${command}`) | |
329619b3 C |
26 | } |
27 | } |