cli-command.ts 684 B

123456789101112131415161718192021222324252627
  1. import { exec } from 'child_process'
  2. import { AbstractCommand } from '../shared'
  3. export class CLICommand extends AbstractCommand {
  4. static exec (command: string) {
  5. return new Promise<string>((res, rej) => {
  6. exec(command, (err, stdout, _stderr) => {
  7. if (err) return rej(err)
  8. return res(stdout)
  9. })
  10. })
  11. }
  12. getEnv () {
  13. return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}`
  14. }
  15. async execWithEnv (command: string, configOverride?: any) {
  16. const prefix = configOverride
  17. ? `NODE_CONFIG='${JSON.stringify(configOverride)}'`
  18. : ''
  19. return CLICommand.exec(`${prefix} ${this.getEnv()} ${command}`)
  20. }
  21. }