2
0

build.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/usr/bin/env bun
  2. import solidPlugin from "../node_modules/@opentui/solid/scripts/solid-plugin"
  3. import path from "path"
  4. import fs from "fs"
  5. import { $ } from "bun"
  6. import { fileURLToPath } from "url"
  7. const __filename = fileURLToPath(import.meta.url)
  8. const __dirname = path.dirname(__filename)
  9. const dir = path.resolve(__dirname, "..")
  10. process.chdir(dir)
  11. import pkg from "../package.json"
  12. import { Script } from "@opencode-ai/script"
  13. const singleFlag = process.argv.includes("--single")
  14. const allTargets: {
  15. os: string
  16. arch: "arm64" | "x64"
  17. abi?: "musl"
  18. avx2?: false
  19. }[] = [
  20. {
  21. os: "linux",
  22. arch: "arm64",
  23. },
  24. {
  25. os: "linux",
  26. arch: "x64",
  27. },
  28. {
  29. os: "linux",
  30. arch: "x64",
  31. avx2: false,
  32. },
  33. {
  34. os: "linux",
  35. arch: "arm64",
  36. abi: "musl",
  37. },
  38. {
  39. os: "linux",
  40. arch: "x64",
  41. abi: "musl",
  42. },
  43. {
  44. os: "linux",
  45. arch: "x64",
  46. abi: "musl",
  47. avx2: false,
  48. },
  49. {
  50. os: "darwin",
  51. arch: "arm64",
  52. },
  53. {
  54. os: "darwin",
  55. arch: "x64",
  56. },
  57. {
  58. os: "darwin",
  59. arch: "x64",
  60. avx2: false,
  61. },
  62. {
  63. os: "windows",
  64. arch: "x64",
  65. },
  66. {
  67. os: "windows",
  68. arch: "x64",
  69. avx2: false,
  70. },
  71. ]
  72. const targets = singleFlag
  73. ? allTargets.filter((item) => item.os === process.platform && item.arch === process.arch)
  74. : allTargets
  75. await $`rm -rf dist`
  76. const binaries: Record<string, string> = {}
  77. await $`bun install --os="*" --cpu="*" @opentui/core@${pkg.dependencies["@opentui/core"]}`
  78. await $`bun install --os="*" --cpu="*" @parcel/watcher@${pkg.dependencies["@parcel/watcher"]}`
  79. for (const item of targets) {
  80. const name = [
  81. pkg.name,
  82. item.os,
  83. item.arch,
  84. item.avx2 === false ? "baseline" : undefined,
  85. item.abi === undefined ? undefined : item.abi,
  86. ]
  87. .filter(Boolean)
  88. .join("-")
  89. console.log(`building ${name}`)
  90. await $`mkdir -p dist/${name}/bin`
  91. const parserWorker = fs.realpathSync(path.resolve(dir, "./node_modules/@opentui/core/parser.worker.js"))
  92. const workerPath = "./src/cli/cmd/tui/worker.ts"
  93. await Bun.build({
  94. conditions: ["browser"],
  95. tsconfig: "./tsconfig.json",
  96. plugins: [solidPlugin],
  97. sourcemap: "external",
  98. compile: {
  99. target: name.replace(pkg.name, "bun") as any,
  100. outfile: `dist/${name}/bin/opencode`,
  101. execArgv: [`--user-agent=opencode/${Script.version}`, `--env-file=""`, `--`],
  102. windows: {},
  103. },
  104. entrypoints: ["./src/index.ts", parserWorker, workerPath],
  105. define: {
  106. OPENCODE_VERSION: `'${Script.version}'`,
  107. OTUI_TREE_SITTER_WORKER_PATH: "/$bunfs/root/" + path.relative(dir, parserWorker).replaceAll("\\", "/"),
  108. OPENCODE_WORKER_PATH: workerPath,
  109. OPENCODE_CHANNEL: `'${Script.channel}'`,
  110. },
  111. })
  112. await $`rm -rf ./dist/${name}/bin/tui`
  113. await Bun.file(`dist/${name}/package.json`).write(
  114. JSON.stringify(
  115. {
  116. name,
  117. version: Script.version,
  118. os: [item.os === "windows" ? "win32" : item.os],
  119. cpu: [item.arch],
  120. },
  121. null,
  122. 2,
  123. ),
  124. )
  125. binaries[name] = Script.version
  126. }
  127. export { binaries }