From bb48183a121117baeb0966e01d5cd909927cd924 Mon Sep 17 00:00:00 2001 From: shivamsouravjha Date: Sat, 4 Nov 2023 11:16:14 +0000 Subject: [PATCH] udpate:start and stop user application --- keployV2/keployCli.ts | 19 +++++++++++++++---- package-lock.json | 17 ++++++++++++----- package.json | 3 ++- yarn.lock | 5 +++++ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/keployV2/keployCli.ts b/keployV2/keployCli.ts index 822ea0e..b3a22ec 100644 --- a/keployV2/keployCli.ts +++ b/keployV2/keployCli.ts @@ -1,5 +1,6 @@ import axios from 'axios'; import { exec, execSync, spawn, ChildProcess } from 'child_process'; +const treeKill = require('tree-kill'); const GRAPHQL_ENDPOINT = '/query'; const HOST = 'http://localhost:'; @@ -18,6 +19,19 @@ export const setTestRunCompletionStatus = (status: boolean) => { hasTestRunCompleted = status; }; +let userCommandPID:any = 0; + +export const StartUserApplication = (userCmd:string) =>{ + const [cmd, ...args] = userCmd.split(' '); + const npmStartProcess = spawn(cmd, args,{ + stdio: [process.stdin, 'pipe', process.stderr], + }); + userCommandPID = npmStartProcess.pid +} + +export const StopUserApplication = () =>{ + treeKill(userCommandPID) +} let childProcesses: ChildProcess[] = []; const processWrap = (command: string): Promise => { return new Promise((resolve, reject) => { @@ -182,7 +196,6 @@ export const FetchTestSets = async (): Promise => { return null; }; - export const FetchTestSetStatus = async (testRunId: string): Promise => { try { const client = await setHttpClient(); @@ -211,10 +224,8 @@ export const RunTestSet = async (testSetName: string): Promise => if (!client) throw new Error("Could not initialize HTTP client."); const response = await client.post('', { - timeout: 5000, // Set a timeout (5000 ms or 5 seconds, adjust as necessary) query: `mutation { runTestSet(testSet: "${testSetName}") { success testRunId message } }` }); - if (response.data && response.data.data && response.data.data.runTestSet) { return response.data.data.runTestSet.testRunId; } else { @@ -226,10 +237,10 @@ export const RunTestSet = async (testSetName: string): Promise => return null; }; - export const StopKeployServer = () => { return killProcessOnPort(serverPort); }; + export const killProcessOnPort = async (port: number): Promise => { return new Promise((resolve, reject) => { //console.debug(`Trying to kill process running on port: ${port}`); diff --git a/package-lock.json b/package-lock.json index 16b604f..586dc67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "typescript-sdk", + "name": "@keploy/typescript-sdk", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "typescript-sdk", + "name": "@keploy/typescript-sdk", "version": "1.0.0", "license": "MIT", "dependencies": { @@ -19,7 +19,8 @@ "import-in-the-middle": "^1.3.4", "merge-descriptors": "^1.0.1", "node-fetch": "^2.6.7", - "require-in-the-middle": "^5.1.0" + "require-in-the-middle": "^5.1.0", + "tree-kill": "^1.2.2" }, "devDependencies": { "@commitlint/cli": "^16.2.1", @@ -1631,7 +1632,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -2073,7 +2073,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -5779,6 +5778,14 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/trim-newlines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz", diff --git a/package.json b/package.json index a9dfc7e..eefdebc 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "import-in-the-middle": "^1.3.4", "merge-descriptors": "^1.0.1", "node-fetch": "^2.6.7", - "require-in-the-middle": "^5.1.0" + "require-in-the-middle": "^5.1.0", + "tree-kill": "^1.2.2" }, "description": "[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen?logo=github)](CODE_OF_CONDUCT.md) [![Slack](.github/slack.svg)](https://join.slack.com/t/keploy/shared_invite/zt-12rfbvc01-o54cOG0X1G6eVJTuI_orSA) [![License](.github/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)", "bugs": { diff --git a/yarn.lock b/yarn.lock index acb4fa8..97b0baa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3462,6 +3462,11 @@ tr46@~0.0.3: resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz" integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== +tree-kill@^1.2.2: + version "1.2.2" + resolved "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz" + integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A== + trim-newlines@^3.0.0: version "3.0.1" resolved "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz"