This commit is contained in:
Dax Raad
2025-06-06 23:58:09 -04:00
parent b34d5c959b
commit f22c93ba1b
3 changed files with 126 additions and 106 deletions

View File

@@ -22,42 +22,49 @@ yargs(hideBin(process.argv))
.command({
command: "$0",
describe: "Start OpenCode TUI",
handler: async () => {
await App.provide({ cwd: process.cwd(), version: VERSION }, async () => {
await Share.init()
const server = Server.listen()
builder: (yargs) =>
yargs.option("print-logs", {
type: "boolean",
}),
handler: async (args) => {
await App.provide(
{ cwd: process.cwd(), version: VERSION, printLogs: args.printLogs },
async () => {
await Share.init()
const server = Server.listen()
let cmd = ["go", "run", "./main.go"]
let cwd = new URL("../../tui/cmd/opencode", import.meta.url).pathname
if (Bun.embeddedFiles.length > 0) {
const blob = Bun.embeddedFiles[0] as File
const binary = path.join(Global.Path.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 })
await fs.chmod(binary, 0o755)
let cmd = ["go", "run", "./main.go"]
let cwd = new URL("../../tui/cmd/opencode", import.meta.url).pathname
if (Bun.embeddedFiles.length > 0) {
const blob = Bun.embeddedFiles[0] as File
const binary = path.join(Global.Path.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 })
await fs.chmod(binary, 0o755)
}
cwd = process.cwd()
cmd = [binary]
}
cwd = process.cwd()
cmd = [binary]
}
const proc = Bun.spawn({
cmd,
cwd,
stdout: "inherit",
stderr: "inherit",
stdin: "inherit",
env: {
...process.env,
OPENCODE_SERVER: server.url.toString(),
},
onExit: () => {
server.stop()
},
})
await proc.exited
await server.stop()
})
const proc = Bun.spawn({
cmd,
cwd,
stdout: "inherit",
stderr: "inherit",
stdin: "inherit",
env: {
...process.env,
OPENCODE_SERVER: server.url.toString(),
},
onExit: () => {
server.stop()
},
})
await proc.exited
await server.stop()
},
)
},
})
.command(RunCommand)