From c4c6284a05e41fa97d9a47f521314e569d9d51dc Mon Sep 17 00:00:00 2001 From: sekhar kumar dash Date: Tue, 4 Apr 2023 23:41:24 +0530 Subject: [PATCH] build: editing the keploy.ts Signed-off-by: sekhar kumar dash --- src/keploy.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/keploy.ts b/src/keploy.ts index eeeae15..5af8177 100644 --- a/src/keploy.ts +++ b/src/keploy.ts @@ -13,6 +13,8 @@ import { StrArr } from "../proto/services/StrArr"; import assert = require("assert"); import { createExecutionContext, getExecutionContext } from "./context"; import Mode, { MODE_OFF } from "./mode"; +import { exec, spawn } from "child_process"; + const PROTO_PATH = "../proto/services.proto"; const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_PATH)); @@ -85,7 +87,35 @@ export default class Keploy { this.responses = {}; this.dependencies = {}; this.mocks = {}; - } + if (process.env.KEPLOY_MODE === "record" || process.env.KEPLOY_MODE === "test") { + exec("which keploy", (error: Error | null, stdout: string, stderr: string) => { + if (error) { + console.error(`Error finding keploy: ${error.message}`); + return; + } + + if (!stdout) { + console.log( + "Keploy Server is not installed. Please install it using https://docs.keploy.io/docs/go/installation" + ); + return; + } + + exec("lsof -i:6789", (error: Error | null, stdout: string, stderr: string) => { + if (error) { + console.error(`Error checking port: ${error.message}`); + return; + } + + if (!stdout) { + const keployProcess = spawn("keploy", [], { env: { KEPLOY_PORT: "6789" } }); + keployProcess.on("error", (error: Error) => { + console.error(`Error starting keploy: ${error.message}`); + }); + } + }); + }); + }} validateServerConfig({ url = process.env.KEPLOY_SERVER_URL || "localhost:6789",