mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-24 03:04:21 +01:00
embed go
This commit is contained in:
1
packages/opencode/.gitignore
vendored
1
packages/opencode/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
node_modules
|
||||
dist
|
||||
gen
|
||||
app.log
|
||||
|
||||
@@ -4,19 +4,15 @@ import { $ } from "bun"
|
||||
|
||||
import pkg from "../package.json"
|
||||
|
||||
const dry = process.argv.includes("--dry")
|
||||
|
||||
const version = `0.0.0-${Date.now()}`
|
||||
|
||||
const ARCH = {
|
||||
const GOARCH: Record<string, string> = {
|
||||
arm64: "arm64",
|
||||
x64: "amd64",
|
||||
}
|
||||
|
||||
const OS = {
|
||||
linux: "linux",
|
||||
darwin: "mac",
|
||||
win32: "windows",
|
||||
}
|
||||
|
||||
const targets = [
|
||||
["linux", "arm64"],
|
||||
["linux", "x64"],
|
||||
@@ -32,20 +28,24 @@ for (const [os, arch] of targets) {
|
||||
console.log(`building ${os}-${arch}`)
|
||||
const name = `${pkg.name}-${os}-${arch}`
|
||||
await $`mkdir -p dist/${name}/bin`
|
||||
await $`bun build --compile --minify --target=bun-${os}-${arch} --outfile=dist/${name}/bin/${pkg.name} ./src/index.ts`
|
||||
await $`GOOS=${os} GOARCH=${GOARCH[arch]} go build -o ../opencode/dist/${name}/bin/tui ../tui/main.go`.cwd(
|
||||
"../tui",
|
||||
)
|
||||
await $`bun build --compile --minify --target=bun-${os}-${arch} --outfile=dist/${name}/bin/opencode ./src/index.ts ./dist/${name}/bin/tui`
|
||||
await $`rm -rf ./dist/${name}/bin/tui`
|
||||
await Bun.file(`dist/${name}/package.json`).write(
|
||||
JSON.stringify(
|
||||
{
|
||||
name,
|
||||
version,
|
||||
os: [os],
|
||||
os: [os === "windows" ? "win32" : os],
|
||||
cpu: [arch],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
)
|
||||
await $`cd dist/${name} && npm publish --access public --tag latest`
|
||||
if (!dry) await $`cd dist/${name} && npm publish --access public --tag latest`
|
||||
optionalDependencies[name] = version
|
||||
}
|
||||
|
||||
@@ -65,4 +65,5 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
|
||||
2,
|
||||
),
|
||||
)
|
||||
await $`cd ./dist/${pkg.name} && npm publish --access public --tag latest`
|
||||
if (!dry)
|
||||
await $`cd ./dist/${pkg.name} && npm publish --access public --tag latest`
|
||||
|
||||
@@ -7,16 +7,42 @@ import { Bus } from "./bus"
|
||||
import { Session } from "./session/session"
|
||||
import cac from "cac"
|
||||
import { Share } from "./share/share"
|
||||
import { Storage } from "./storage/storage"
|
||||
import { LLM } from "./llm/llm"
|
||||
import { Message } from "./session/message"
|
||||
import { Global } from "./global"
|
||||
|
||||
const cli = cac("opencode")
|
||||
|
||||
cli.command("", "Start the opencode in interactive mode").action(async () => {
|
||||
await App.provide({ directory: process.cwd() }, async () => {
|
||||
await Share.init()
|
||||
Server.listen()
|
||||
const server = Server.listen()
|
||||
|
||||
let cmd = ["go", "run", "./main.go"]
|
||||
let cwd = "../tui"
|
||||
if (Bun.embeddedFiles.length > 0) {
|
||||
const blob = Bun.embeddedFiles[0] as File
|
||||
const binary = path.join(Global.cache(), "tui", blob.name)
|
||||
const file = Bun.file(binary)
|
||||
if (!(await file.exists())) {
|
||||
console.log("installing tui binary...")
|
||||
await Bun.write(file, blob, { mode: 0o755 })
|
||||
}
|
||||
cwd = process.cwd()
|
||||
cmd = [binary]
|
||||
}
|
||||
const proc = Bun.spawn({
|
||||
cmd,
|
||||
cwd,
|
||||
stdout: "inherit",
|
||||
stderr: "inherit",
|
||||
stdin: "inherit",
|
||||
onExit: () => {
|
||||
server.stop()
|
||||
},
|
||||
})
|
||||
await proc.exited
|
||||
await server.stop()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user