120 lines
6.0 KiB
TypeScript
Raw Normal View History

import { generateTheme } from "./generateTheme";
2024-02-05 08:52:58 +01:00
import { generatePom } from "./generatePom";
2023-11-30 22:36:58 +01:00
import { join as pathJoin, relative as pathRelative, basename as pathBasename, dirname as pathDirname, sep as pathSep } from "path";
import * as child_process from "child_process";
2022-04-09 20:17:20 +02:00
import { generateStartKeycloakTestingContainer } from "./generateStartKeycloakTestingContainer";
import * as fs from "fs";
2024-01-30 06:38:26 +01:00
import { readBuildOptions } from "./buildOptions";
2022-09-08 12:06:26 +03:00
import { getLogger } from "../tools/logger";
import { assert } from "tsafe/assert";
2024-01-30 06:37:49 +01:00
import { getThemeSrcDirPath } from "../getThemeSrcDirPath";
import { getProjectRoot } from "../tools/getProjectRoot";
export async function main() {
2023-04-02 03:10:16 +02:00
const buildOptions = readBuildOptions({
"processArgv": process.argv.slice(2)
2022-08-16 14:41:06 +07:00
});
const logger = getLogger({ "isSilent": buildOptions.isSilent });
logger.log("🔏 Building the keycloak theme...⌚");
const keycloakifyDirPath = getProjectRoot();
2023-03-24 06:25:25 +01:00
const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath });
for (const themeName of buildOptions.themeNames) {
await generateTheme({
themeName,
themeSrcDirPath,
"keycloakifySrcDirPath": pathJoin(keycloakifyDirPath, "src"),
buildOptions,
2023-06-08 23:09:14 +02:00
"keycloakifyVersion": (() => {
const version = JSON.parse(fs.readFileSync(pathJoin(keycloakifyDirPath, "package.json")).toString("utf8"))["version"];
2023-06-08 23:09:14 +02:00
assert(typeof version === "string");
return version;
})()
});
}
2024-02-05 08:52:58 +01:00
{
const { pomFileCode } = generatePom({ buildOptions });
fs.writeFileSync(pathJoin(buildOptions.keycloakifyBuildDirPath, "pom.xml"), Buffer.from(pomFileCode, "utf8"));
}
const jarFilePath = pathJoin(buildOptions.keycloakifyBuildDirPath, "target", `${buildOptions.artifactId}-${buildOptions.themeVersion}.jar`);
2023-09-04 00:25:36 +02:00
if (buildOptions.doCreateJar) {
child_process.execSync("mvn clean install", { "cwd": buildOptions.keycloakifyBuildDirPath });
2023-11-30 22:36:58 +01:00
const jarDirPath = pathDirname(jarFilePath);
const retrocompatJarFilePath = pathJoin(jarDirPath, "retrocompat-" + pathBasename(jarFilePath));
fs.renameSync(pathJoin(jarDirPath, "original-" + pathBasename(jarFilePath)), retrocompatJarFilePath);
fs.writeFileSync(
pathJoin(jarDirPath, "README.md"),
Buffer.from(
[
`- The ${jarFilePath} is to be used in Keycloak 23 and up. `,
`- The ${retrocompatJarFilePath} is to be used in Keycloak 22 and below.`,
` Note that Keycloak 22 is only supported for login and email theme but not for account themes. `
].join("\n"),
"utf8"
)
2023-12-01 00:03:44 +01:00
);
}
const containerKeycloakVersion = "23.0.0";
2022-04-09 20:17:20 +02:00
generateStartKeycloakTestingContainer({
"keycloakVersion": containerKeycloakVersion,
jarFilePath,
buildOptions
});
2022-09-08 12:06:26 +03:00
logger.log(
[
"",
...(!buildOptions.doCreateJar
? []
: [
`✅ Your keycloak theme has been generated and bundled into .${pathSep}${pathRelative(
buildOptions.reactAppRootDirPath,
jarFilePath
)} 🚀`
]),
"",
`To test your theme locally you can spin up a Keycloak ${containerKeycloakVersion} container image with the theme pre loaded by running:`,
"",
2023-03-21 15:16:23 +01:00
`👉 $ .${pathSep}${pathRelative(
buildOptions.reactAppRootDirPath,
2023-04-02 03:10:16 +02:00
pathJoin(buildOptions.keycloakifyBuildDirPath, generateStartKeycloakTestingContainer.basename)
2023-03-21 15:16:23 +01:00
)} 👈`,
``,
`Once your container is up and running: `,
2022-04-09 20:17:20 +02:00
"- Log into the admin console 👉 http://localhost:8080/admin username: admin, password: admin 👈",
2023-04-20 18:15:03 +02:00
`- Create a realm: Master -> AddRealm -> Name: myrealm`,
`- Enable registration: Realm settings -> Login tab -> User registration: on`,
`- Enable the Account theme (optional): Realm settings -> Themes tab -> Account theme: ${buildOptions.themeNames[0]}`,
` Clients -> account -> Login theme: ${buildOptions.themeNames[0]}`,
`- Enable the email theme (optional): Realm settings -> Themes tab -> Email theme: ${buildOptions.themeNames[0]} (option will appear only if you have ran npx initialize-email-theme)`,
2023-04-20 18:15:03 +02:00
`- Create a client Clients -> Create -> Client ID: myclient`,
` Root URL: https://www.keycloak.org/app/`,
` Valid redirect URIs: https://www.keycloak.org/app* http://localhost* (localhost is optional)`,
` Valid post logout redirect URIs: https://www.keycloak.org/app* http://localhost*`,
` Web origins: *`,
` Login Theme: ${buildOptions.themeNames[0]}`,
2023-04-20 18:15:03 +02:00
` Save (button at the bottom of the page)`,
2023-03-21 23:21:30 +01:00
``,
`- Go to 👉 https://www.keycloak.org/app/ 👈 Click "Save" then "Sign in". You should see your login page`,
2023-03-21 19:44:01 +01:00
`- Got to 👉 http://localhost:8080/realms/myrealm/account 👈 to see your account theme`,
2023-03-22 01:46:05 +01:00
``,
`Video tutorial: https://youtu.be/WMyGZNHQkjU`,
2023-03-21 15:16:23 +01:00
``
].join("\n")
);
}