Compare commits

...

7 Commits

Author SHA1 Message Date
5cf290b033 Update changelog v2.0.6 2021-07-08 01:08:57 +00:00
aec3da25b3 Bump version (changelog ignore) 2021-07-08 02:44:54 +02:00
66d7cb563d Merge pull request #18 from asashay/add-custom-props-to-theme-properties
Add possibility to add custom properties to theme.properties file
2021-07-08 02:43:37 +02:00
551e9c041e add possibility to add custom properties to theme.properties file 2021-07-06 15:52:14 +03:00
fffb6d5b5e Update changelog v2.0.5 2021-07-05 01:10:51 +00:00
ac0bfeb360 Bump version (changelog ignore) 2021-07-05 03:06:49 +02:00
7c30059ca3 Fix broken url for big stylesheet #16 2021-07-05 03:06:31 +02:00
6 changed files with 52 additions and 13 deletions

View File

@ -1,3 +1,14 @@
### **2.0.6** (2021-07-08)
- Merge pull request #18 from asashay/add-custom-props-to-theme-properties
Add possibility to add custom properties to theme.properties file
- add possibility to add custom properties to theme.properties file
### **2.0.5** (2021-07-05)
- Fix broken url for big stylesheet #16
### **2.0.4** (2021-07-03) ### **2.0.4** (2021-07-03)
- Fix: #7 - Fix: #7

View File

@ -1,6 +1,6 @@
{ {
"name": "keycloakify", "name": "keycloakify",
"version": "2.0.4", "version": "2.0.6",
"description": "Keycloak theme generator for Reacts app", "description": "Keycloak theme generator for Reacts app",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -19,6 +19,7 @@ export function main() {
console.log("🔏 Building the keycloak theme...⌚"); console.log("🔏 Building the keycloak theme...⌚");
const extraPagesId: string[] = (parsedPackageJson as any)["keycloakify"]?.["extraPages"] ?? []; const extraPagesId: string[] = (parsedPackageJson as any)["keycloakify"]?.["extraPages"] ?? [];
const extraThemeProperties: string[] = (parsedPackageJson as any)["keycloakify"]?.["extraThemeProperties"] ?? [];
generateKeycloakThemeResources({ generateKeycloakThemeResources({
keycloakThemeBuildingDirPath, keycloakThemeBuildingDirPath,
@ -55,7 +56,8 @@ export function main() {
}; };
})(), })(),
extraPagesId extraPagesId,
extraThemeProperties
}); });
const { jarFilePath } = generateJavaStackFiles({ const { jarFilePath } = generateJavaStackFiles({

View File

@ -23,12 +23,13 @@ export function generateKeycloakThemeResources(
//If urlOrigin is not undefined then it means --externals-assets //If urlOrigin is not undefined then it means --externals-assets
urlOrigin: undefined | string; urlOrigin: undefined | string;
extraPagesId: string[]; extraPagesId: string[];
extraThemeProperties: string[];
} }
) { ) {
const { const {
themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath, themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath,
urlPathname, urlOrigin, extraPagesId urlPathname, urlOrigin, extraPagesId, extraThemeProperties
} = params; } = params;
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login"); const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
@ -166,7 +167,10 @@ export function generateKeycloakThemeResources(
fs.writeFileSync( fs.writeFileSync(
pathJoin(themeDirPath, "theme.properties"), pathJoin(themeDirPath, "theme.properties"),
Buffer.from("parent=keycloak", "utf8") Buffer.from(
"parent=keycloak".concat("\n\n", extraThemeProperties.join("\n\n")),
"utf8"
)
); );
} }

View File

@ -5,18 +5,39 @@ import { ftlValuesGlobalName } from "./ftlValuesGlobalName";
export function replaceImportsFromStaticInJsCode( export function replaceImportsFromStaticInJsCode(
params: { params: {
jsCode: string; jsCode: string;
urlOrigin: undefined | string; urlOrigin: undefined | string;
} }
): { fixedJsCode: string; } { ): { fixedJsCode: string; } {
/*
NOTE:
When we have urlOrigin defined it means that
we are building with --external-assets
so we have to make sur that the fixed js code will run
inside and outside keycloak.
When urlOrigin isn't defined we can assume the fixedJsCode
will always run in keycloak context.
*/
const { jsCode, urlOrigin } = params; const { jsCode, urlOrigin } = params;
const fixedJsCode = jsCode.replace( const fixedJsCode =
jsCode
.replace(
/([a-z]+\.[a-z]+)\+"static\//g, /([a-z]+\.[a-z]+)\+"static\//g,
(...[, group]) => (...[, group]) =>
urlOrigin === undefined ? urlOrigin === undefined ?
`window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/` : `window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/` :
`("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group} + "static/` `("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group} + "static/`
)
.replace(
/".chunk.css",([a-z])+=([a-z]+\.[a-z]+)\+([a-z]+),/,
(...[, group1, group2, group3]) =>
urlOrigin === undefined ?
`".chunk.css",${group1} = window.${ftlValuesGlobalName}.url.resourcesPath + "/build/" + ${group3},` :
`".chunk.css",${group1} = ("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group2} + ${group3},`
); );
return { fixedJsCode }; return { fixedJsCode };

View File

@ -14,6 +14,7 @@ generateKeycloakThemeResources({
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme"), "keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme"),
"urlPathname": "/keycloakify-demo-app/", "urlPathname": "/keycloakify-demo-app/",
"urlOrigin": undefined, "urlOrigin": undefined,
"extraPagesId": ["my-custom-page.ftl"] "extraPagesId": ["my-custom-page.ftl"],
"extraThemeProperties": ["env=test"]
}); });