2021-06-14 21:21:36 +02:00
|
|
|
import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources";
|
|
|
|
import { generateJavaStackFiles } from "./generateJavaStackFiles";
|
2023-03-21 15:16:23 +01:00
|
|
|
import { join as pathJoin, relative as pathRelative, basename as pathBasename, sep as pathSep } from "path";
|
2021-06-14 21:21:36 +02:00
|
|
|
import * as child_process from "child_process";
|
2022-04-09 20:17:20 +02:00
|
|
|
import { generateStartKeycloakTestingContainer } from "./generateStartKeycloakTestingContainer";
|
2022-01-18 18:52:52 +01:00
|
|
|
import * as fs from "fs";
|
2022-08-16 14:41:06 +07:00
|
|
|
import { readBuildOptions } from "./BuildOptions";
|
2022-09-08 12:06:26 +03:00
|
|
|
import { getLogger } from "../tools/logger";
|
|
|
|
import { getCliOptions } from "../tools/cliOptions";
|
2023-02-03 14:28:06 +01:00
|
|
|
import jar from "../tools/jar";
|
2023-02-04 18:02:39 +01:00
|
|
|
import { assert } from "tsafe/assert";
|
2023-03-24 05:43:34 +01:00
|
|
|
import { Equals } from "tsafe";
|
2023-04-02 03:10:16 +02:00
|
|
|
import { getEmailThemeSrcDirPath } from "../getSrcDirPath";
|
2023-04-04 01:40:55 +02:00
|
|
|
import { getProjectRoot } from "../tools/getProjectRoot";
|
2021-06-14 21:21:36 +02:00
|
|
|
|
2023-01-16 14:42:20 +01:00
|
|
|
export async function main() {
|
2022-09-08 12:06:26 +03:00
|
|
|
const { isSilent, hasExternalAssets } = getCliOptions(process.argv.slice(2));
|
|
|
|
const logger = getLogger({ isSilent });
|
|
|
|
logger.log("🔏 Building the keycloak theme...⌚");
|
2021-06-14 21:21:36 +02:00
|
|
|
|
2023-04-02 03:10:16 +02:00
|
|
|
const projectDirPath = process.cwd();
|
2022-08-20 14:04:47 +07:00
|
|
|
|
2023-04-02 03:10:16 +02:00
|
|
|
const buildOptions = readBuildOptions({
|
|
|
|
projectDirPath,
|
2022-09-08 12:06:26 +03:00
|
|
|
"isExternalAssetsCliParamProvided": hasExternalAssets,
|
|
|
|
"isSilent": isSilent
|
2022-08-16 14:41:06 +07:00
|
|
|
});
|
2021-06-23 18:03:49 +02:00
|
|
|
|
2023-01-16 14:42:20 +01:00
|
|
|
const { doBundlesEmailTemplate } = await generateKeycloakThemeResources({
|
2023-04-02 03:10:16 +02:00
|
|
|
keycloakThemeBuildingDirPath: buildOptions.keycloakifyBuildDirPath,
|
2023-03-24 06:25:25 +01:00
|
|
|
"emailThemeSrcDirPath": (() => {
|
2023-04-02 03:10:16 +02:00
|
|
|
const { emailThemeSrcDirPath } = getEmailThemeSrcDirPath({ projectDirPath });
|
2023-03-24 06:25:25 +01:00
|
|
|
|
|
|
|
if (emailThemeSrcDirPath === undefined || !fs.existsSync(emailThemeSrcDirPath)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return emailThemeSrcDirPath;
|
|
|
|
})(),
|
2023-04-02 03:10:16 +02:00
|
|
|
"reactAppBuildDirPath": buildOptions.reactAppBuildDirPath,
|
2022-08-16 14:41:06 +07:00
|
|
|
buildOptions,
|
2023-04-04 01:40:55 +02:00
|
|
|
"keycloakVersion": buildOptions.keycloakVersionDefaultAssets,
|
|
|
|
"keycloakifyVersion": (() => {
|
|
|
|
const version = JSON.parse(fs.readFileSync(pathJoin(getProjectRoot(), "package.json")).toString("utf8"))["version"];
|
|
|
|
|
|
|
|
assert(typeof version === "string");
|
|
|
|
|
|
|
|
return version;
|
|
|
|
})()
|
2021-06-14 21:21:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const { jarFilePath } = generateJavaStackFiles({
|
2023-04-02 03:10:16 +02:00
|
|
|
keycloakThemeBuildingDirPath: buildOptions.keycloakifyBuildDirPath,
|
2022-08-16 14:41:06 +07:00
|
|
|
doBundlesEmailTemplate,
|
2022-08-20 11:44:48 +07:00
|
|
|
buildOptions
|
2021-06-14 21:21:36 +02:00
|
|
|
});
|
|
|
|
|
2023-02-04 18:02:39 +01:00
|
|
|
switch (buildOptions.bundler) {
|
|
|
|
case "none":
|
|
|
|
logger.log("😱 Skipping bundling step, there will be no jar");
|
|
|
|
break;
|
|
|
|
case "keycloakify":
|
|
|
|
logger.log("🫶 Let keycloakify do its thang");
|
|
|
|
await jar({
|
2023-04-02 03:10:16 +02:00
|
|
|
"rootPath": pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources"),
|
2023-04-06 16:38:13 +02:00
|
|
|
"version": buildOptions.themeVersion,
|
2023-02-04 18:02:39 +01:00
|
|
|
"groupId": buildOptions.groupId,
|
2023-02-05 13:36:52 +01:00
|
|
|
"artifactId": buildOptions.artifactId,
|
2023-02-04 18:02:39 +01:00
|
|
|
"targetPath": jarFilePath
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "mvn":
|
|
|
|
logger.log("🫙 Run maven to deliver a jar");
|
2023-04-02 03:10:16 +02:00
|
|
|
child_process.execSync("mvn package", { "cwd": buildOptions.keycloakifyBuildDirPath });
|
2023-02-04 18:02:39 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert<Equals<typeof buildOptions.bundler, never>>(false);
|
2023-02-03 14:28:06 +01:00
|
|
|
}
|
2021-06-14 21:21:36 +02:00
|
|
|
|
2023-02-03 14:28:06 +01:00
|
|
|
// We want, however, to test in a container running the latest Keycloak version
|
2022-11-11 15:48:32 +01:00
|
|
|
const containerKeycloakVersion = "20.0.1";
|
2022-04-20 22:13:42 +02:00
|
|
|
|
2022-04-09 20:17:20 +02:00
|
|
|
generateStartKeycloakTestingContainer({
|
2023-04-02 03:10:16 +02:00
|
|
|
keycloakThemeBuildingDirPath: buildOptions.keycloakifyBuildDirPath,
|
2022-04-20 22:13:42 +02:00
|
|
|
"keycloakVersion": containerKeycloakVersion,
|
2022-08-20 11:44:48 +07:00
|
|
|
buildOptions
|
2021-06-14 21:21:36 +02:00
|
|
|
});
|
|
|
|
|
2022-09-08 12:06:26 +03:00
|
|
|
logger.log(
|
2021-10-11 21:35:40 +02:00
|
|
|
[
|
|
|
|
"",
|
2023-04-02 03:10:16 +02:00
|
|
|
`✅ Your keycloak theme has been generated and bundled into .${pathSep}${pathRelative(projectDirPath, jarFilePath)} 🚀`,
|
2022-04-25 13:05:13 +02:00
|
|
|
`It is to be placed in "/opt/keycloak/providers" in the container running a quay.io/keycloak/keycloak Docker image.`,
|
2021-10-11 21:35:40 +02:00
|
|
|
"",
|
2022-04-29 18:35:07 +02:00
|
|
|
//TODO: Restore when we find a good Helm chart for Keycloak.
|
|
|
|
//"Using Helm (https://github.com/codecentric/helm-charts), edit to reflect:",
|
2021-10-11 21:35:40 +02:00
|
|
|
"",
|
|
|
|
"value.yaml: ",
|
|
|
|
" extraInitContainers: |",
|
|
|
|
" - name: realm-ext-provider",
|
|
|
|
" image: curlimages/curl",
|
|
|
|
" imagePullPolicy: IfNotPresent",
|
|
|
|
" command:",
|
|
|
|
" - sh",
|
|
|
|
" args:",
|
|
|
|
" - -c",
|
2021-10-12 00:26:29 +02:00
|
|
|
` - curl -L -f -S -o /extensions/${pathBasename(jarFilePath)} https://AN.URL.FOR/${pathBasename(jarFilePath)}`,
|
2021-10-11 21:35:40 +02:00
|
|
|
" volumeMounts:",
|
|
|
|
" - name: extensions",
|
|
|
|
" mountPath: /extensions",
|
|
|
|
" ",
|
|
|
|
" extraVolumeMounts: |",
|
|
|
|
" - name: extensions",
|
2022-04-25 13:05:13 +02:00
|
|
|
" mountPath: /opt/keycloak/providers",
|
2021-10-11 21:35:40 +02:00
|
|
|
" extraEnv: |",
|
|
|
|
" - name: KEYCLOAK_USER",
|
|
|
|
" value: admin",
|
|
|
|
" - name: KEYCLOAK_PASSWORD",
|
|
|
|
" value: xxxxxxxxx",
|
|
|
|
" - name: JAVA_OPTS",
|
|
|
|
" value: -Dkeycloak.profile=preview",
|
|
|
|
"",
|
|
|
|
"",
|
2022-04-20 22:13:42 +02:00
|
|
|
`To test your theme locally you can spin up a Keycloak ${containerKeycloakVersion} container image with the theme pre loaded by running:`,
|
2021-10-11 21:35:40 +02:00
|
|
|
"",
|
2023-03-21 15:16:23 +01:00
|
|
|
`👉 $ .${pathSep}${pathRelative(
|
2023-04-02 03:10:16 +02:00
|
|
|
projectDirPath,
|
|
|
|
pathJoin(buildOptions.keycloakifyBuildDirPath, generateStartKeycloakTestingContainer.basename)
|
2023-03-21 15:16:23 +01:00
|
|
|
)} 👈`,
|
2021-10-11 21:35:40 +02:00
|
|
|
"",
|
2023-03-21 15:16:23 +01:00
|
|
|
`Test with different Keycloak versions by editing the .sh file. see available versions here: https://quay.io/repository/keycloak/keycloak?tab=tags`,
|
|
|
|
``,
|
|
|
|
`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-03-21 23:21:30 +01:00
|
|
|
`- Create a realm: myrealm`,
|
|
|
|
`- Enable registration: Realm settings -> Login tab -> User registration: on`,
|
|
|
|
`- Enable the Account theme: Realm settings -> Themes tab -> Account theme, select ${buildOptions.themeName} `,
|
|
|
|
`- Create a client id myclient`,
|
2023-03-21 15:16:23 +01:00
|
|
|
` Root URL: https://www.keycloak.org/app/`,
|
2023-03-21 23:21:30 +01:00
|
|
|
` Valid redirect URIs: https://www.keycloak.org/app* http://localhost* (localhost is optional)`,
|
2023-03-21 15:16:23 +01:00
|
|
|
` Valid post logout redirect URIs: https://www.keycloak.org/app* http://localhost*`,
|
|
|
|
` Web origins: *`,
|
2023-03-21 23:21:30 +01:00
|
|
|
` Login Theme: ${buildOptions.themeName}`,
|
|
|
|
` Save (button at the bottom of the page)`,
|
|
|
|
``,
|
|
|
|
`- 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
|
|
|
``
|
2022-08-20 11:44:48 +07:00
|
|
|
].join("\n")
|
2021-10-11 21:35:40 +02:00
|
|
|
);
|
2021-06-14 21:21:36 +02:00
|
|
|
}
|