From 7db6bd883949461772edb85538284105e3153a93 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 05:13:58 +0000 Subject: [PATCH] feat: implement automatic update checks - Add silent mode to updatePackage - Automatically check for updates before running commands - Maintain graceful failure handling Co-Authored-By: Michael Latman --- src/auto-update.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/auto-update.ts b/src/auto-update.ts index dbb81c3..68f487d 100644 --- a/src/auto-update.ts +++ b/src/auto-update.ts @@ -17,32 +17,30 @@ async function getLatestVersion(): Promise { return stdout.trim(); } -export async function updatePackage(): Promise { +export async function updatePackage(silent: boolean = false): Promise { try { const currentVersion = await getCurrentVersion(); const latestVersion = await getLatestVersion(); if (currentVersion !== latestVersion) { - console.log(chalk.yellow(`\nA new version of mcp-get is available: ${latestVersion} (current: ${currentVersion})`)); - console.log(chalk.cyan('Installing update...')); + if (!silent) { + console.log(chalk.yellow(`\nA new version of mcp-get is available: ${latestVersion} (current: ${currentVersion})`)); + console.log(chalk.cyan('Installing update...')); + } try { - // Use npx to ensure we get the latest version await execAsync('npx --yes @michaellatman/mcp-get@latest'); - console.log(chalk.green('✓ Update complete\n')); + if (!silent) console.log(chalk.green('✓ Update complete\n')); } catch (installError: any) { - console.error(chalk.red('Failed to install update:'), installError.message); - process.exit(1); + if (!silent) console.error(chalk.red('Failed to install update:'), installError.message); + return; } - - // Exit after update to ensure the new version is used - process.exit(0); } else { - console.log(chalk.green('✓ mcp-get is already up to date\n')); + if (!silent) console.log(chalk.green('✓ mcp-get is already up to date\n')); } } catch (error: any) { - console.error(chalk.red('Failed to check for updates:'), error.message); - process.exit(1); + if (!silent) console.error(chalk.red('Failed to check for updates:'), error.message); + return; } }