install-vsix.js 3.3 KB

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