mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
// Delete dist directory
|
|
import { $ } from "bun";
|
|
import { cp, exists, mkdir, rm } from "node:fs/promises";
|
|
import { rawRoutes } from "~routes";
|
|
|
|
if (!(await exists("./pages/dist"))) {
|
|
console.log("Please build the Vite server first, or use `bun prod-build`");
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`Building at ${process.cwd()}`);
|
|
|
|
await rm("./dist", { recursive: true });
|
|
|
|
await mkdir(`${process.cwd()}/dist`);
|
|
|
|
await Bun.build({
|
|
entrypoints: [
|
|
`${process.cwd()}/index.ts`,
|
|
`${process.cwd()}/prisma.ts`,
|
|
`${process.cwd()}/cli.ts`,
|
|
// Force Bun to include endpoints
|
|
...Object.values(rawRoutes),
|
|
],
|
|
outdir: `${process.cwd()}/dist`,
|
|
target: "bun",
|
|
splitting: true,
|
|
minify: false,
|
|
external: ["bullmq"],
|
|
}).then((output) => {
|
|
if (!output.success) {
|
|
console.log(output.logs);
|
|
}
|
|
});
|
|
|
|
// Fix for wrong Bun file resolution, replaces node_modules with ./node_modules inside all dynamic imports
|
|
// I apologize for this
|
|
await $`sed -i 's|import("node_modules/|import("./node_modules/|g' dist/*.js`;
|
|
|
|
// Create pages directory
|
|
// mkdir ./dist/pages
|
|
await mkdir(`${process.cwd()}/dist/pages`);
|
|
|
|
// Copy Vite build output to dist
|
|
// cp -r ./pages/dist ./dist/pages
|
|
await cp(`${process.cwd()}/pages/dist`, `${process.cwd()}/dist/pages/`, {
|
|
recursive: true,
|
|
});
|
|
|
|
// Copy the Bee Movie script from pages
|
|
await cp(
|
|
`${process.cwd()}/pages/beemovie.txt`,
|
|
`${process.cwd()}/dist/pages/beemovie.txt`,
|
|
);
|
|
|
|
console.log("Built!");
|