PeerTube/shared/extra-utils/cli/cli-command.ts

28 lines
684 B
TypeScript
Raw Normal View History

2017-09-07 08:27:35 -05:00
import { exec } from 'child_process'
2021-07-05 09:37:50 -05:00
import { AbstractCommand } from '../shared'
2017-09-07 08:27:35 -05:00
2021-07-06 02:55:05 -05:00
export class CLICommand extends AbstractCommand {
2017-09-07 08:27:35 -05:00
2021-07-05 09:37:50 -05:00
static exec (command: string) {
return new Promise<string>((res, rej) => {
exec(command, (err, stdout, _stderr) => {
if (err) return rej(err)
2017-09-07 08:27:35 -05:00
2021-07-05 09:37:50 -05:00
return res(stdout)
})
2017-09-07 08:27:35 -05:00
})
2021-07-05 09:37:50 -05:00
}
2017-09-07 08:27:35 -05:00
2021-07-05 09:37:50 -05:00
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}`)
2021-07-05 09:37:50 -05:00
}
}