2024-06-10 09:24:16 +02:00
|
|
|
import { onlyBuildJarFileBasenameEnvName } from "../shared/constants";
|
2024-05-26 17:58:41 +02:00
|
|
|
import * as child_process from "child_process";
|
|
|
|
import { Deferred } from "evt/tools/Deferred";
|
|
|
|
import { assert } from "tsafe/assert";
|
2024-06-09 09:15:16 +02:00
|
|
|
import type { BuildContext } from "../shared/buildContext";
|
2024-05-26 17:58:41 +02:00
|
|
|
|
2024-06-09 09:15:16 +02:00
|
|
|
export type BuildContextLike = {
|
2024-06-09 09:03:43 +02:00
|
|
|
projectDirPath: string;
|
2024-05-26 17:58:41 +02:00
|
|
|
keycloakifyBuildDirPath: string;
|
|
|
|
bundler: "vite" | "webpack";
|
|
|
|
npmWorkspaceRootDirPath: string;
|
|
|
|
};
|
|
|
|
|
2024-06-09 09:15:16 +02:00
|
|
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
2024-05-26 17:58:41 +02:00
|
|
|
|
|
|
|
export async function keycloakifyBuild(params: {
|
2024-06-10 09:24:16 +02:00
|
|
|
onlyBuildJarFileBasename: string | undefined;
|
2024-06-09 09:15:16 +02:00
|
|
|
buildContext: BuildContextLike;
|
2024-05-26 17:58:41 +02:00
|
|
|
}): Promise<{ isKeycloakifyBuildSuccess: boolean }> {
|
2024-06-10 09:24:16 +02:00
|
|
|
const { buildContext, onlyBuildJarFileBasename } = params;
|
2024-05-26 17:58:41 +02:00
|
|
|
|
|
|
|
const dResult = new Deferred<{ isSuccess: boolean }>();
|
|
|
|
|
|
|
|
const child = child_process.spawn("npx", ["keycloakify", "build"], {
|
2024-06-09 09:15:16 +02:00
|
|
|
cwd: buildContext.projectDirPath,
|
2024-05-26 17:58:41 +02:00
|
|
|
env: {
|
|
|
|
...process.env,
|
2024-06-10 09:24:16 +02:00
|
|
|
[onlyBuildJarFileBasenameEnvName]: onlyBuildJarFileBasename
|
2024-05-26 17:58:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
child.stdout.on("data", data => process.stdout.write(data));
|
|
|
|
|
|
|
|
child.stderr.on("data", data => process.stderr.write(data));
|
|
|
|
|
|
|
|
child.on("exit", code => dResult.resolve({ isSuccess: code === 0 }));
|
|
|
|
|
|
|
|
const { isSuccess } = await dResult.pr;
|
|
|
|
|
|
|
|
return { isKeycloakifyBuildSuccess: isSuccess };
|
|
|
|
}
|