Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/keploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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",
Expand Down