Skip to content

Commit

Permalink
fix: implement update command and improve error handling
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and michaellatman committed Dec 13, 2024
1 parent c56cd1d commit a1f7110
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/auto-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import chalk from 'chalk';
const execAsync = promisify(exec);

async function getCurrentVersion(): Promise<string> {
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;
}

Expand All @@ -24,18 +25,24 @@ export async function updatePackage(): Promise<void> {
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);
}
}

5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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 <package> 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);
}
}
Expand Down

0 comments on commit a1f7110

Please sign in to comment.