b51b9eb677
Update all github.com/Kilo-Org/kilo references to github.com/Kilo-Org/kilocode across package.json files, documentation, scripts, and configuration files. This reflects the repository rename from kilo to kilocode.
204 lines
5.4 KiB
TypeScript
Executable File
204 lines
5.4 KiB
TypeScript
Executable File
#!/usr/bin/env bun
|
|
|
|
import solidPlugin from "../node_modules/@opentui/solid/scripts/solid-plugin"
|
|
import path from "path"
|
|
import fs from "fs"
|
|
import { $ } from "bun"
|
|
import { fileURLToPath } from "url"
|
|
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
const __dirname = path.dirname(__filename)
|
|
const dir = path.resolve(__dirname, "..")
|
|
|
|
process.chdir(dir)
|
|
|
|
import pkg from "../package.json"
|
|
import { Script } from "@opencode-ai/script"
|
|
const modelsUrl = process.env.KILO_MODELS_URL || "https://models.dev" // kilocode_change
|
|
// Fetch and generate models.dev snapshot
|
|
const modelsData = process.env.MODELS_DEV_API_JSON
|
|
? await Bun.file(process.env.MODELS_DEV_API_JSON).text()
|
|
: await fetch(`${modelsUrl}/api.json`).then((x) => x.text())
|
|
await Bun.write(
|
|
path.join(dir, "src/provider/models-snapshot.ts"),
|
|
`// Auto-generated by build.ts - do not edit\nexport const snapshot = ${modelsData} as const\n`,
|
|
)
|
|
console.log("Generated models-snapshot.ts")
|
|
|
|
const singleFlag = process.argv.includes("--single")
|
|
const baselineFlag = process.argv.includes("--baseline")
|
|
const skipInstall = process.argv.includes("--skip-install")
|
|
|
|
const allTargets: {
|
|
os: string
|
|
arch: "arm64" | "x64"
|
|
abi?: "musl"
|
|
avx2?: false
|
|
}[] = [
|
|
{
|
|
os: "linux",
|
|
arch: "arm64",
|
|
},
|
|
{
|
|
os: "linux",
|
|
arch: "x64",
|
|
},
|
|
{
|
|
os: "linux",
|
|
arch: "x64",
|
|
avx2: false,
|
|
},
|
|
{
|
|
os: "linux",
|
|
arch: "arm64",
|
|
abi: "musl",
|
|
},
|
|
{
|
|
os: "linux",
|
|
arch: "x64",
|
|
abi: "musl",
|
|
},
|
|
{
|
|
os: "linux",
|
|
arch: "x64",
|
|
abi: "musl",
|
|
avx2: false,
|
|
},
|
|
{
|
|
os: "darwin",
|
|
arch: "arm64",
|
|
},
|
|
{
|
|
os: "darwin",
|
|
arch: "x64",
|
|
},
|
|
{
|
|
os: "darwin",
|
|
arch: "x64",
|
|
avx2: false,
|
|
},
|
|
{
|
|
os: "win32",
|
|
arch: "x64",
|
|
},
|
|
{
|
|
os: "win32",
|
|
arch: "x64",
|
|
avx2: false,
|
|
},
|
|
]
|
|
|
|
const targets = singleFlag
|
|
? allTargets.filter((item) => {
|
|
if (item.os !== process.platform || item.arch !== process.arch) {
|
|
return false
|
|
}
|
|
|
|
// When building for the current platform, prefer a single native binary by default.
|
|
// Baseline binaries require additional Bun artifacts and can be flaky to download.
|
|
if (item.avx2 === false) {
|
|
return baselineFlag
|
|
}
|
|
|
|
// also skip abi-specific builds for the same reason
|
|
if (item.abi !== undefined) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
})
|
|
: allTargets
|
|
|
|
await $`rm -rf dist`
|
|
|
|
const binaries: Record<string, string> = {}
|
|
if (!skipInstall) {
|
|
await $`bun install --os="*" --cpu="*" @opentui/core@${pkg.dependencies["@opentui/core"]}`
|
|
await $`bun install --os="*" --cpu="*" @parcel/watcher@${pkg.dependencies["@parcel/watcher"]}`
|
|
}
|
|
for (const item of targets) {
|
|
const name = [
|
|
pkg.name,
|
|
// changing to win32 flags npm for some reason
|
|
item.os === "win32" ? "windows" : item.os,
|
|
item.arch,
|
|
item.avx2 === false ? "baseline" : undefined,
|
|
item.abi === undefined ? undefined : item.abi,
|
|
]
|
|
.filter(Boolean)
|
|
.join("-")
|
|
console.log(`building ${name}`)
|
|
await $`mkdir -p dist/${name}/bin`
|
|
|
|
const parserWorker = fs.realpathSync(path.resolve(dir, "./node_modules/@opentui/core/parser.worker.js"))
|
|
const workerPath = "./src/cli/cmd/tui/worker.ts"
|
|
|
|
// Use platform-specific bunfs root path based on target OS
|
|
const bunfsRoot = item.os === "win32" ? "B:/~BUN/root/" : "/$bunfs/root/"
|
|
const workerRelativePath = path.relative(dir, parserWorker).replaceAll("\\", "/")
|
|
|
|
await Bun.build({
|
|
conditions: ["browser"],
|
|
tsconfig: "./tsconfig.json",
|
|
plugins: [solidPlugin],
|
|
sourcemap: "external",
|
|
compile: {
|
|
autoloadBunfig: false,
|
|
autoloadDotenv: false,
|
|
//@ts-ignore (bun types aren't up to date)
|
|
autoloadTsconfig: true,
|
|
autoloadPackageJson: true,
|
|
target: name.replace(pkg.name, "bun") as any,
|
|
outfile: `dist/${name}/bin/kilo`,
|
|
execArgv: [`--user-agent=kilo/${Script.version}`, "--use-system-ca", "--"],
|
|
windows: {},
|
|
},
|
|
entrypoints: ["./src/index.ts", parserWorker, workerPath],
|
|
define: {
|
|
KILO_VERSION: `'${Script.version}'`, // kilocode_change
|
|
OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + workerRelativePath,
|
|
KILO_WORKER_PATH: workerPath,
|
|
KILO_CHANNEL: `'${Script.channel}'`, // kilocode_change
|
|
KILO_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "",
|
|
},
|
|
})
|
|
|
|
await $`rm -rf ./dist/${name}/bin/tui`
|
|
await Bun.file(`dist/${name}/package.json`).write(
|
|
JSON.stringify(
|
|
{
|
|
name,
|
|
version: Script.version,
|
|
os: [item.os],
|
|
cpu: [item.arch],
|
|
repository: {
|
|
type: "git",
|
|
url: "https://github.com/Kilo-Org/kilocode",
|
|
},
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
)
|
|
binaries[name] = Script.version
|
|
}
|
|
|
|
if (Script.release) {
|
|
const archives: string[] = [] // kilocode_change
|
|
for (const key of Object.keys(binaries)) {
|
|
const archive = key.replace(pkg.name, "kilo") // kilocode_change
|
|
if (key.includes("linux")) {
|
|
const out = path.resolve("dist", `${archive}.tar.gz`) // kilocode_change
|
|
await $`tar -czf ${out} *`.cwd(`dist/${key}/bin`) // kilocode_change
|
|
archives.push(out) // kilocode_change
|
|
} else {
|
|
const out = path.resolve("dist", `${archive}.zip`) // kilocode_change
|
|
await $`zip -r ${out} *`.cwd(`dist/${key}/bin`) // kilocode_change
|
|
archives.push(out) // kilocode_change
|
|
}
|
|
}
|
|
await $`gh release upload v${Script.version} ${archives} --clobber` // kilocode_change
|
|
}
|
|
|
|
export { binaries }
|