2024-08-29 20:32:04 +02:00
|
|
|
import { readdir } from "node:fs/promises";
|
2024-04-07 10:56:15 +02:00
|
|
|
import { $ } from "bun";
|
2024-05-08 02:10:42 +02:00
|
|
|
import ora from "ora";
|
2024-05-29 02:59:49 +02:00
|
|
|
import { routes } from "~/routes";
|
2024-03-12 19:27:50 +01:00
|
|
|
|
2024-05-08 02:10:42 +02:00
|
|
|
const buildSpinner = ora("Building").start();
|
2023-12-09 00:00:47 +01:00
|
|
|
|
2024-04-09 13:14:53 +02:00
|
|
|
await $`rm -rf dist && mkdir dist`;
|
2023-12-09 03:59:02 +01:00
|
|
|
|
2024-08-29 20:32:04 +02:00
|
|
|
// Get all directories under the plugins/ directory
|
|
|
|
|
const pluginDirs = await readdir("plugins", { withFileTypes: true });
|
|
|
|
|
|
2023-12-08 09:25:31 +01:00
|
|
|
await Bun.build({
|
2024-04-07 07:30:49 +02:00
|
|
|
entrypoints: [
|
2024-05-08 02:10:42 +02:00
|
|
|
"index.ts",
|
|
|
|
|
"cli/index.ts",
|
2024-04-07 07:30:49 +02:00
|
|
|
// Force Bun to include endpoints
|
2024-04-16 09:13:34 +02:00
|
|
|
...Object.values(routes),
|
2024-08-29 20:32:04 +02:00
|
|
|
// Include all plugins
|
|
|
|
|
...pluginDirs
|
|
|
|
|
.filter((dir) => dir.isDirectory())
|
|
|
|
|
.map((dir) => `plugins/${dir.name}/index.ts`),
|
2024-04-07 07:30:49 +02:00
|
|
|
],
|
2024-05-08 02:10:42 +02:00
|
|
|
outdir: "dist",
|
2024-04-07 07:30:49 +02:00
|
|
|
target: "bun",
|
|
|
|
|
splitting: true,
|
2024-04-14 13:37:32 +02:00
|
|
|
minify: false,
|
2024-11-25 13:24:14 +01:00
|
|
|
external: ["unzipit", "acorn", "@bull-board/ui"],
|
2024-04-07 07:30:49 +02:00
|
|
|
}).then((output) => {
|
|
|
|
|
if (!output.success) {
|
2024-06-29 08:49:17 +02:00
|
|
|
console.error(output.logs);
|
2024-10-03 11:59:26 +02:00
|
|
|
throw new Error("Build failed");
|
2024-04-07 07:30:49 +02:00
|
|
|
}
|
2023-12-08 09:25:31 +01:00
|
|
|
});
|
2023-12-09 02:51:48 +01:00
|
|
|
|
2024-05-08 02:10:42 +02:00
|
|
|
buildSpinner.text = "Transforming";
|
|
|
|
|
|
2024-11-25 13:09:28 +01:00
|
|
|
// Fix Bun incorrectly transforming aliased imports
|
|
|
|
|
await $`sed -i 's/var serveStatic = (options) => {/var serveStaticBase = (options) => {/g' dist/index.js`;
|
|
|
|
|
await $`sed -i 's/ return serveStatic({/ return serveStaticBase({/g' dist/index.js`;
|
|
|
|
|
|
2024-04-14 03:26:19 +02:00
|
|
|
// Copy Drizzle migrations to dist
|
|
|
|
|
await $`cp -r drizzle dist/drizzle`;
|
|
|
|
|
|
2024-09-24 14:42:39 +02:00
|
|
|
// Copy plugin manifests
|
|
|
|
|
await $`cp plugins/openid/manifest.json dist/plugins/openid/manifest.json`;
|
|
|
|
|
|
2024-04-07 15:19:21 +02:00
|
|
|
// Copy Sharp to dist
|
2024-04-09 14:51:03 +02:00
|
|
|
await $`mkdir -p dist/node_modules/@img`;
|
2024-11-23 14:35:04 +01:00
|
|
|
await $`cp -r node_modules/@img/sharp-libvips-linuxmusl-* dist/node_modules/@img`;
|
|
|
|
|
await $`cp -r node_modules/@img/sharp-linuxmusl-* dist/node_modules/@img`;
|
2024-04-07 15:19:21 +02:00
|
|
|
|
2024-05-09 04:29:41 +02:00
|
|
|
// Copy unzipit and uzip-module to dist
|
|
|
|
|
await $`cp -r node_modules/unzipit dist/node_modules/unzipit`;
|
|
|
|
|
await $`cp -r node_modules/uzip-module dist/node_modules/uzip-module`;
|
2024-09-24 14:42:39 +02:00
|
|
|
|
2024-06-29 13:27:03 +02:00
|
|
|
// Copy acorn to dist
|
|
|
|
|
await $`cp -r node_modules/acorn dist/node_modules/acorn`;
|
2024-05-09 04:29:41 +02:00
|
|
|
|
2024-11-25 13:24:14 +01:00
|
|
|
// Copy bull-board to dist
|
|
|
|
|
await $`mkdir -p dist/node_modules/@bull-board`;
|
|
|
|
|
await $`cp -r node_modules/@bull-board/ui dist/node_modules/@bull-board/ui`;
|
|
|
|
|
|
2024-03-13 09:10:32 +01:00
|
|
|
// Copy the Bee Movie script from pages
|
2024-04-09 13:55:03 +02:00
|
|
|
await $`cp beemovie.txt dist/beemovie.txt`;
|
2024-03-13 09:10:32 +01:00
|
|
|
|
2024-05-08 02:35:00 +02:00
|
|
|
// Copy package.json
|
|
|
|
|
await $`cp package.json dist/package.json`;
|
2024-05-08 09:26:17 +02:00
|
|
|
// Copy cli/theme.json
|
|
|
|
|
await $`cp cli/theme.json dist/cli/theme.json`;
|
2024-05-08 02:35:00 +02:00
|
|
|
|
2024-05-08 02:10:42 +02:00
|
|
|
buildSpinner.stop();
|