]>
Commit | Line | Data |
---|---|---|
3cf68b86 C |
1 | import { exec, spawn } from 'child_process' |
2 | import { join, resolve } from 'path' | |
3 | ||
4 | function runServer (appInstance: string, config: any = {}) { | |
5 | const env = Object.create(process.env) | |
6 | env['NODE_ENV'] = 'test' | |
7 | env['NODE_APP_INSTANCE'] = appInstance | |
8 | ||
9 | env['NODE_CONFIG'] = JSON.stringify({ | |
10 | rates_limit: { | |
11 | api: { | |
12 | max: 5000 | |
13 | }, | |
14 | login: { | |
15 | max: 5000 | |
16 | } | |
17 | }, | |
18 | log: { | |
19 | level: 'warn' | |
20 | }, | |
21 | signup: { | |
22 | enabled: false | |
23 | }, | |
24 | transcoding: { | |
25 | enabled: false | |
26 | }, | |
a6241926 C |
27 | video_studio: { |
28 | enabled: false | |
29 | }, | |
3cf68b86 C |
30 | |
31 | ...config | |
32 | }) | |
33 | ||
34 | const forkOptions = { | |
35 | env, | |
36 | cwd: getRootCWD(), | |
37 | detached: false | |
38 | } | |
39 | ||
40 | const p = spawn('node', [ join('dist', 'server.js') ], forkOptions) | |
41 | p.stderr.on('data', data => console.error(data.toString())) | |
42 | p.stdout.on('data', data => console.error(data.toString())) | |
43 | ||
44 | return p | |
45 | } | |
46 | ||
47 | function runCommand (command: string) { | |
48 | return new Promise<void>((res, rej) => { | |
49 | const p = exec(command, { cwd: getRootCWD() }) | |
50 | ||
51 | p.stderr.on('data', data => console.error(data.toString())) | |
52 | p.on('error', err => rej(err)) | |
53 | p.on('exit', () => res()) | |
54 | }) | |
55 | } | |
56 | ||
57 | export { | |
58 | runServer, | |
59 | runCommand | |
60 | } | |
61 | ||
62 | // --------------------------------------------------------------------------- | |
63 | ||
64 | function getRootCWD () { | |
65 | return resolve('../..') | |
66 | } |