From a1f71109e680d1df85f8a18ea88ec9d446fe9227 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 04:22:46 +0000 Subject: [PATCH] fix: implement update command and improve error handling - Added update command to CLI - Connected updatePackage() from auto-update.ts - Improved error handling for update process - Added proper version comparison messaging Co-Authored-By: Michael Latman --- src/auto-update.ts | 27 +++++++++++++++++---------- src/index.ts | 5 +++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/auto-update.ts b/src/auto-update.ts index 5864f3a..dbb81c3 100644 --- a/src/auto-update.ts +++ b/src/auto-update.ts @@ -7,7 +7,8 @@ import chalk from 'chalk'; const execAsync = promisify(exec); async function getCurrentVersion(): Promise { - const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8')); + const packageJsonPath = new URL('../package.json', import.meta.url).pathname; + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); return packageJson.version; } @@ -24,18 +25,24 @@ export async function updatePackage(): Promise { if (currentVersion !== latestVersion) { console.log(chalk.yellow(`\nA new version of mcp-get is available: ${latestVersion} (current: ${currentVersion})`)); console.log(chalk.cyan('Installing update...')); - - // Use npx to ensure we get the latest version - await execAsync('npx --yes @michaellatman/mcp-get@latest'); - - console.log(chalk.green('✓ Update complete\n')); - + + 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')); + } catch (installError: any) { + console.error(chalk.red('Failed to install update:'), installError.message); + process.exit(1); + } + // 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')); } - } catch (error) { - // Log update check failure but continue with execution - console.log(chalk.yellow('\nFailed to check for updates. Continuing with current version.')); + } catch (error: any) { + console.error(chalk.red('Failed to check for updates:'), error.message); + process.exit(1); } } diff --git a/src/index.ts b/src/index.ts index 2e2ed7b..66247f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { list } from './commands/list.js'; import { install } from './commands/install.js'; import { uninstall } from './commands/uninstall.js'; import { listInstalledPackages } from './commands/installed.js'; +import { updatePackage } from './auto-update.js'; const command = process.argv[2]; const packageName = process.argv[3]; @@ -26,12 +27,16 @@ async function main() { case 'installed': await listInstalledPackages(); break; + case 'update': + await updatePackage(); + break; default: console.log('Available commands:'); console.log(' list List all available packages'); console.log(' install Install a package'); console.log(' uninstall [package] Uninstall a package'); console.log(' installed List installed packages'); + console.log(' update Update mcp-get to latest version'); process.exit(1); } }