github.com/DapperCollectives/CAST/backend@v0.0.0-20230921221157-1350c8be7c96/chain.js (about) 1 const fs = require("fs"); 2 const { exec, spawn } = require("child_process"); 3 4 const execCb = (error, stdout, stderr) => { 5 if (error) { 6 console.log(`error: ${error.message}`); 7 return; 8 } 9 if (stderr) { 10 console.log(`stderr: ${stderr}`); 11 return; 12 } 13 14 console.log(stdout); 15 }; 16 17 let chainProcess; 18 19 if (fs.existsSync("./flow.json")) { 20 console.log("Found flow file, starting emulator..."); 21 chainProcess = spawn("flow", ["emulator", "--verbose"]); 22 } else { 23 console.log("No existing flow file found, creating new one..."); 24 exec("flow init", (error, stdout, stderr) => { 25 execCb(error, stdout, stderr); 26 chainProcess = spawn("flow", ["emulator", "--verbose"]); 27 }); 28 } 29 30 chainProcess.stdout.on("data", (stdout) => { 31 console.log(stdout.toString()); 32 }); 33 34 chainProcess.stderr.on("data", (stderr) => { 35 console.log(`stderr: ${stderr}`); 36 }); 37 38 const execOpts = { 39 env: { 40 ...process.env, 41 APP_ENV: "local", 42 BASE_URL: "http://localhost:8701", 43 }, 44 }; 45 46 exec( 47 'flow dev-wallet --emulator-host "http://localhost:8888" -f flow.json', 48 execOpts, 49 execCb 50 );