|
1 | | -import { select, input, password } from "@inquirer/prompts"; |
| 1 | +import { select, input, password, confirm } from "@inquirer/prompts"; |
2 | 2 | import chalk from "chalk"; |
| 3 | +import { spawn } from "child_process"; |
3 | 4 | import type { |
4 | 5 | ProjectConfig, |
5 | 6 | AgentFramework, |
@@ -66,15 +67,69 @@ export const collectConfig = async (): Promise<ProjectConfig> => { |
66 | 67 | ); |
67 | 68 |
|
68 | 69 | if (selectedCodingProvider) { |
69 | | - const availability = await selectedCodingProvider.isAvailable(); |
| 70 | + let availability = await selectedCodingProvider.isAvailable(); |
70 | 71 | if (!availability.installed && availability.installCommand) { |
71 | 72 | console.log( |
72 | 73 | chalk.yellow( |
73 | 74 | `\n⚠️ ${selectedCodingProvider.displayName} is not installed.` |
74 | 75 | ) |
75 | 76 | ); |
76 | 77 | console.log(chalk.gray("To install it, run:")); |
77 | | - console.log(chalk.cyan(`${availability.installCommand}\n`)); |
| 78 | + console.log(chalk.cyan(`${availability.installCommand}`)); |
| 79 | + |
| 80 | + const shouldInstall = await confirm({ |
| 81 | + message: "Would you like me to install it for you?", |
| 82 | + default: true, |
| 83 | + }); |
| 84 | + |
| 85 | + if (shouldInstall) { |
| 86 | + console.log(chalk.gray("Installing...")); |
| 87 | + try { |
| 88 | + await new Promise<void>((resolve, reject) => { |
| 89 | + const [cmd, ...args] = availability.installCommand!.split(" "); |
| 90 | + const child = spawn(cmd, args, { stdio: "inherit" }); |
| 91 | + |
| 92 | + child.on("close", (code: number) => { |
| 93 | + if (code === 0) { |
| 94 | + resolve(); |
| 95 | + } else { |
| 96 | + reject( |
| 97 | + new Error(`Installation failed with exit code ${code}`) |
| 98 | + ); |
| 99 | + } |
| 100 | + }); |
| 101 | + |
| 102 | + child.on("error", reject); |
| 103 | + }); |
| 104 | + |
| 105 | + // Check availability again after installation |
| 106 | + availability = await selectedCodingProvider.isAvailable(); |
| 107 | + if (availability.installed) { |
| 108 | + console.log( |
| 109 | + chalk.green( |
| 110 | + `✅ ${selectedCodingProvider.displayName} installed successfully!\n` |
| 111 | + ) |
| 112 | + ); |
| 113 | + } else { |
| 114 | + console.log( |
| 115 | + chalk.red( |
| 116 | + `❌ Installation may have failed. Please try installing manually.\n` |
| 117 | + ) |
| 118 | + ); |
| 119 | + } |
| 120 | + } catch (error) { |
| 121 | + console.log( |
| 122 | + chalk.red( |
| 123 | + `❌ Installation failed: ${ |
| 124 | + error instanceof Error ? error.message : "Unknown error" |
| 125 | + }` |
| 126 | + ) |
| 127 | + ); |
| 128 | + console.log(chalk.gray("Please try installing manually.\n")); |
| 129 | + } |
| 130 | + } else { |
| 131 | + console.log(); |
| 132 | + } |
78 | 133 | } |
79 | 134 | } |
80 | 135 |
|
|
0 commit comments