install-vsix.js 2.7 KB

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