dev-snapshot.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import { join, dirname } from "node:path"
  4. import { tmpdir } from "node:os"
  5. import { rmSync, mkdirSync, existsSync } from "node:fs"
  6. const mode = process.argv[2] ?? "install"
  7. const shouldInstall = mode === "install"
  8. const root = join(import.meta.dir, "..")
  9. const pkgPath = join(root, "package.json")
  10. const pkg = await Bun.file(pkgPath).json()
  11. const sha = (await $`git rev-parse --short HEAD`.text()).trim()
  12. const user =
  13. (await $`git config --get --default local user.name`.text())
  14. .trim()
  15. .toLowerCase()
  16. .replace(/[^a-z0-9]+/g, "-")
  17. .replace(/^-+|-+$/g, "") || "local"
  18. const snapshotVersion = `${pkg.version}-snapshot+${sha}.${user}`
  19. console.log(`Building snapshot version: ${snapshotVersion}`)
  20. console.log(`Base version: ${pkg.version}`)
  21. console.log(`Commit: ${sha}`)
  22. console.log(`Mode: ${mode}\n`)
  23. console.log("🧹 Cleaning build directories...")
  24. for (const dir of ["bin", "dist"]) {
  25. const dirPath = join(root, dir)
  26. if (existsSync(dirPath)) {
  27. rmSync(dirPath, { recursive: true, force: true })
  28. console.log(` ✓ Cleaned ${dir}/`)
  29. }
  30. }
  31. const outDir = join(tmpdir(), "kilo-vscode-snapshots")
  32. mkdirSync(outDir, { recursive: true })
  33. console.log("\n📦 Rebuilding SDK...")
  34. await $`bun run --cwd ../sdk/js build`.cwd(root)
  35. console.log("\n🔧 Preparing CLI binary...")
  36. await $`bun script/local-bin.ts`.cwd(root)
  37. console.log("\n✅ Type-checking...")
  38. await $`bun run typecheck`.cwd(root)
  39. console.log("\n🔍 Linting...")
  40. await $`bun run lint`.cwd(root)
  41. console.log("\n🏗️ Building extension...")
  42. await $`node ${join(root, "esbuild.js")} --production`.cwd(root)
  43. console.log("\n📦 Packaging VSIX...")
  44. const vsixPath = join(outDir, `kilo-vscode-snapshot-${sha}-${user}.vsix`)
  45. await $`bunx vsce package ${snapshotVersion} --no-update-package-json --no-dependencies --skip-license -o ${vsixPath}`.cwd(
  46. root,
  47. )
  48. if (shouldInstall) {
  49. const execPath = process.env.VSCODE_EXEC_PATH ?? ""
  50. const isInsiders = execPath.toLowerCase().includes("insiders")
  51. const name = isInsiders ? "code-insiders" : "code"
  52. const winPath = process.platform === "win32" && execPath ? join(dirname(execPath), "bin", name + ".cmd") : ""
  53. const cli = winPath && existsSync(winPath) ? winPath : name
  54. console.log(`\n🚀 Installing to ${cli}...`)
  55. await $`${cli} --force --install-extension ${vsixPath}`
  56. console.log(`\n✅ Successfully installed snapshot extension!`)
  57. console.log(` Version: ${snapshotVersion}`)
  58. }