diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-17 09:29:23 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-17 09:29:23 +0100 |
commit | bf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (patch) | |
tree | 54b40aaf01bae210632473285c3c7571d51e4f89 /shared/server-commands/cli/cli-command.ts | |
parent | 6b5f72beda96d8b7e4d6329c4001827334de27dd (diff) | |
download | PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.gz PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.zst PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.zip |
shared/ typescript types dir server-commands
Diffstat (limited to 'shared/server-commands/cli/cli-command.ts')
-rw-r--r-- | shared/server-commands/cli/cli-command.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/shared/server-commands/cli/cli-command.ts b/shared/server-commands/cli/cli-command.ts new file mode 100644 index 000000000..ab9738174 --- /dev/null +++ b/shared/server-commands/cli/cli-command.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import { exec } from 'child_process' | ||
2 | import { AbstractCommand } from '../shared' | ||
3 | |||
4 | export class CLICommand extends AbstractCommand { | ||
5 | |||
6 | static exec (command: string) { | ||
7 | return new Promise<string>((res, rej) => { | ||
8 | exec(command, (err, stdout, _stderr) => { | ||
9 | if (err) return rej(err) | ||
10 | |||
11 | return res(stdout) | ||
12 | }) | ||
13 | }) | ||
14 | } | ||
15 | |||
16 | getEnv () { | ||
17 | return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}` | ||
18 | } | ||
19 | |||
20 | async execWithEnv (command: string, configOverride?: any) { | ||
21 | const prefix = configOverride | ||
22 | ? `NODE_CONFIG='${JSON.stringify(configOverride)}'` | ||
23 | : '' | ||
24 | |||
25 | return CLICommand.exec(`${prefix} ${this.getEnv()} ${command}`) | ||
26 | } | ||
27 | } | ||