opencode.mjs 834 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env node
  2. import { createRequire } from "node:module"
  3. const require = createRequire(import.meta.url)
  4. import path from "path"
  5. import { execFileSync } from "child_process"
  6. let resolved = process.env.SST_BIN_PATH
  7. if (!resolved) {
  8. const name = `opencode-${process.platform}-${process.arch}`
  9. const binary = process.platform === "win32" ? "opencode.exe" : "opencode"
  10. try {
  11. resolved = require.resolve(path.join(name, "bin", binary))
  12. } catch (ex) {
  13. console.error(
  14. `It seems that your package manager failed to install the right version of the SST CLI for your platform. You can try manually installing the "${name}" package`,
  15. )
  16. process.exit(1)
  17. }
  18. }
  19. process.on("SIGINT", () => {})
  20. try {
  21. execFileSync(resolved, process.argv.slice(2), {
  22. stdio: "inherit",
  23. })
  24. } catch (ex) {
  25. process.exit(1)
  26. }