File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 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" )
Original file line number Diff line number Diff line change 1+ export { Server } from "./server/server"
You can’t perform that action at this time.
0 commit comments