aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/cli/cli.ts
blob: 1bf100869017c19b9bf8cc398f622d8f425603ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { exec } from 'child_process'
import { AbstractCommand } from '../shared'

class CLICommand extends AbstractCommand {

  static exec (command: string) {
    return new Promise<string>((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) {
    return CLICommand.exec(`${this.getEnv()} ${command}`)
  }
}

export {
  CLICommand
}