Refactor checkpoint
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
import { downloadKeycloakDefaultTheme } from "./shared/downloadKeycloakDefaultTheme";
|
||||
import { join as pathJoin, relative as pathRelative } from "path";
|
||||
import { transformCodebase } from "./tools/transformCodebase";
|
||||
import { promptKeycloakVersion } from "./shared/promptKeycloakVersion";
|
||||
import { getBuildContext } from "./shared/buildContext";
|
||||
import * as fs from "fs";
|
||||
import type { CliCommandOptions } from "./main";
|
||||
import { downloadAndExtractArchive } from "./tools/downloadAndExtractArchive";
|
||||
|
||||
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
||||
const { cliCommandOptions } = params;
|
||||
@ -13,9 +13,12 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
||||
|
||||
const emailThemeSrcDirPath = pathJoin(buildContext.themeSrcDirPath, "email");
|
||||
|
||||
if (fs.existsSync(emailThemeSrcDirPath)) {
|
||||
if (
|
||||
fs.existsSync(emailThemeSrcDirPath) &&
|
||||
fs.readdirSync(emailThemeSrcDirPath).length > 0
|
||||
) {
|
||||
console.warn(
|
||||
`There is already a ${pathRelative(
|
||||
`There is already a non empty ${pathRelative(
|
||||
process.cwd(),
|
||||
emailThemeSrcDirPath
|
||||
)} directory in your project. Aborting.`
|
||||
@ -34,13 +37,27 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
||||
buildContext
|
||||
});
|
||||
|
||||
const { defaultThemeDirPath } = await downloadKeycloakDefaultTheme({
|
||||
keycloakVersion,
|
||||
buildContext
|
||||
const { extractedDirPath } = await downloadAndExtractArchive({
|
||||
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
||||
cacheDirPath: buildContext.cacheDirPath,
|
||||
fetchOptions: buildContext.fetchOptions,
|
||||
uniqueIdOfOnArchiveFile: "extractOnlyEmailTheme",
|
||||
onArchiveFile: async ({ fileRelativePath, writeFile }) => {
|
||||
const fileRelativePath_target = pathRelative(
|
||||
pathJoin("theme", "base", "email"),
|
||||
fileRelativePath
|
||||
);
|
||||
|
||||
if (fileRelativePath_target.startsWith("..")) {
|
||||
return;
|
||||
}
|
||||
|
||||
await writeFile({ fileRelativePath: fileRelativePath_target });
|
||||
}
|
||||
});
|
||||
|
||||
transformCodebase({
|
||||
srcDirPath: pathJoin(defaultThemeDirPath, "base", "email"),
|
||||
srcDirPath: extractedDirPath,
|
||||
destDirPath: emailThemeSrcDirPath
|
||||
});
|
||||
|
||||
|
@ -7,7 +7,6 @@ import { join as pathJoin, dirname as pathDirname } from "path";
|
||||
import { transformCodebase } from "../../tools/transformCodebase";
|
||||
import type { BuildContext } from "../../shared/buildContext";
|
||||
import * as fs from "fs/promises";
|
||||
import { ACCOUNT_V1_THEME_NAME } from "../../shared/constants";
|
||||
import {
|
||||
generatePom,
|
||||
BuildContextLike as BuildContextLike_generatePom
|
||||
@ -75,7 +74,7 @@ export async function buildJar(params: {
|
||||
|
||||
if (
|
||||
isInside({
|
||||
dirPath: pathJoin("theme", ACCOUNT_V1_THEME_NAME),
|
||||
dirPath: pathJoin("theme", "account-v1"),
|
||||
filePath: fileRelativePath
|
||||
})
|
||||
) {
|
||||
@ -90,10 +89,7 @@ export async function buildJar(params: {
|
||||
const modifiedSourceCode = Buffer.from(
|
||||
sourceCode
|
||||
.toString("utf8")
|
||||
.replace(
|
||||
`parent=${ACCOUNT_V1_THEME_NAME}`,
|
||||
"parent=keycloak"
|
||||
),
|
||||
.replace(`parent=account-v1`, "parent=keycloak"),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
@ -126,7 +122,7 @@ export async function buildJar(params: {
|
||||
assert(metaInfKeycloakTheme !== undefined);
|
||||
|
||||
metaInfKeycloakTheme.themes = metaInfKeycloakTheme.themes.filter(
|
||||
({ name }) => name !== ACCOUNT_V1_THEME_NAME
|
||||
({ name }) => name !== "account-v1"
|
||||
);
|
||||
|
||||
return metaInfKeycloakTheme;
|
||||
|
@ -254,7 +254,8 @@ export async function generateResourcesForMainTheme(params: {
|
||||
transformCodebase({
|
||||
srcDirPath: pathJoin(
|
||||
getThisCodebaseRootDirPath(),
|
||||
WELL_KNOWN_DIRECTORY_BASE_NAME.RESOURCES,
|
||||
"public",
|
||||
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY,
|
||||
themeType
|
||||
),
|
||||
destDirPath: pathJoin(themeTypeDirPath, "resources")
|
||||
@ -309,10 +310,7 @@ export async function generateResourcesForMainTheme(params: {
|
||||
}
|
||||
|
||||
transformCodebase({
|
||||
srcDirPath: pathJoin(
|
||||
getThisCodebaseRootDirPath(),
|
||||
WELL_KNOWN_DIRECTORY_BASE_NAME.ACCOUNT_V1
|
||||
),
|
||||
srcDirPath: pathJoin(getThisCodebaseRootDirPath(), "account-v1"),
|
||||
destDirPath: pathJoin(resourcesDirPath, "theme", "account-v1", "account")
|
||||
});
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
export const WELL_KNOWN_DIRECTORY_BASE_NAME = {
|
||||
DOT_KEYCLOAKIFY: ".keycloakify",
|
||||
RESOURCES_COMMON: "resources-common",
|
||||
DIST: "dist",
|
||||
RESOURCES: "resources",
|
||||
ACCOUNT_V1: "account-v1"
|
||||
};
|
||||
DIST: "dist"
|
||||
} as const;
|
||||
|
||||
export const THEME_TYPES = ["login", "account"] as const;
|
||||
|
||||
|
@ -65,7 +65,8 @@ export function copyKeycloakResourcesToPublic(params: {
|
||||
transformCodebase({
|
||||
srcDirPath: pathJoin(
|
||||
getThisCodebaseRootDirPath(),
|
||||
WELL_KNOWN_DIRECTORY_BASE_NAME.RESOURCES
|
||||
"public",
|
||||
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY
|
||||
),
|
||||
destDirPath
|
||||
});
|
||||
|
@ -2,7 +2,7 @@ import { getBuildContext } from "../shared/buildContext";
|
||||
import { exclude } from "tsafe/exclude";
|
||||
import type { CliCommandOptions as CliCommandOptions_common } from "../main";
|
||||
import { promptKeycloakVersion } from "../shared/promptKeycloakVersion";
|
||||
import { ACCOUNT_V1_THEME_NAME, CONTAINER_NAME } from "../shared/constants";
|
||||
import { CONTAINER_NAME } from "../shared/constants";
|
||||
import { SemVer } from "../tools/SemVer";
|
||||
import { assert, type Equals } from "tsafe/assert";
|
||||
import * as fs from "fs";
|
||||
@ -409,13 +409,9 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
||||
...[
|
||||
...buildContext.themeNames,
|
||||
...(fs.existsSync(
|
||||
pathJoin(
|
||||
buildContext.keycloakifyBuildDirPath,
|
||||
"theme",
|
||||
ACCOUNT_V1_THEME_NAME
|
||||
)
|
||||
pathJoin(buildContext.keycloakifyBuildDirPath, "theme", "account-v1")
|
||||
)
|
||||
? [ACCOUNT_V1_THEME_NAME]
|
||||
? ["account-v1"]
|
||||
: [])
|
||||
]
|
||||
.map(themeName => ({
|
||||
|
Reference in New Issue
Block a user