mirror of
https://github.com/eyaltoledano/claude-task-master.git
synced 2026-01-30 06:12:05 +00:00
fix: improve auto-update to happen before you execute a command (#1371)
This commit is contained in:
@@ -32,7 +32,8 @@ export {
|
||||
checkForUpdate,
|
||||
performAutoUpdate,
|
||||
displayUpgradeNotification,
|
||||
compareVersions
|
||||
compareVersions,
|
||||
restartWithNewVersion
|
||||
} from './utils/auto-update.js';
|
||||
|
||||
export { runInteractiveSetup } from './commands/models/index.js';
|
||||
|
||||
@@ -7,6 +7,7 @@ import https from 'https';
|
||||
import chalk from 'chalk';
|
||||
import ora from 'ora';
|
||||
import boxen from 'boxen';
|
||||
import process from 'process';
|
||||
|
||||
export interface UpdateInfo {
|
||||
currentVersion: string;
|
||||
@@ -345,9 +346,6 @@ export async function performAutoUpdate(
|
||||
`Successfully updated to version ${chalk.bold(latestVersion)}`
|
||||
)
|
||||
);
|
||||
console.log(
|
||||
chalk.dim('Please restart your command to use the new version.')
|
||||
);
|
||||
resolve(true);
|
||||
} else {
|
||||
spinner.fail(chalk.red('Auto-update failed'));
|
||||
@@ -375,3 +373,33 @@ export async function performAutoUpdate(
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart the CLI with the newly installed version
|
||||
* @param argv - Original command-line arguments (process.argv)
|
||||
*/
|
||||
export function restartWithNewVersion(argv: string[]): void {
|
||||
const args = argv.slice(2); // Remove 'node' and script path
|
||||
|
||||
console.log(chalk.dim('Restarting with updated version...\n'));
|
||||
|
||||
// Spawn the updated task-master command
|
||||
const child = spawn('task-master', args, {
|
||||
stdio: 'inherit', // Inherit stdin/stdout/stderr so it looks seamless
|
||||
detached: false,
|
||||
shell: process.platform === 'win32' // Windows compatibility
|
||||
});
|
||||
|
||||
child.on('exit', (code) => {
|
||||
process.exit(code || 0);
|
||||
});
|
||||
|
||||
child.on('error', (error) => {
|
||||
console.error(
|
||||
chalk.red('Failed to restart with new version:'),
|
||||
error.message
|
||||
);
|
||||
console.log(chalk.yellow('Please run your command again manually.'));
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user