server/packages/api/build.ts

68 lines
2 KiB
TypeScript
Raw Normal View History

import { readdir } from "node:fs/promises";
2025-05-01 16:27:34 +02:00
import { $, build } from "bun";
import { routes } from "./routes.ts";
2024-03-12 19:27:50 +01:00
2025-05-01 16:27:34 +02:00
console.log("Building...");
2024-04-09 13:14:53 +02:00
await $`rm -rf dist && mkdir dist`;
2023-12-09 03:59:02 +01:00
// Get all directories under the plugins/ directory
const pluginDirs = await readdir("plugins", { withFileTypes: true });
await build({
2024-04-07 07:30:49 +02:00
entrypoints: [
"packages/api/index.ts",
// HACK: Include to avoid cyclical import errors
"packages/config/index.ts",
"cli/index.ts",
2024-04-07 07:30:49 +02:00
// Force Bun to include endpoints
...Object.values(routes),
// Include all plugins
...pluginDirs
.filter((dir) => dir.isDirectory())
.map((dir) => `plugins/${dir.name}/index.ts`),
2024-04-07 07:30:49 +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,
external: ["acorn", "@bull-board/ui"],
});
2025-05-01 16:27:34 +02:00
console.log("Copying files...");
// Fix Bun build mistake
await $`sed -i 's/ProxiableUrl, url, sensitiveString, keyPair, exportedConfig/url, sensitiveString, keyPair, exportedConfig/g' dist/packages/config/*.js`;
// Copy Drizzle stuff
await $`mkdir -p dist/packages/plugin-kit/tables`;
await $`cp -rL packages/plugin-kit/tables/migrations dist/packages/plugin-kit/tables`;
2024-04-14 03:26:19 +02:00
// Copy plugin manifests
await $`cp plugins/openid/manifest.json dist/plugins/openid/manifest.json`;
await $`mkdir -p dist/node_modules`;
// Copy Sharp to dist
await $`mkdir -p dist/node_modules/@img`;
await $`cp -rL node_modules/@img/sharp-libvips-linux* dist/node_modules/@img`;
await $`cp -rL node_modules/@img/sharp-linux* dist/node_modules/@img`;
// Copy acorn to dist
await $`cp -rL node_modules/acorn dist/node_modules/acorn`;
// Copy bull-board to dist
await $`mkdir -p dist/node_modules/@bull-board`;
await $`cp -rL 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
// Copy package.json
await $`cp package.json dist/package.json`;
// Fixes issues with sharp
await $`cp -rL node_modules/detect-libc dist/node_modules/`;
2025-05-01 16:27:34 +02:00
console.log("Build complete!");