-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild.ts
36 lines (31 loc) Β· 1.06 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { build, $ } from "bun"
import { resolve } from "path"
import { version } from "../package.json"
// https://coolify.io/docs/knowledge-base/environment-variables/
const commitHash =
process.env["SOURCE_COMMIT"] || (await $`git rev-parse HEAD`.quiet()).text().trim().slice(0, 7) || "N/A"
// Migrate if run in production
if (process.env.NODE_ENV === "production") {
console.info(`π§ Migrating...`)
try {
await $`bun scripts/migrate.ts`.quiet()
} catch (error) {
console.error("π¨ Error migrating:", error)
process.exit(1)
}
}
console.info(`π§ Building...`)
await Bun.build({
entrypoints: [resolve(__dirname, "../src/index.ts")],
outdir: resolve(__dirname, "../dist"),
target: "bun",
external: ["@aws-sdk/*", "sharp"],
sourcemap: "external",
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
"process.env.BUILD_DATE": JSON.stringify(new Date().toISOString()),
"process.env.GIT_COMMIT_HASH": JSON.stringify(commitHash),
"process.env.VERSION": JSON.stringify(version),
},
})
console.info(`β
Build complete`)