Skip to content

Commit 92cd908

Browse files
authored
feat: add Node.js entry point and build script (#18324)
1 parent 6fcc970 commit 92cd908

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bun
2+
3+
import fs from "fs"
4+
import path from "path"
5+
import { fileURLToPath } from "url"
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
const dir = path.resolve(__dirname, "..")
10+
11+
process.chdir(dir)
12+
13+
// Load migrations from migration directories
14+
const migrationDirs = (
15+
await fs.promises.readdir(path.join(dir, "migration"), {
16+
withFileTypes: true,
17+
})
18+
)
19+
.filter((entry) => entry.isDirectory() && /^\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}/.test(entry.name))
20+
.map((entry) => entry.name)
21+
.sort()
22+
23+
const migrations = await Promise.all(
24+
migrationDirs.map(async (name) => {
25+
const file = path.join(dir, "migration", name, "migration.sql")
26+
const sql = await Bun.file(file).text()
27+
const match = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/.exec(name)
28+
const timestamp = match
29+
? Date.UTC(
30+
Number(match[1]),
31+
Number(match[2]) - 1,
32+
Number(match[3]),
33+
Number(match[4]),
34+
Number(match[5]),
35+
Number(match[6]),
36+
)
37+
: 0
38+
return { sql, timestamp, name }
39+
}),
40+
)
41+
console.log(`Loaded ${migrations.length} migrations`)
42+
43+
await Bun.build({
44+
target: "node",
45+
entrypoints: ["./src/node.ts"],
46+
outdir: "./dist",
47+
format: "esm",
48+
external: ["jsonc-parser"],
49+
define: {
50+
OPENCODE_MIGRATIONS: JSON.stringify(migrations),
51+
},
52+
})
53+
54+
console.log("Build complete")

packages/opencode/src/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Server } from "./server/server"

0 commit comments

Comments
 (0)