39 lines
2.5 KiB
JavaScript
39 lines
2.5 KiB
JavaScript
import { build } from "esbuild";
|
|
import { resolve, dirname } from "node:path";
|
|
import { readFileSync, readdirSync } from "node:fs";
|
|
|
|
// A private copy of the existing engine keeps dedicated matches and offline
|
|
// practice isolated from the React player's stores. No second spell interpreter.
|
|
await build({
|
|
entryPoints: ["scripts/arena-pipeline/combat-runtime.ts"],
|
|
outfile: "server/generated/arena-combat-runtime.mjs",
|
|
bundle: true,
|
|
format: "esm",
|
|
platform: "neutral",
|
|
mainFields: ["module", "main"],
|
|
target: "es2022",
|
|
// Escape catalog line breaks in string literals, preserving tooltip text
|
|
// without generating source lines that end in whitespace.
|
|
supported: { "template-literal": false },
|
|
minify: true,
|
|
define: { "import.meta.env.MODE": '"test"', "import.meta.env.DEV": "false", "import.meta.env.BASE_URL": '"/"', "process.env.NODE_ENV": '"production"' },
|
|
plugins: [{
|
|
name: "arena-engine-host",
|
|
setup(builder) {
|
|
builder.onLoad({ filter: /coaAbilityCatalogLoader\.ts$/ }, ({ path }) => {
|
|
const paths = readdirSync(resolve(dirname(path), "generated/coaAbilities")).filter((name) => name.endsWith(".json"))
|
|
.map((name) => `./generated/coaAbilities/${name}`);
|
|
return { contents: readFileSync(path, "utf8").replace(/import\.meta\.glob<[^>]+>\([^;]+\)/, `{${paths.map((name) => `${JSON.stringify(name)}: () => import(${JSON.stringify(name)})`).join(",")}}`), loader: "ts" };
|
|
});
|
|
builder.onResolve({ filter: /^zustand$/ }, () => ({ path: resolve("scripts/arena-pipeline/runtime-store.ts") }));
|
|
builder.onResolve({ filter: /^\.\/store$/ }, ({ importer }) => importer.endsWith("combatStore.ts") ? ({ path: "game-store", namespace: "arena-host" }) : undefined);
|
|
builder.onResolve({ filter: /^\.\/dungeonEncounterRuntime$/ }, ({ importer }) => importer.endsWith("combatStore.ts") ? ({ path: "encounter", namespace: "arena-host" }) : undefined);
|
|
builder.onResolve({ filter: /^\.\/onlineSessionRuntime$/ }, ({ importer }) => importer.endsWith("combatStore.ts") ? ({ path: "online", namespace: "arena-host" }) : undefined);
|
|
builder.onLoad({ filter: /.*/, namespace: "arena-host" }, ({ path }) => ({ contents: path === "game-store"
|
|
? 'export const useGameStore = { getState: () => ({ gameMode: "arena" }) };'
|
|
: path === "online" ? 'export const onlinePlayerRuntimeActors = () => []; export const onlinePlayerRuntimeActor = () => null;'
|
|
: 'export const dispatchDungeonEncounterSignal = () => {}; export const dungeonEncounterStateMatches = () => false;', loader: "js" }));
|
|
},
|
|
}],
|
|
});
|