Improve incremental build time

This commit is contained in:
Joseph Garrone
2024-07-13 09:26:48 +02:00
parent 2d7f21b021
commit 6d82a74db4

View File

@ -45,20 +45,21 @@ export async function buildJar(params: {
buildContext buildContext
} = params; } = params;
const keycloakifyBuildTmpDirPath = pathJoin( const keycloakifyBuildCacheDirPath = pathJoin(
buildContext.cacheDirPath, buildContext.cacheDirPath,
"maven",
jarFileBasename.replace(".jar", "") jarFileBasename.replace(".jar", "")
); );
rmSync(keycloakifyBuildTmpDirPath, { recursive: true, force: true });
const tmpResourcesDirPath = pathJoin( const tmpResourcesDirPath = pathJoin(
keycloakifyBuildTmpDirPath, keycloakifyBuildCacheDirPath,
"src", "src",
"main", "main",
"resources" "resources"
); );
rmSync(tmpResourcesDirPath, { recursive: true, force: true });
transformCodebase({ transformCodebase({
srcDirPath: resourcesDirPath, srcDirPath: resourcesDirPath,
destDirPath: tmpResourcesDirPath, destDirPath: tmpResourcesDirPath,
@ -155,10 +156,7 @@ export async function buildJar(params: {
(["register.ftl", "login-update-profile.ftl"] as const).forEach(pageId => (["register.ftl", "login-update-profile.ftl"] as const).forEach(pageId =>
buildContext.themeNames.map(themeName => { buildContext.themeNames.map(themeName => {
const ftlFilePath = pathJoin( const ftlFilePath = pathJoin(
keycloakifyBuildTmpDirPath, tmpResourcesDirPath,
"src",
"main",
"resources",
"theme", "theme",
themeName, themeName,
"login", "login",
@ -200,15 +198,15 @@ export async function buildJar(params: {
}); });
await fs.writeFile( await fs.writeFile(
pathJoin(keycloakifyBuildTmpDirPath, "pom.xml"), pathJoin(keycloakifyBuildCacheDirPath, "pom.xml"),
Buffer.from(pomFileCode, "utf8") Buffer.from(pomFileCode, "utf8")
); );
} }
await new Promise<void>((resolve, reject) => await new Promise<void>((resolve, reject) =>
child_process.exec( child_process.exec(
`mvn clean install -Dmaven.repo.local="${pathJoin(keycloakifyBuildTmpDirPath, ".m2")}"`, `mvn install -Dmaven.repo.local="${pathJoin(keycloakifyBuildCacheDirPath, ".m2")}"`,
{ cwd: keycloakifyBuildTmpDirPath }, { cwd: keycloakifyBuildCacheDirPath },
error => { error => {
if (error !== null) { if (error !== null) {
console.error( console.error(
@ -233,12 +231,10 @@ export async function buildJar(params: {
await fs.rename( await fs.rename(
pathJoin( pathJoin(
keycloakifyBuildTmpDirPath, keycloakifyBuildCacheDirPath,
"target", "target",
`${buildContext.artifactId}-${buildContext.themeVersion}.jar` `${buildContext.artifactId}-${buildContext.themeVersion}.jar`
), ),
pathJoin(buildContext.keycloakifyBuildDirPath, jarFileBasename) pathJoin(buildContext.keycloakifyBuildDirPath, jarFileBasename)
); );
rmSync(keycloakifyBuildTmpDirPath, { recursive: true });
} }