2021-02-21 23:40:10 +01:00
# ! / u s r / b i n / e n v n o d e
2021-02-21 20:54:33 +01:00
import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources" ;
import { generateJavaStackFiles } from "./generateJavaStackFiles" ;
import type { ParsedPackageJson } from "./generateJavaStackFiles" ;
2021-02-23 13:11:56 +01:00
import { join as pathJoin , relative as pathRelative , basename as pathBasename } from "path" ;
2021-02-21 21:16:43 +01:00
import * as child_process from "child_process" ;
2021-02-23 13:11:56 +01:00
import { generateDebugFiles , containerLaunchScriptBasename } from "./generateDebugFiles" ;
2021-02-21 20:54:33 +01:00
const reactProjectDirPath = process . cwd ( ) ;
const parsedPackageJson : ParsedPackageJson = require ( pathJoin ( reactProjectDirPath , "package.json" ) ) ;
2021-02-21 23:06:42 +01:00
export const keycloakThemeBuildingDirPath = pathJoin ( reactProjectDirPath , "build_keycloak" ) ;
2021-02-21 20:54:33 +01:00
2021-02-23 13:11:56 +01:00
2021-02-21 23:06:42 +01:00
if ( require . main === module ) {
2021-02-21 20:54:33 +01:00
2021-02-28 18:40:57 +01:00
console . log ( "🔏 Building the keycloak theme...⌚" ) ;
2021-02-21 23:06:42 +01:00
generateKeycloakThemeResources ( {
keycloakThemeBuildingDirPath ,
"reactAppBuildDirPath" : pathJoin ( reactProjectDirPath , "build" ) ,
"themeName" : parsedPackageJson . name
} ) ;
2021-02-21 20:54:33 +01:00
2021-02-23 13:11:56 +01:00
const { jarFilePath } = generateJavaStackFiles ( {
2021-02-21 23:06:42 +01:00
parsedPackageJson ,
keycloakThemeBuildingDirPath
} ) ;
2021-02-21 22:28:35 +01:00
2021-02-21 23:06:42 +01:00
child_process . execSync (
"mvn package" ,
{ "cwd" : keycloakThemeBuildingDirPath }
) ;
generateDebugFiles ( {
keycloakThemeBuildingDirPath ,
"packageJsonName" : parsedPackageJson . name
} ) ;
2021-02-23 13:11:56 +01:00
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' ,
'' ,
'' ,
2021-02-23 15:32:37 +01:00
'To test your theme locally, with hot reloading, you can spin up a Keycloak container image with the theme loaded by running:' ,
'' ,
2021-02-27 18:19:02 +01:00
` 👉 $ ./ ${ pathRelative ( reactProjectDirPath , pathJoin ( keycloakThemeBuildingDirPath , containerLaunchScriptBasename ) ) } 👈 ` ,
2021-02-23 15:32:37 +01:00
'' ,
2021-02-27 18:19:02 +01:00
'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),' ,
2021-02-23 15:32:37 +01:00
` 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 ` ,
'' ,
2021-02-27 18:19:02 +01:00
'Once your container is up and configured 👉 http://localhost:8080/auth/realms/myrealm/account 👈' ,
2021-02-23 13:11:56 +01:00
'' ,
] . join ( "\n" ) ) ;
2021-02-21 23:06:42 +01:00
}