2023-12-09 00:00:47 +01:00
|
|
|
// Delete dist directory
|
2024-04-07 10:56:15 +02:00
|
|
|
import { $ } from "bun";
|
2024-04-07 13:45:15 +02:00
|
|
|
import { exists, mkdir, rm } from "node:fs/promises";
|
2024-03-13 09:10:32 +01:00
|
|
|
import { rawRoutes } from "~routes";
|
2024-03-12 19:27:50 +01:00
|
|
|
|
2023-12-09 02:51:48 +01:00
|
|
|
if (!(await exists("./pages/dist"))) {
|
2024-04-07 07:30:49 +02:00
|
|
|
console.log("Please build the Vite server first, or use `bun prod-build`");
|
|
|
|
|
process.exit(1);
|
2023-12-09 02:51:48 +01:00
|
|
|
}
|
2023-12-09 00:00:47 +01:00
|
|
|
|
2023-12-09 03:56:00 +01:00
|
|
|
console.log(`Building at ${process.cwd()}`);
|
|
|
|
|
|
2023-12-09 00:00:47 +01:00
|
|
|
await rm("./dist", { recursive: true });
|
|
|
|
|
|
2024-04-07 07:30:49 +02:00
|
|
|
await mkdir(`${process.cwd()}/dist`);
|
2023-12-09 03:59:02 +01:00
|
|
|
|
2023-12-08 09:25:31 +01:00
|
|
|
await Bun.build({
|
2024-04-07 07:30:49 +02:00
|
|
|
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,
|
2024-04-07 10:56:15 +02:00
|
|
|
minify: false,
|
2024-04-07 15:14:51 +02:00
|
|
|
external: ["bullmq", "@prisma/client", "sharp"],
|
2024-04-07 07:30:49 +02:00
|
|
|
}).then((output) => {
|
|
|
|
|
if (!output.success) {
|
|
|
|
|
console.log(output.logs);
|
|
|
|
|
}
|
2023-12-08 09:25:31 +01:00
|
|
|
});
|
2023-12-09 02:51:48 +01:00
|
|
|
|
2024-04-07 10:56:15 +02:00
|
|
|
// 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`;
|
|
|
|
|
|
2024-04-07 11:22:45 +02:00
|
|
|
// Copy generated Prisma client to dist
|
2024-04-07 13:00:52 +02:00
|
|
|
await $`mkdir -p dist/node_modules/@prisma`;
|
|
|
|
|
await $`cp -r ${process.cwd()}/node_modules/@prisma dist/node_modules/`;
|
2024-04-07 11:22:45 +02:00
|
|
|
await $`cp -r ${process.cwd()}/node_modules/.prisma dist/node_modules`;
|
2024-04-07 12:58:17 +02:00
|
|
|
await $`mkdir -p dist/node_modules/.bin`;
|
|
|
|
|
await $`cp -r ${process.cwd()}/node_modules/.bin/prisma dist/node_modules/.bin`;
|
|
|
|
|
await $`cp -r ${process.cwd()}/node_modules/prisma dist/node_modules/`;
|
2024-04-07 11:22:45 +02:00
|
|
|
|
2024-04-07 15:19:21 +02:00
|
|
|
// Copy Sharp to dist
|
|
|
|
|
await $`cp -r ${process.cwd()}/node_modules/@img dist/node_modules/`;
|
|
|
|
|
await $`cp -r ${process.cwd()}/node_modules/sharp dist/node_modules/`;
|
|
|
|
|
|
2023-12-09 02:51:48 +01:00
|
|
|
// Create pages directory
|
2024-04-07 13:45:15 +02:00
|
|
|
await $`mkdir -p dist/pages/dist`;
|
2023-12-09 02:51:48 +01:00
|
|
|
|
|
|
|
|
// Copy Vite build output to dist
|
2024-04-07 13:45:15 +02:00
|
|
|
await $`cp -r ${process.cwd()}/pages/dist dist/pages/`;
|
2023-12-09 03:59:02 +01:00
|
|
|
|
2024-03-13 09:10:32 +01:00
|
|
|
// Copy the Bee Movie script from pages
|
2024-04-07 13:45:15 +02:00
|
|
|
await $`cp ${process.cwd()}/pages/beemovie.txt dist/pages/beemovie.txt`;
|
2024-03-13 09:10:32 +01:00
|
|
|
|
2024-04-07 07:30:49 +02:00
|
|
|
console.log("Built!");
|