aboutsummaryrefslogblamecommitdiffhomepage
path: root/shared/server-commands/cli/cli-command.ts
blob: ab9738174f2ee3aaf3663e1aa1f6edfd5bfcec68 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                    
                                           
 
                                                 
 



                                               
 

                          
      
   
 



                                                                                





                                                                   

   
import { exec } from 'child_process'
import { AbstractCommand } from '../shared'

export 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, configOverride?: any) {
    const prefix = configOverride
      ? `NODE_CONFIG='${JSON.stringify(configOverride)}'`
      : ''

    return CLICommand.exec(`${prefix} ${this.getEnv()} ${command}`)
  }
}