-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchain.js
More file actions
50 lines (42 loc) · 1.06 KB
/
chain.js
File metadata and controls
50 lines (42 loc) · 1.06 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require("fs");
const { exec, spawn } = require("child_process");
const execCb = (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(stdout);
};
let chainProcess;
if (fs.existsSync("./flow.json")) {
console.log("Found flow file, starting emulator...");
chainProcess = spawn("flow", ["emulator", "--verbose"]);
} else {
console.log("No existing flow file found, creating new one...");
exec("flow init", (error, stdout, stderr) => {
execCb(error, stdout, stderr);
chainProcess = spawn("flow", ["emulator", "--verbose"]);
});
}
chainProcess.stdout.on("data", (stdout) => {
console.log(stdout.toString());
});
chainProcess.stderr.on("data", (stderr) => {
console.log(`stderr: ${stderr}`);
});
const execOpts = {
env: {
...process.env,
APP_ENV: "local",
BASE_URL: "http://localhost:8701",
},
};
exec(
'flow dev-wallet --emulator-host "http://localhost:8888" -f flow.json',
execOpts,
execCb
);