2023-04-18 03:10:29 +02:00
import { generateTheme } from "./generateTheme" ;
2024-05-11 23:20:15 +02:00
import { join as pathJoin , relative as pathRelative , 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" ;
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" ;
2024-01-30 06:37:49 +01:00
import { getThemeSrcDirPath } from "../getThemeSrcDirPath" ;
2024-02-11 20:15:18 +01:00
import { getThisCodebaseRootDirPath } from "../tools/getThisCodebaseRootDirPath" ;
import { readThisNpmProjectVersion } from "../tools/readThisNpmProjectVersion" ;
2024-02-23 19:15:59 +01:00
import { keycloakifyBuildOptionsForPostPostBuildScriptEnvName } from "../constants" ;
2024-05-12 19:16:59 +02:00
import { buildJars } from "./buildJars" ;
import { generateThemeVariations } from "./generateThemeVariants" ;
2021-06-14 21:21:36 +02:00
2023-01-16 14:42:20 +01:00
export async function main() {
2023-04-02 03:10:16 +02:00
const buildOptions = readBuildOptions ( {
2023-04-19 05:04:11 +02:00
"processArgv" : process . argv . slice ( 2 )
2022-08-16 14:41:06 +07:00
} ) ;
2021-06-23 18:03:49 +02:00
2023-04-19 05:04:11 +02:00
const logger = getLogger ( { "isSilent" : buildOptions . isSilent } ) ;
logger . log ( "🔏 Building the keycloak theme...⌚" ) ;
2024-02-08 00:56:33 +01:00
const { themeSrcDirPath } = getThemeSrcDirPath ( { "reactAppRootDirPath" : buildOptions . reactAppRootDirPath } ) ;
2023-04-04 01:40:55 +02:00
2024-05-12 19:37:16 +02:00
fs . writeFileSync ( pathJoin ( buildOptions . keycloakifyBuildDirPath , ".gitignore" ) , Buffer . from ( "*" , "utf8" ) ) ;
2024-05-12 19:16:59 +02:00
2024-05-12 19:37:16 +02:00
{
const [ themeName , . . . themeVariantNames ] = buildOptions . themeNames ;
2024-05-12 19:16:59 +02:00
2024-05-12 19:37:16 +02:00
const { implementedThemeTypes } = await generateTheme ( {
2023-09-04 01:19:21 +02:00
themeName ,
2024-05-12 19:37:16 +02:00
themeSrcDirPath ,
"keycloakifySrcDirPath" : pathJoin ( getThisCodebaseRootDirPath ( ) , "src" ) ,
"keycloakifyVersion" : readThisNpmProjectVersion ( ) ,
2024-02-11 20:15:18 +01:00
buildOptions
2023-06-08 23:09:14 +02:00
} ) ;
2024-05-12 19:37:16 +02:00
for ( const themeVariantName of themeVariantNames ) {
generateThemeVariations ( {
themeName ,
themeVariantName ,
implementedThemeTypes ,
buildOptions
} ) ;
}
2024-02-05 08:52:58 +01:00
}
2024-03-05 19:42:49 +01:00
run_post_build_script : {
if ( buildOptions . bundler !== "vite" ) {
break run_post_build_script ;
2024-02-23 19:15:59 +01:00
}
2024-03-05 19:42:49 +01:00
child_process . execSync ( "npx vite" , {
"cwd" : buildOptions . reactAppRootDirPath ,
"env" : {
. . . process . env ,
[ keycloakifyBuildOptionsForPostPostBuildScriptEnvName ] : JSON . stringify ( buildOptions )
}
} ) ;
}
2024-02-23 19:15:59 +01:00
2024-05-12 19:16:59 +02:00
const { lastJarFileBasename } = await buildJars ( {
"doImplementAccountTheme" : implementedThemeTypes . account ,
buildOptions
} ) ;
2024-02-23 19:15:59 +01:00
2024-05-12 19:16:59 +02:00
generateStartKeycloakTestingContainer ( {
"jarFilePath" : pathJoin ( buildOptions . keycloakifyBuildDirPath , lastJarFileBasename ) ,
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
[
2024-05-12 19:16:59 +02:00
` ✅ Your keycloak theme has been generated and bundled into . ${ pathSep } ${ pathJoin (
pathRelative ( buildOptions . reactAppRootDirPath , buildOptions . keycloakifyBuildDirPath ) ,
"keycloak-theme-for-kc-*.jar"
) } ` ,
2021-10-11 21:35:40 +02:00
"" ,
2024-05-12 19:16:59 +02:00
` To test your theme locally you can spin up a Keycloak 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 (
2024-02-08 00:56:33 +01:00
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 ` ,
2023-09-04 01:19:21 +02:00
` - 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: * ` ,
2023-09-04 01:19:21 +02:00
` 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
` `
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
}