Skip to content

Commit

Permalink
feat: added keploy version mapping
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Sharma <[email protected]>
  • Loading branch information
ayush3160 committed Nov 29, 2024
1 parent 2b6614d commit 30bea9f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
4 changes: 4 additions & 0 deletions keploy-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"1.0.20": "v2.3.0-beta41",
"1.0.25": "v2.3.0-beta41"
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "keployio",
"displayName": "Keploy",
"description": "Streamline testing with the power of Keploy, directly in your favorite IDE.",
"version": "1.0.20",
"version": "1.0.25",
"publisher": "Keploy",
"icon": "media/logo.png",
"pricing": "Free",
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"submenus": [
{
"icon": "$(account)",
"icon": "$(account)",
"label": "Sign In Options",
"id": "sign_in_submenu"
}
Expand Down Expand Up @@ -107,7 +107,6 @@
{
"command": "keploy.SignInWithMicrosoft",
"title": "Sign In with Microsoft"

}
]
},
Expand Down Expand Up @@ -216,4 +215,4 @@
"walk": "^2.3.15",
"yaml": "^2.4.2"
}
}
}
19 changes: 17 additions & 2 deletions src/OneClickInstall.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { exec } from 'child_process';
import { getKeployVersion , getCurrentKeployVersion } from './version';

export default function executeKeployOneClickCommand(): void {
export default async function executeKeployOneClickCommand(): Promise<void> {
// Check if Keploy is installed by trying to run the `keploy` command
const checkKeployExistsCommand = `keploy`;
const keployVersion = await getKeployVersion();
const currentKeployVersion = await getCurrentKeployVersion();

// Check the if keploy is installed and have the same version or not
if(currentKeployVersion !== "" && keployVersion !== currentKeployVersion){
const removeKeployCommand = `rm -rf ~/.keploy`;
exec(removeKeployCommand, (error, stdout, stderr) => {
if (error) {
console.error(`Error during removal: ${error.message}`);
return;
}
});
}

// The command to download and install Keploy
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`;
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -v ${keployVersion} -noRoot`;

exec(checkKeployExistsCommand, (error, stdout, stderr) => {
if (error) {
// Execute the installation command
Expand Down
6 changes: 4 additions & 2 deletions src/updateKeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ export async function downloadAndUpdateDocker(): Promise<void> {

export async function downloadAndInstallKeployBinary(): Promise<void> {
console.log('Downloading and installing Keploy binary...');
return new Promise<void>((resolve, reject) => {
return new Promise<void>(async (resolve, reject) => {

try {
const curlCmd = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`;
const keployVersion = await getKeployVersion();

const curlCmd = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -v ${keployVersion} -noRoot`;

child_process.exec(curlCmd, (error, stdout, stderr) => {
if (error) {
Expand Down
22 changes: 12 additions & 10 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

import { execShell } from './execShell';
import * as path from 'path';
import * as fs from 'fs';
export async function getKeployVersion() {
// GitHub repository details
const repoOwner = "keploy";
const repoName = "keploy";
const packagePath = path.resolve(__dirname, '../package.json');
const packageContent = fs.readFileSync(packagePath, 'utf-8');
const packageData = JSON.parse(packageContent);

const apiURL = `https://api.github.com/repos/${repoOwner}/${repoName}/releases/latest`;
const keployVersionJsonPath = path.resolve(__dirname, '../keploy-version.json');
const keployVersionJsonContent = fs.readFileSync(keployVersionJsonPath, 'utf-8');
const keployVersionJson = JSON.parse(keployVersionJsonContent);

// Get the latest release
const response = await fetch(apiURL);
const data: any = await response.json();
const latestVersion = data.tag_name;
return latestVersion;
const keployVersion = keployVersionJson[`${packageData.version}`];

return keployVersion;
}

export async function getCurrentKeployVersion() {
Expand All @@ -24,7 +26,7 @@ export async function getCurrentKeployVersion() {
output = await execShell('/usr/local/bin/keploybin --version');
}catch(error){
console.log("Error Fetching version With Absolute path " + error);
throw error;
return '';
}
}
console.log('output:', output);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"rootDir": "src",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true /* enable all strict type-checking options */
"strict": true, /* enable all strict type-checking options */
"resolveJsonModule": true
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
Expand Down

0 comments on commit 30bea9f

Please sign in to comment.