|
| 1 | +const { execSync } = require("child_process") |
| 2 | +const fs = require("fs") |
| 3 | +const readline = require("readline") |
| 4 | + |
| 5 | +// detect "yes" flags |
| 6 | +const autoYes = process.argv.includes("-y") |
| 7 | + |
| 8 | +// detect editor command from args or default to "code" |
| 9 | +const editorArg = process.argv.find((arg) => arg.startsWith("--editor=")) |
| 10 | +const defaultEditor = editorArg ? editorArg.split("=")[1] : "code" |
| 11 | + |
| 12 | +const rl = readline.createInterface({ |
| 13 | + input: process.stdin, |
| 14 | + output: process.stdout, |
| 15 | +}) |
| 16 | + |
| 17 | +const askQuestion = (question) => { |
| 18 | + return new Promise((resolve) => { |
| 19 | + rl.question(question, (answer) => { |
| 20 | + resolve(answer) |
| 21 | + }) |
| 22 | + }) |
| 23 | +} |
| 24 | + |
| 25 | +async function main() { |
| 26 | + try { |
| 27 | + const packageJson = JSON.parse(fs.readFileSync("./src/package.json", "utf-8")) |
| 28 | + const name = packageJson.name |
| 29 | + const version = packageJson.version |
| 30 | + const vsixFileName = `./bin/${name}-${version}.vsix` |
| 31 | + const publisher = packageJson.publisher |
| 32 | + const extensionId = `${publisher}.${name}` |
| 33 | + |
| 34 | + console.log("\n🚀 Roo Code VSIX Installer") |
| 35 | + console.log("========================") |
| 36 | + console.log("\nThis script will:") |
| 37 | + console.log("1. Uninstall any existing version of the Roo Code extension") |
| 38 | + console.log("2. Install the newly built VSIX package") |
| 39 | + console.log(`\nExtension: ${extensionId}`) |
| 40 | + console.log(`VSIX file: ${vsixFileName}`) |
| 41 | + |
| 42 | + // Ask for editor command if not provided |
| 43 | + let editorCommand = defaultEditor |
| 44 | + if (!editorArg && !autoYes) { |
| 45 | + const editorAnswer = await askQuestion( |
| 46 | + "\nWhich editor command to use? (code/cursor/code-insiders) [default: code]: ", |
| 47 | + ) |
| 48 | + if (editorAnswer.trim()) { |
| 49 | + editorCommand = editorAnswer.trim() |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + // skip prompt if auto-yes |
| 54 | + const answer = autoYes ? "y" : await askQuestion("\nDo you wish to continue? (y/n): ") |
| 55 | + |
| 56 | + if (answer.toLowerCase() !== "y") { |
| 57 | + console.log("Installation cancelled.") |
| 58 | + rl.close() |
| 59 | + process.exit(0) |
| 60 | + } |
| 61 | + |
| 62 | + console.log(`\nProceeding with installation using '${editorCommand}' command...`) |
| 63 | + |
| 64 | + try { |
| 65 | + execSync(`${editorCommand} --uninstall-extension ${extensionId}`, { stdio: "inherit" }) |
| 66 | + } catch (e) { |
| 67 | + console.log("Extension not installed, skipping uninstall step") |
| 68 | + } |
| 69 | + |
| 70 | + if (!fs.existsSync(vsixFileName)) { |
| 71 | + console.error(`\n❌ VSIX file not found: ${vsixFileName}`) |
| 72 | + console.error("Make sure the build completed successfully") |
| 73 | + rl.close() |
| 74 | + process.exit(1) |
| 75 | + } |
| 76 | + |
| 77 | + execSync(`${editorCommand} --install-extension ${vsixFileName}`, { stdio: "inherit" }) |
| 78 | + |
| 79 | + console.log(`\n✅ Successfully installed extension from ${vsixFileName}`) |
| 80 | + console.log("\n⚠️ IMPORTANT: You need to restart VS Code for the changes to take effect.") |
| 81 | + console.log(" Please close and reopen VS Code to use the updated extension.\n") |
| 82 | + |
| 83 | + rl.close() |
| 84 | + } catch (error) { |
| 85 | + console.error("\n❌ Failed to install extension:", error.message) |
| 86 | + rl.close() |
| 87 | + process.exit(1) |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +main() |
0 commit comments