Skip to content

Commit

Permalink
feat: implement automatic update checks
Browse files Browse the repository at this point in the history
- Add silent mode to updatePackage
- Automatically check for updates before running commands
- Maintain graceful failure handling

Co-Authored-By: Michael Latman <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and michaellatman committed Dec 13, 2024
1 parent a1f7110 commit 7db6bd8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/auto-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,30 @@ async function getLatestVersion(): Promise<string> {
return stdout.trim();
}

export async function updatePackage(): Promise<void> {
export async function updatePackage(silent: boolean = false): Promise<void> {
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;
}
}

0 comments on commit 7db6bd8

Please sign in to comment.