From daa3efa5348bafcc30e4e172a094165690c5db09 Mon Sep 17 00:00:00 2001 From: garronej Date: Mon, 14 Jun 2021 21:21:36 +0200 Subject: [PATCH] Refactor dir structure (changelog ignore) --- .../build-keycloak-theme.ts | 115 +++++++++++++++++ src/bin/build-keycloak-theme/index.ts | 116 +----------------- src/bin/install-builtin-keycloak-themes.ts | 2 +- 3 files changed, 117 insertions(+), 116 deletions(-) create mode 100644 src/bin/build-keycloak-theme/build-keycloak-theme.ts diff --git a/src/bin/build-keycloak-theme/build-keycloak-theme.ts b/src/bin/build-keycloak-theme/build-keycloak-theme.ts new file mode 100644 index 00000000..afe19abe --- /dev/null +++ b/src/bin/build-keycloak-theme/build-keycloak-theme.ts @@ -0,0 +1,115 @@ +#!/usr/bin/env node + +import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources"; +import { generateJavaStackFiles } from "./generateJavaStackFiles"; +import type { ParsedPackageJson } from "./generateJavaStackFiles"; +import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path"; +import * as child_process from "child_process"; +import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles"; +import { URL } from "url"; + + +const reactProjectDirPath = process.cwd(); + +const doUseExternalAssets = process.argv[2]?.toLowerCase() === "--external-assets"; + +const parsedPackageJson: ParsedPackageJson = require(pathJoin(reactProjectDirPath, "package.json")); + +export const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak"); + + +if (require.main === module) { + + console.log("🔏 Building the keycloak theme...⌚"); + + generateKeycloakThemeResources({ + keycloakThemeBuildingDirPath, + "reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"), + "themeName": parsedPackageJson.name, + ...(() => { + + const url = (() => { + + const { homepage } = parsedPackageJson; + + return homepage === undefined ? + undefined : + new URL(homepage); + + })(); + + return { + "urlPathname": + url === undefined ? + "/" : + url.pathname.replace(/([^/])$/, "$1/"), + "urlOrigin": !doUseExternalAssets ? undefined : (() => { + + if (url === undefined) { + console.error("ERROR: You must specify 'homepage' in your package.json"); + process.exit(-1); + } + + return url.origin; + + })() + + }; + + })() + }); + + const { jarFilePath } = generateJavaStackFiles({ + parsedPackageJson, + keycloakThemeBuildingDirPath + }); + + child_process.execSync( + "mvn package", + { "cwd": keycloakThemeBuildingDirPath } + ); + + generateDebugFiles({ + keycloakThemeBuildingDirPath, + "packageJsonName": parsedPackageJson.name + }); + + console.log([ + '', + `✅ Your keycloak theme has been generated and bundled into ./${pathRelative(reactProjectDirPath, jarFilePath)} 🚀`, + `It is to be placed in "/opt/jboss/keycloak/standalone/deployments" in the container running a jboss/keycloak Docker image. (Tested with 11.0.3)`, + '', + 'Using Helm (https://github.com/codecentric/helm-charts), edit to reflect:', + '', + 'value.yaml: ', + ' extraInitContainers: |', + ' - name: realm-ext-provider', + ' image: curlimages/curl', + ' imagePullPolicy: IfNotPresent', + ' command:', + ' - sh', + ' args:', + ' - -c', + ` - curl -L -f -S -o /extensions/${pathBasename(jarFilePath)} https://AN.URL.FOR/${pathBasename(jarFilePath)}`, + ' volumeMounts:', + ' - name: extensions', + ' mountPath: /extensions', + ' ', + ' extraVolumeMounts: |', + ' - name: extensions', + ' mountPath: /opt/jboss/keycloak/standalone/deployments', + '', + '', + 'To test your theme locally, with hot reloading, you can spin up a Keycloak container image with the theme loaded by running:', + '', + `👉 $ ./${pathRelative(reactProjectDirPath, pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename))} 👈`, + '', + 'To enable the theme within keycloak log into the admin console ( 👉 http://localhost:8080 username: admin, password: admin 👈), create a realm (called "myrealm" for example),', + `go to your realm settings, click on the theme tab then select ${parsedPackageJson.name}.`, + `More details: https://www.keycloak.org/getting-started/getting-started-docker`, + '', + 'Once your container is up and configured 👉 http://localhost:8080/auth/realms/myrealm/account 👈', + '', + ].join("\n")); + +} diff --git a/src/bin/build-keycloak-theme/index.ts b/src/bin/build-keycloak-theme/index.ts index afe19abe..7df8d254 100644 --- a/src/bin/build-keycloak-theme/index.ts +++ b/src/bin/build-keycloak-theme/index.ts @@ -1,115 +1 @@ -#!/usr/bin/env node - -import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources"; -import { generateJavaStackFiles } from "./generateJavaStackFiles"; -import type { ParsedPackageJson } from "./generateJavaStackFiles"; -import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path"; -import * as child_process from "child_process"; -import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles"; -import { URL } from "url"; - - -const reactProjectDirPath = process.cwd(); - -const doUseExternalAssets = process.argv[2]?.toLowerCase() === "--external-assets"; - -const parsedPackageJson: ParsedPackageJson = require(pathJoin(reactProjectDirPath, "package.json")); - -export const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak"); - - -if (require.main === module) { - - console.log("🔏 Building the keycloak theme...⌚"); - - generateKeycloakThemeResources({ - keycloakThemeBuildingDirPath, - "reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"), - "themeName": parsedPackageJson.name, - ...(() => { - - const url = (() => { - - const { homepage } = parsedPackageJson; - - return homepage === undefined ? - undefined : - new URL(homepage); - - })(); - - return { - "urlPathname": - url === undefined ? - "/" : - url.pathname.replace(/([^/])$/, "$1/"), - "urlOrigin": !doUseExternalAssets ? undefined : (() => { - - if (url === undefined) { - console.error("ERROR: You must specify 'homepage' in your package.json"); - process.exit(-1); - } - - return url.origin; - - })() - - }; - - })() - }); - - const { jarFilePath } = generateJavaStackFiles({ - parsedPackageJson, - keycloakThemeBuildingDirPath - }); - - child_process.execSync( - "mvn package", - { "cwd": keycloakThemeBuildingDirPath } - ); - - generateDebugFiles({ - keycloakThemeBuildingDirPath, - "packageJsonName": parsedPackageJson.name - }); - - console.log([ - '', - `✅ Your keycloak theme has been generated and bundled into ./${pathRelative(reactProjectDirPath, jarFilePath)} 🚀`, - `It is to be placed in "/opt/jboss/keycloak/standalone/deployments" in the container running a jboss/keycloak Docker image. (Tested with 11.0.3)`, - '', - 'Using Helm (https://github.com/codecentric/helm-charts), edit to reflect:', - '', - 'value.yaml: ', - ' extraInitContainers: |', - ' - name: realm-ext-provider', - ' image: curlimages/curl', - ' imagePullPolicy: IfNotPresent', - ' command:', - ' - sh', - ' args:', - ' - -c', - ` - curl -L -f -S -o /extensions/${pathBasename(jarFilePath)} https://AN.URL.FOR/${pathBasename(jarFilePath)}`, - ' volumeMounts:', - ' - name: extensions', - ' mountPath: /extensions', - ' ', - ' extraVolumeMounts: |', - ' - name: extensions', - ' mountPath: /opt/jboss/keycloak/standalone/deployments', - '', - '', - 'To test your theme locally, with hot reloading, you can spin up a Keycloak container image with the theme loaded by running:', - '', - `👉 $ ./${pathRelative(reactProjectDirPath, pathJoin(keycloakThemeBuildingDirPath, containerLaunchScriptBasename))} 👈`, - '', - 'To enable the theme within keycloak log into the admin console ( 👉 http://localhost:8080 username: admin, password: admin 👈), create a realm (called "myrealm" for example),', - `go to your realm settings, click on the theme tab then select ${parsedPackageJson.name}.`, - `More details: https://www.keycloak.org/getting-started/getting-started-docker`, - '', - 'Once your container is up and configured 👉 http://localhost:8080/auth/realms/myrealm/account 👈', - '', - ].join("\n")); - -} +export * from "./build-keycloak-theme"; \ No newline at end of file diff --git a/src/bin/install-builtin-keycloak-themes.ts b/src/bin/install-builtin-keycloak-themes.ts index 625a4cff..9d5d06ea 100644 --- a/src/bin/install-builtin-keycloak-themes.ts +++ b/src/bin/install-builtin-keycloak-themes.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme"; +import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme/build-keycloak-theme"; import { downloadAndUnzip } from "./tools/downloadAndUnzip"; import { join as pathJoin } from "path";