2
0

preinstall.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env node
  2. import fs from "fs"
  3. import path from "path"
  4. import os from "os"
  5. import { fileURLToPath } from "url"
  6. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  7. function main() {
  8. if (os.platform() !== "win32") {
  9. console.log("Non-Windows platform detected, skipping preinstall")
  10. return
  11. }
  12. console.log("Windows detected: Modifying package.json bin entry")
  13. // Read package.json
  14. const packageJsonPath = path.join(__dirname, "package.json")
  15. const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
  16. // Modify bin to point to .cmd file on Windows
  17. packageJson.bin = {
  18. opencode: "./bin/opencode.cmd",
  19. }
  20. // Write it back
  21. fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
  22. console.log("Updated package.json bin to use opencode.cmd")
  23. // Now you can also remove the Unix script if you want
  24. const unixScript = path.join(__dirname, "bin", "opencode")
  25. if (fs.existsSync(unixScript)) {
  26. console.log("Removing Unix shell script")
  27. fs.unlinkSync(unixScript)
  28. }
  29. }
  30. try {
  31. main()
  32. } catch (error) {
  33. console.error("Preinstall script error:", error.message)
  34. process.exit(0)
  35. }