1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Introduce CLI command

This commit is contained in:
Chocobozzz 2021-07-05 16:37:50 +02:00
parent a6a79eae0d
commit 329619b345
No known key found for this signature in database
GPG key ID: 583A612D890159BE
16 changed files with 94 additions and 138 deletions

View file

@ -1,24 +1,27 @@
import { exec } from 'child_process'
import { AbstractCommand } from '../shared'
import { ServerInfo } from '../server/servers'
class CLICommand extends AbstractCommand {
function getEnvCli (server?: ServerInfo) {
return `NODE_ENV=test NODE_APP_INSTANCE=${server.internalServerNumber}`
}
static exec (command: string) {
return new Promise<string>((res, rej) => {
exec(command, (err, stdout, _stderr) => {
if (err) return rej(err)
async function execCLI (command: string) {
return new Promise<string>((res, rej) => {
exec(command, (err, stdout, stderr) => {
if (err) return rej(err)
return res(stdout)
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 {
execCLI,
getEnvCli
CLICommand
}