feat: add module build service with nasher compile and pack
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { runEphemeralContainer } from "./docker.service.js";
|
||||
import {
|
||||
getWorkspacePath,
|
||||
getServerPath,
|
||||
} from "./workspace.service.js";
|
||||
import { broadcast } from "./ws.service.js";
|
||||
|
||||
export async function buildModule(
|
||||
target: string = "bare",
|
||||
mode: "compile" | "pack" = "compile",
|
||||
): Promise<{ success: boolean; output: string }> {
|
||||
const workspacePath = getWorkspacePath();
|
||||
const cmd =
|
||||
mode === "compile"
|
||||
? ["nasher", "compile", target, "--yes"]
|
||||
: ["nasher", "pack", target, "--yes"];
|
||||
|
||||
broadcast("build", "start", { type: "module", target, mode });
|
||||
|
||||
const result = await runEphemeralContainer({
|
||||
image: "layonara-builder",
|
||||
cmd,
|
||||
binds: [
|
||||
`${workspacePath}/repos/nwn-module:/build/nwn-module`,
|
||||
`${workspacePath}/server/modules:/output/modules`,
|
||||
],
|
||||
workingDir: "/build/nwn-module",
|
||||
});
|
||||
|
||||
const success = result.statusCode === 0;
|
||||
broadcast("build", success ? "complete" : "failed", {
|
||||
type: "module",
|
||||
target,
|
||||
mode,
|
||||
exitCode: result.statusCode,
|
||||
});
|
||||
|
||||
if (success && mode === "pack") {
|
||||
broadcast("build", "info", { message: "Module packed successfully" });
|
||||
}
|
||||
|
||||
return { success, output: result.output };
|
||||
}
|
||||
Reference in New Issue
Block a user