forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.js
29 lines (25 loc) · 859 Bytes
/
simulator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import waitOn from "wait-on";
import axios from "axios";
import { exec } from "child_process";
export const SIMULATOR_HOST = "localhost:7072";
export const SIMULATOR_URL = `http://${SIMULATOR_HOST}/`;
const HEALTH_URL = SIMULATOR_URL + "api/state";
const SHUTDOWN_URL = SIMULATOR_URL + "api/shutdown";
export async function startSimulator() {
console.log("starting simulator");
const instance = exec("npm run simulator");
console.log("exec end");
instance.stdout.pipe(process.stdout);
instance.stderr.pipe(process.stderr);
instance.on("exit", (code) => {
if (code !== 0) {
throw new Error("simulator terminated", code);
}
});
console.log("waiton");
await waitOn({ resources: [HEALTH_URL], log: true });
}
export async function stopSimulator() {
console.log("shutting down simulator");
await axios.post(SHUTDOWN_URL);
}