Compare commits
84 Commits
v10.0.0-rc
...
v10.0.0-rc
Author | SHA1 | Date | |
---|---|---|---|
41739c8528 | |||
89b32dc7fc | |||
44aec23251 | |||
12fd6160c5 | |||
8819abc418 | |||
96b627095c | |||
dba004f924 | |||
5423a07c47 | |||
aba725372e | |||
a61aa9dd5d | |||
74349b20ce | |||
09ab9a1c8f | |||
abfe5789a3 | |||
67ebac496d | |||
60a2bf173b | |||
4e03f07864 | |||
aef1709d7f | |||
2f590f7be2 | |||
d5fa6ca89a | |||
8eaaffb25a | |||
28c5e2bab2 | |||
e212039f2c | |||
99b0b67f77 | |||
6ec9ba3c01 | |||
d7960a7dcf | |||
2a6e9af9c9 | |||
327e4d1f90 | |||
fffadd7b9e | |||
aaaf0d2e77 | |||
9f9a9b8c90 | |||
1f6edb3c0c | |||
142efb4f99 | |||
532655d2d5 | |||
287edabd90 | |||
7aaedbe2ce | |||
4cae1c673c | |||
8e01d836a9 | |||
f6dc8f0741 | |||
3a976d08d2 | |||
50e83b1eb5 | |||
61fbbb0b09 | |||
9e70e5c12e | |||
69d9b64468 | |||
0620d29880 | |||
b52dc74d9b | |||
a46aef2e7e | |||
736806a53d | |||
f1475e5cdf | |||
d04724c70a | |||
bacaadc16d | |||
c51dd235f0 | |||
92f2c9857e | |||
3998cc7f8b | |||
c126d080bc | |||
bc05f1714d | |||
e98becb94b | |||
250b94c8b5 | |||
47f03f6833 | |||
6e7ae48f78 | |||
526dbcc0e7 | |||
1abc5a5643 | |||
c81c350136 | |||
f90dc8bc7e | |||
072e22d072 | |||
59807c1bb0 | |||
7c19e1f1f7 | |||
3b9f915f57 | |||
d85cc530d4 | |||
2bb27c7642 | |||
e90e003204 | |||
b1e58e1add | |||
0fd836314a | |||
0bc3f08cc1 | |||
a78af5080a | |||
074e465284 | |||
bc8165d0ae | |||
ba8561d75a | |||
b2d381ba4b | |||
d39353d332 | |||
ee916af48e | |||
da1dc0309b | |||
30f4e7d833 | |||
cf3a86fb9b | |||
e1633f43f4 |
17
.github/workflows/ci.yaml
vendored
17
.github/workflows/ci.yaml
vendored
@ -16,8 +16,8 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
- uses: bahmutov/npm-install@v1
|
- uses: bahmutov/npm-install@v1
|
||||||
- name: If this step fails run 'yarn format' then commit again.
|
- name: If this step fails run 'npm run format' then commit again.
|
||||||
run: yarn format:check
|
run: npm run format:check
|
||||||
test:
|
test:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
needs: test_lint
|
needs: test_lint
|
||||||
@ -32,13 +32,12 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
- uses: bahmutov/npm-install@v1
|
- uses: bahmutov/npm-install@v1
|
||||||
- run: yarn build
|
- run: npm run build
|
||||||
- run: yarn test
|
- run: npm run test
|
||||||
#- run: yarn test:keycloakify-starter
|
|
||||||
|
|
||||||
storybook:
|
storybook:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'push'
|
#if: github.event_name == 'push'
|
||||||
needs: test
|
needs: test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@ -46,11 +45,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: '18'
|
node-version: '18'
|
||||||
- uses: bahmutov/npm-install@v1
|
- uses: bahmutov/npm-install@v1
|
||||||
- run: yarn build-storybook -o ./build_storybook
|
- run: npm run build-storybook
|
||||||
- run: git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${{github.repository}}.git
|
- run: git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${{github.repository}}.git
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- run: npx -y -p gh-pages@3.1.0 gh-pages -d ./build_storybook -u "github-actions-bot <actions@github.com>"
|
- run: npx -y -p gh-pages@3.1.0 gh-pages -d ./storybook-static -u "github-actions-bot <actions@github.com>"
|
||||||
|
|
||||||
check_if_version_upgraded:
|
check_if_version_upgraded:
|
||||||
name: Check if version upgrade
|
name: Check if version upgrade
|
||||||
@ -112,7 +111,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
registry-url: https://registry.npmjs.org/
|
registry-url: https://registry.npmjs.org/
|
||||||
- uses: bahmutov/npm-install@v1
|
- uses: bahmutov/npm-install@v1
|
||||||
- run: yarn build
|
- run: npm run build
|
||||||
- run: npx -y -p denoify@1.6.12 enable_short_npm_import_path
|
- run: npx -y -p denoify@1.6.12 enable_short_npm_import_path
|
||||||
env:
|
env:
|
||||||
DRY_RUN: "0"
|
DRY_RUN: "0"
|
||||||
|
29
package.json
29
package.json
@ -1,24 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"version": "10.0.0-rc.52",
|
"version": "10.0.0-rc.77",
|
||||||
"description": "Create Keycloak themes using React",
|
"description": "Create Keycloak themes using React",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/keycloakify/keycloakify.git"
|
"url": "git://github.com/keycloakify/keycloakify.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "patch-package && ts-node --skipProject scripts/generate-i18n-messages.ts",
|
"prepare": "tsx scripts/generate-i18n-messages.ts",
|
||||||
"build": "ts-node --skipProject scripts/build.ts",
|
"build": "tsx scripts/build.ts",
|
||||||
"storybook": "ts-node --skipProject scripts/start-storybook.ts",
|
"storybook": "tsx scripts/start-storybook.ts",
|
||||||
"link-in-starter": "ts-node --skipProject scripts/link-in-starter.ts",
|
"link-in-starter": "tsx scripts/link-in-starter.ts",
|
||||||
"test": "yarn test:types && vitest run",
|
"test": "yarn test:types && vitest run",
|
||||||
"test:types": "tsc -p test/tsconfig.json --noEmit",
|
"test:types": "tsc -p test/tsconfig.json --noEmit",
|
||||||
"_format": "prettier '**/*.{ts,tsx,json,md}'",
|
"_format": "prettier '**/*.{ts,tsx,json,md}'",
|
||||||
"format": "yarn _format --write",
|
"format": "yarn _format --write",
|
||||||
"format:check": "yarn _format --list-different",
|
"format:check": "yarn _format --list-different",
|
||||||
"link-in-app": "ts-node --skipProject scripts/link-in-app.ts",
|
"link-in-app": "tsx scripts/link-in-app.ts",
|
||||||
"build-storybook": "ts-node --skipProject scripts/build-storybook.ts",
|
"build-storybook": "tsx scripts/build-storybook.ts",
|
||||||
"dump-keycloak-realm": "ts-node --skipProject scripts/dump-keycloak-realm.ts"
|
"dump-keycloak-realm": "tsx scripts/dump-keycloak-realm.ts"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"keycloakify": "dist/bin/main.js"
|
"keycloakify": "dist/bin/main.js"
|
||||||
@ -41,10 +41,10 @@
|
|||||||
"!dist/bin/",
|
"!dist/bin/",
|
||||||
"dist/bin/main.js",
|
"dist/bin/main.js",
|
||||||
"dist/bin/*.index.js",
|
"dist/bin/*.index.js",
|
||||||
|
"!dist/bin/shared/*.js",
|
||||||
"dist/bin/shared/constants.js",
|
"dist/bin/shared/constants.js",
|
||||||
"dist/bin/shared/constants.d.ts",
|
"dist/bin/shared/*.d.ts",
|
||||||
"dist/bin/shared/constants.js.map",
|
"dist/bin/shared/*.js.map",
|
||||||
"dist/bin/shared/buildContext.d.ts",
|
|
||||||
"!dist/vite-plugin/",
|
"!dist/vite-plugin/",
|
||||||
"dist/vite-plugin/index.d.ts",
|
"dist/vite-plugin/index.d.ts",
|
||||||
"dist/vite-plugin/vite-plugin.d.ts",
|
"dist/vite-plugin/vite-plugin.d.ts",
|
||||||
@ -102,7 +102,6 @@
|
|||||||
"lint-staged": "^11.0.0",
|
"lint-staged": "^11.0.0",
|
||||||
"magic-string": "^0.30.7",
|
"magic-string": "^0.30.7",
|
||||||
"make-fetch-happen": "^11.0.3",
|
"make-fetch-happen": "^11.0.3",
|
||||||
"patch-package": "^8.0.0",
|
|
||||||
"powerhooks": "^1.0.10",
|
"powerhooks": "^1.0.10",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"properties-parser": "^0.3.1",
|
"properties-parser": "^0.3.1",
|
||||||
@ -111,8 +110,7 @@
|
|||||||
"recast": "^0.23.3",
|
"recast": "^0.23.3",
|
||||||
"run-exclusive": "^2.2.19",
|
"run-exclusive": "^2.2.19",
|
||||||
"storybook-dark-mode": "^1.1.2",
|
"storybook-dark-mode": "^1.1.2",
|
||||||
"termost": "^0.12.0",
|
"termost": "^v0.12.1",
|
||||||
"ts-node": "^10.9.2",
|
|
||||||
"tsc-alias": "^1.8.10",
|
"tsc-alias": "^1.8.10",
|
||||||
"tss-react": "^4.9.10",
|
"tss-react": "^4.9.10",
|
||||||
"typescript": "^4.9.1-beta",
|
"typescript": "^4.9.1-beta",
|
||||||
@ -120,6 +118,7 @@
|
|||||||
"vitest": "^1.6.0",
|
"vitest": "^1.6.0",
|
||||||
"yauzl": "^2.10.0",
|
"yauzl": "^2.10.0",
|
||||||
"zod": "^3.17.10",
|
"zod": "^3.17.10",
|
||||||
"evt": "^2.5.7"
|
"evt": "^2.5.7",
|
||||||
|
"tsx": "^4.15.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -11,13 +11,17 @@ import { is } from "tsafe/is";
|
|||||||
{
|
{
|
||||||
const dCompleted = new Deferred<void>();
|
const dCompleted = new Deferred<void>();
|
||||||
|
|
||||||
const child = child_process.spawn("docker", [
|
const child = child_process.spawn(
|
||||||
...["exec", containerName],
|
"docker",
|
||||||
...["/opt/keycloak/bin/kc.sh", "export"],
|
[
|
||||||
...["--dir", "/tmp"],
|
...["exec", containerName],
|
||||||
...["--realm", "myrealm"],
|
...["/opt/keycloak/bin/kc.sh", "export"],
|
||||||
...["--users", "realm_file"]
|
...["--dir", "/tmp"],
|
||||||
]);
|
...["--realm", "myrealm"],
|
||||||
|
...["--users", "realm_file"]
|
||||||
|
],
|
||||||
|
{ shell: true }
|
||||||
|
);
|
||||||
|
|
||||||
let output = "";
|
let output = "";
|
||||||
|
|
||||||
|
@ -2,66 +2,53 @@ import { execSync } from "child_process";
|
|||||||
import { join as pathJoin, relative as pathRelative } from "path";
|
import { join as pathJoin, relative as pathRelative } from "path";
|
||||||
import { getThisCodebaseRootDirPath } from "../src/bin/tools/getThisCodebaseRootDirPath";
|
import { getThisCodebaseRootDirPath } from "../src/bin/tools/getThisCodebaseRootDirPath";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
import * as os from "os";
|
||||||
|
|
||||||
const singletonDependencies: string[] = ["react", "@types/react"];
|
const singletonDependencies: string[] = ["react", "@types/react"];
|
||||||
|
|
||||||
|
// For example [ "@emotion" ] it's more convenient than
|
||||||
|
// having to list every sub emotion packages (@emotion/css @emotion/utils ...)
|
||||||
|
// in singletonDependencies
|
||||||
|
const namespaceSingletonDependencies: string[] = [];
|
||||||
|
|
||||||
const rootDirPath = getThisCodebaseRootDirPath();
|
const rootDirPath = getThisCodebaseRootDirPath();
|
||||||
|
|
||||||
|
const commonThirdPartyDeps = [
|
||||||
|
...namespaceSingletonDependencies
|
||||||
|
.map(namespaceModuleName =>
|
||||||
|
fs
|
||||||
|
.readdirSync(pathJoin(rootDirPath, "node_modules", namespaceModuleName))
|
||||||
|
.map(submoduleName => `${namespaceModuleName}/${submoduleName}`)
|
||||||
|
)
|
||||||
|
.reduce((prev, curr) => [...prev, ...curr], []),
|
||||||
|
...singletonDependencies
|
||||||
|
];
|
||||||
|
|
||||||
//NOTE: This is only required because of: https://github.com/garronej/ts-ci/blob/c0e207b9677523d4ec97fe672ddd72ccbb3c1cc4/README.md?plain=1#L54-L58
|
//NOTE: This is only required because of: https://github.com/garronej/ts-ci/blob/c0e207b9677523d4ec97fe672ddd72ccbb3c1cc4/README.md?plain=1#L54-L58
|
||||||
fs.writeFileSync(
|
{
|
||||||
pathJoin(rootDirPath, "dist", "package.json"),
|
let modifiedPackageJsonContent = fs
|
||||||
Buffer.from(
|
.readFileSync(pathJoin(rootDirPath, "package.json"))
|
||||||
JSON.stringify(
|
.toString("utf8");
|
||||||
(() => {
|
|
||||||
const packageJsonParsed = JSON.parse(
|
|
||||||
fs
|
|
||||||
.readFileSync(pathJoin(rootDirPath, "package.json"))
|
|
||||||
.toString("utf8")
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
modifiedPackageJsonContent = (() => {
|
||||||
...packageJsonParsed,
|
const o = JSON.parse(modifiedPackageJsonContent);
|
||||||
main: packageJsonParsed["main"]?.replace(/^dist\//, ""),
|
|
||||||
types: packageJsonParsed["types"]?.replace(/^dist\//, ""),
|
|
||||||
module: packageJsonParsed["module"]?.replace(/^dist\//, ""),
|
|
||||||
exports: !("exports" in packageJsonParsed)
|
|
||||||
? undefined
|
|
||||||
: Object.fromEntries(
|
|
||||||
Object.entries(packageJsonParsed["exports"]).map(
|
|
||||||
([key, value]) => [
|
|
||||||
key,
|
|
||||||
(value as string).replace(/^\.\/dist\//, "./")
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
};
|
|
||||||
})(),
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
),
|
|
||||||
"utf8"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const commonThirdPartyDeps = (() => {
|
delete o.files;
|
||||||
// For example [ "@emotion" ] it's more convenient than
|
|
||||||
// having to list every sub emotion packages (@emotion/css @emotion/utils ...)
|
|
||||||
// in singletonDependencies
|
|
||||||
const namespaceSingletonDependencies: string[] = [];
|
|
||||||
|
|
||||||
return [
|
return JSON.stringify(o, null, 2);
|
||||||
...namespaceSingletonDependencies
|
})();
|
||||||
.map(namespaceModuleName =>
|
|
||||||
fs
|
modifiedPackageJsonContent = modifiedPackageJsonContent
|
||||||
.readdirSync(
|
.replace(/"dist\//g, '"')
|
||||||
pathJoin(rootDirPath, "node_modules", namespaceModuleName)
|
.replace(/"\.\/dist\//g, '"./')
|
||||||
)
|
.replace(/"!dist\//g, '"!')
|
||||||
.map(submoduleName => `${namespaceModuleName}/${submoduleName}`)
|
.replace(/"!\.\/dist\//g, '"!./');
|
||||||
)
|
|
||||||
.reduce((prev, curr) => [...prev, ...curr], []),
|
fs.writeFileSync(
|
||||||
...singletonDependencies
|
pathJoin(rootDirPath, "dist", "package.json"),
|
||||||
];
|
Buffer.from(modifiedPackageJsonContent, "utf8")
|
||||||
})();
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const yarnGlobalDirPath = pathJoin(rootDirPath, ".yarn_home");
|
const yarnGlobalDirPath = pathJoin(rootDirPath, ".yarn_home");
|
||||||
|
|
||||||
@ -83,7 +70,9 @@ const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => {
|
|||||||
cwd,
|
cwd,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
HOME: yarnGlobalDirPath
|
...(os.platform() === "win32"
|
||||||
|
? { USERPROFILE: yarnGlobalDirPath }
|
||||||
|
: { HOME: yarnGlobalDirPath })
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ fs.rmSync(join("..", "keycloakify-starter", "node_modules"), {
|
|||||||
|
|
||||||
run("yarn install", { cwd: join("..", "keycloakify-starter") });
|
run("yarn install", { cwd: join("..", "keycloakify-starter") });
|
||||||
|
|
||||||
run(`npx ts-node --skipProject ${join("scripts", "link-in-app.ts")} keycloakify-starter`);
|
run(`npx tsx ${join("scripts", "link-in-app.ts")} keycloakify-starter`);
|
||||||
|
|
||||||
startRebuildOnSrcChange();
|
startRebuildOnSrcChange();
|
||||||
|
|
||||||
|
@ -13,7 +13,9 @@ run(`node ${join("dist", "bin", "main.js")} copy-keycloak-resources-to-public`,
|
|||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const child = child_process.spawn("npx", ["start-storybook", "-p", "6006"]);
|
const child = child_process.spawn("npx", ["start-storybook", "-p", "6006"], {
|
||||||
|
shell: true
|
||||||
|
});
|
||||||
|
|
||||||
child.stdout.on("data", data => process.stdout.write(data));
|
child.stdout.on("data", data => process.stdout.write(data));
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export function startRebuildOnSrcChange() {
|
|||||||
|
|
||||||
const dCompleted = new Deferred<void>();
|
const dCompleted = new Deferred<void>();
|
||||||
|
|
||||||
const child = child_process.spawn("yarn", ["build"]);
|
const child = child_process.spawn("yarn", ["build"], { shell: true });
|
||||||
|
|
||||||
child.stdout.on("data", data => process.stdout.write(data));
|
child.stdout.on("data", data => process.stdout.write(data));
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import {
|
import { basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/shared/constants";
|
||||||
nameOfTheGlobal,
|
|
||||||
basenameOfTheKeycloakifyResourcesDir
|
|
||||||
} from "keycloakify/bin/shared/constants";
|
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,7 +6,7 @@ import { assert } from "tsafe/assert";
|
|||||||
* This works both in your main app and in your Keycloak theme.
|
* This works both in your main app and in your Keycloak theme.
|
||||||
*/
|
*/
|
||||||
export const PUBLIC_URL = (() => {
|
export const PUBLIC_URL = (() => {
|
||||||
const kcContext = (window as any)[nameOfTheGlobal];
|
const kcContext = (window as any).kcContext;
|
||||||
|
|
||||||
if (kcContext === undefined || process.env.NODE_ENV === "development") {
|
if (kcContext === undefined || process.env.NODE_ENV === "development") {
|
||||||
assert(
|
assert(
|
||||||
|
@ -166,6 +166,7 @@ export declare namespace KcContext {
|
|||||||
algorithm: "HmacSHA1" | "HmacSHA256" | "HmacSHA512";
|
algorithm: "HmacSHA1" | "HmacSHA256" | "HmacSHA512";
|
||||||
digits: number;
|
digits: number;
|
||||||
lookAheadWindow: number;
|
lookAheadWindow: number;
|
||||||
|
getAlgorithmKey: () => string;
|
||||||
} & (
|
} & (
|
||||||
| {
|
| {
|
||||||
type: "totp";
|
type: "totp";
|
||||||
|
@ -82,17 +82,7 @@ export const kcContextCommonMock: KcContext.Common = {
|
|||||||
email: "john.doe@code.gouv.fr",
|
email: "john.doe@code.gouv.fr",
|
||||||
username: "doe_j"
|
username: "doe_j"
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {}
|
||||||
parent: "account-v1",
|
|
||||||
kcButtonLargeClass: "btn-lg",
|
|
||||||
locales:
|
|
||||||
"ar,ca,cs,da,de,en,es,fr,fi,hu,it,ja,lt,nl,no,pl,pt-BR,ru,sk,sv,tr,zh-CN",
|
|
||||||
kcButtonPrimaryClass: "btn-primary",
|
|
||||||
accountResourceProvider: "account-v1",
|
|
||||||
styles: "css/account.css img/icon-sidebar-active.png img/logo.png resources-common/node_modules/patternfly/dist/css/patternfly.min.css resources-common/node_modules/patternfly/dist/css/patternfly-additions.min.css resources-common/node_modules/patternfly/dist/css/patternfly-additions.min.css",
|
|
||||||
kcButtonClass: "btn",
|
|
||||||
kcButtonDefaultClass: "btn-default"
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const kcContextMocks: KcContext[] = [
|
export const kcContextMocks: KcContext[] = [
|
||||||
@ -158,7 +148,8 @@ export const kcContextMocks: KcContext[] = [
|
|||||||
digits: 6,
|
digits: 6,
|
||||||
lookAheadWindow: 1,
|
lookAheadWindow: 1,
|
||||||
type: "totp",
|
type: "totp",
|
||||||
period: 30
|
period: 30,
|
||||||
|
getAlgorithmKey: () => "SHA1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mode: "qr",
|
mode: "qr",
|
||||||
|
@ -16,12 +16,6 @@ export default function Totp(props: PageProps<Extract<KcContext, { pageId: "totp
|
|||||||
|
|
||||||
const { msg, msgStr, advancedMsg } = i18n;
|
const { msg, msgStr, advancedMsg } = i18n;
|
||||||
|
|
||||||
const algToKeyUriAlg: Record<(typeof kcContext)["totp"]["policy"]["algorithm"], string> = {
|
|
||||||
HmacSHA1: "SHA1",
|
|
||||||
HmacSHA256: "SHA256",
|
|
||||||
HmacSHA512: "SHA512"
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Template {...{ kcContext, i18n, doUseDefaultCss, classes }} active="totp">
|
<Template {...{ kcContext, i18n, doUseDefaultCss, classes }} active="totp">
|
||||||
<>
|
<>
|
||||||
@ -100,7 +94,7 @@ export default function Totp(props: PageProps<Extract<KcContext, { pageId: "totp
|
|||||||
{msg("totpType")}: {msg(`totp.${totp.policy.type}`)}
|
{msg("totpType")}: {msg(`totp.${totp.policy.type}`)}
|
||||||
</li>
|
</li>
|
||||||
<li id="kc-totp-algorithm">
|
<li id="kc-totp-algorithm">
|
||||||
{msg("totpAlgorithm")}: {algToKeyUriAlg?.[totp.policy.algorithm] ?? totp.policy.algorithm}
|
{msg("totpAlgorithm")}: {totp.policy.getAlgorithmKey()}
|
||||||
</li>
|
</li>
|
||||||
<li id="kc-totp-digits">
|
<li id="kc-totp-digits">
|
||||||
{msg("totpDigits")}: {totp.policy.digits}
|
{msg("totpDigits")}: {totp.policy.digits}
|
||||||
|
@ -13,7 +13,6 @@ import * as fs from "fs";
|
|||||||
import { join as pathJoin, relative as pathRelative, dirname as pathDirname } from "path";
|
import { join as pathJoin, relative as pathRelative, dirname as pathDirname } from "path";
|
||||||
import { kebabCaseToCamelCase } from "./tools/kebabCaseToSnakeCase";
|
import { kebabCaseToCamelCase } from "./tools/kebabCaseToSnakeCase";
|
||||||
import { assert, Equals } from "tsafe/assert";
|
import { assert, Equals } from "tsafe/assert";
|
||||||
import { getThemeSrcDirPath } from "./shared/getThemeSrcDirPath";
|
|
||||||
import type { CliCommandOptions } from "./main";
|
import type { CliCommandOptions } from "./main";
|
||||||
import { getBuildContext } from "./shared/buildContext";
|
import { getBuildContext } from "./shared/buildContext";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
@ -53,17 +52,13 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
console.log(`→ ${pageId}`);
|
console.log(`→ ${pageId}`);
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
|
||||||
projectDirPath: buildContext.projectDirPath
|
|
||||||
});
|
|
||||||
|
|
||||||
const componentBasename = capitalize(kebabCaseToCamelCase(pageId)).replace(
|
const componentBasename = capitalize(kebabCaseToCamelCase(pageId)).replace(
|
||||||
/ftl$/,
|
/ftl$/,
|
||||||
"stories.tsx"
|
"stories.tsx"
|
||||||
);
|
);
|
||||||
|
|
||||||
const targetFilePath = pathJoin(
|
const targetFilePath = pathJoin(
|
||||||
themeSrcDirPath,
|
buildContext.themeSrcDirPath,
|
||||||
themeType,
|
themeType,
|
||||||
"pages",
|
"pages",
|
||||||
componentBasename
|
componentBasename
|
||||||
@ -103,7 +98,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
`${chalk.green("✓")} ${chalk.bold(
|
`${chalk.green("✓")} ${chalk.bold(
|
||||||
pathJoin(".", pathRelative(process.cwd(), targetFilePath))
|
pathJoin(".", pathRelative(process.cwd(), targetFilePath))
|
||||||
)} copy pasted from the Keycloakify source code into your project`,
|
)} copy pasted from the Keycloakify source code into your project`,
|
||||||
`You can start storybook with ${chalk.bold("yarn storybook")}`
|
`You can start storybook with ${chalk.bold("npm run storybook")}`
|
||||||
].join("\n")
|
].join("\n")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import * as fs from "fs";
|
|||||||
import { join as pathJoin, relative as pathRelative, dirname as pathDirname } from "path";
|
import { join as pathJoin, relative as pathRelative, dirname as pathDirname } from "path";
|
||||||
import { kebabCaseToCamelCase } from "./tools/kebabCaseToSnakeCase";
|
import { kebabCaseToCamelCase } from "./tools/kebabCaseToSnakeCase";
|
||||||
import { assert, Equals } from "tsafe/assert";
|
import { assert, Equals } from "tsafe/assert";
|
||||||
import { getThemeSrcDirPath } from "./shared/getThemeSrcDirPath";
|
|
||||||
import type { CliCommandOptions } from "./main";
|
import type { CliCommandOptions } from "./main";
|
||||||
import { getBuildContext } from "./shared/buildContext";
|
import { getBuildContext } from "./shared/buildContext";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
@ -68,10 +67,6 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
console.log(`→ ${pageIdOrComponent}`);
|
console.log(`→ ${pageIdOrComponent}`);
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
|
||||||
projectDirPath: buildContext.projectDirPath
|
|
||||||
});
|
|
||||||
|
|
||||||
const componentBasename = (() => {
|
const componentBasename = (() => {
|
||||||
if (pageIdOrComponent === templateValue) {
|
if (pageIdOrComponent === templateValue) {
|
||||||
return "Template.tsx";
|
return "Template.tsx";
|
||||||
@ -96,7 +91,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
const targetFilePath = pathJoin(
|
const targetFilePath = pathJoin(
|
||||||
themeSrcDirPath,
|
buildContext.themeSrcDirPath,
|
||||||
themeType,
|
themeType,
|
||||||
pagesOrDot,
|
pagesOrDot,
|
||||||
componentBasename
|
componentBasename
|
||||||
@ -149,7 +144,11 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
break edit_KcApp;
|
break edit_KcApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
const kcAppTsxPath = pathJoin(themeSrcDirPath, themeType, "KcPage.tsx");
|
const kcAppTsxPath = pathJoin(
|
||||||
|
buildContext.themeSrcDirPath,
|
||||||
|
themeType,
|
||||||
|
"KcPage.tsx"
|
||||||
|
);
|
||||||
|
|
||||||
const kcAppTsxCode = fs.readFileSync(kcAppTsxPath).toString("utf8");
|
const kcAppTsxCode = fs.readFileSync(kcAppTsxPath).toString("utf8");
|
||||||
|
|
||||||
@ -191,6 +190,8 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
const userProfileFormFieldComponentName = "UserProfileFormFields";
|
const userProfileFormFieldComponentName = "UserProfileFormFields";
|
||||||
|
|
||||||
|
const componentName = componentBasename.replace(/.tsx$/, "");
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
[
|
[
|
||||||
``,
|
``,
|
||||||
@ -199,7 +200,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
`${chalk.bold(
|
`${chalk.bold(
|
||||||
pathJoin(
|
pathJoin(
|
||||||
".",
|
".",
|
||||||
pathRelative(process.cwd(), themeSrcDirPath),
|
pathRelative(process.cwd(), buildContext.themeSrcDirPath),
|
||||||
themeType,
|
themeType,
|
||||||
"KcPage.tsx"
|
"KcPage.tsx"
|
||||||
)
|
)
|
||||||
@ -208,10 +209,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
`// ...`,
|
`// ...`,
|
||||||
``,
|
``,
|
||||||
chalk.green(
|
chalk.green(
|
||||||
`+const ${componentBasename.replace(
|
`+const ${componentName} = lazy(() => import("./pages/${componentName}"));`
|
||||||
/.tsx$/,
|
|
||||||
""
|
|
||||||
)} = lazy(() => import("./pages/${componentBasename}"));`
|
|
||||||
),
|
),
|
||||||
...[
|
...[
|
||||||
``,
|
``,
|
||||||
@ -225,7 +223,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
` switch (kcContext.pageId) {`,
|
` switch (kcContext.pageId) {`,
|
||||||
` // ...`,
|
` // ...`,
|
||||||
`+ case "${pageIdOrComponent}": return (`,
|
`+ case "${pageIdOrComponent}": return (`,
|
||||||
`+ <${componentBasename}`,
|
`+ <${componentName}`,
|
||||||
`+ {...{ kcContext, i18n, classes }}`,
|
`+ {...{ kcContext, i18n, classes }}`,
|
||||||
`+ Template={Template}`,
|
`+ Template={Template}`,
|
||||||
`+ doUseDefaultCss={true}`,
|
`+ doUseDefaultCss={true}`,
|
||||||
|
@ -4,7 +4,6 @@ import { transformCodebase } from "./tools/transformCodebase";
|
|||||||
import { promptKeycloakVersion } from "./shared/promptKeycloakVersion";
|
import { promptKeycloakVersion } from "./shared/promptKeycloakVersion";
|
||||||
import { getBuildContext } from "./shared/buildContext";
|
import { getBuildContext } from "./shared/buildContext";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { getThemeSrcDirPath } from "./shared/getThemeSrcDirPath";
|
|
||||||
import type { CliCommandOptions } from "./main";
|
import type { CliCommandOptions } from "./main";
|
||||||
|
|
||||||
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
||||||
@ -12,11 +11,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
const buildContext = getBuildContext({ cliCommandOptions });
|
const buildContext = getBuildContext({ cliCommandOptions });
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
const emailThemeSrcDirPath = pathJoin(buildContext.themeSrcDirPath, "email");
|
||||||
projectDirPath: buildContext.projectDirPath
|
|
||||||
});
|
|
||||||
|
|
||||||
const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email");
|
|
||||||
|
|
||||||
if (fs.existsSync(emailThemeSrcDirPath)) {
|
if (fs.existsSync(emailThemeSrcDirPath)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
@ -16,7 +16,7 @@ import { readFileSync } from "fs";
|
|||||||
import { isInside } from "../../tools/isInside";
|
import { isInside } from "../../tools/isInside";
|
||||||
import child_process from "child_process";
|
import child_process from "child_process";
|
||||||
import { rmSync } from "../../tools/fs.rmSync";
|
import { rmSync } from "../../tools/fs.rmSync";
|
||||||
import { getMetaInfKeycloakThemesJsonFilePath } from "../../shared/metaInfKeycloakThemes";
|
import { writeMetaInfKeycloakThemes } from "../../shared/metaInfKeycloakThemes";
|
||||||
|
|
||||||
export type BuildContextLike = BuildContextLike_generatePom & {
|
export type BuildContextLike = BuildContextLike_generatePom & {
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
@ -50,9 +50,16 @@ export async function buildJar(params: {
|
|||||||
|
|
||||||
rmSync(keycloakifyBuildTmpDirPath, { recursive: true, force: true });
|
rmSync(keycloakifyBuildTmpDirPath, { recursive: true, force: true });
|
||||||
|
|
||||||
|
const tmpResourcesDirPath = pathJoin(
|
||||||
|
keycloakifyBuildTmpDirPath,
|
||||||
|
"src",
|
||||||
|
"main",
|
||||||
|
"resources"
|
||||||
|
);
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: resourcesDirPath,
|
srcDirPath: resourcesDirPath,
|
||||||
destDirPath: pathJoin(keycloakifyBuildTmpDirPath, "src", "main", "resources"),
|
destDirPath: tmpResourcesDirPath,
|
||||||
transformSourceCode:
|
transformSourceCode:
|
||||||
keycloakAccountV1Version !== null
|
keycloakAccountV1Version !== null
|
||||||
? undefined
|
? undefined
|
||||||
@ -71,31 +78,6 @@ export async function buildJar(params: {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
fileRelativePath ===
|
|
||||||
getMetaInfKeycloakThemesJsonFilePath({
|
|
||||||
resourcesDirPath: "."
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
const keycloakThemesJsonParsed = JSON.parse(
|
|
||||||
sourceCode.toString("utf8")
|
|
||||||
) as {
|
|
||||||
themes: { name: string; types: string[] }[];
|
|
||||||
};
|
|
||||||
|
|
||||||
keycloakThemesJsonParsed.themes =
|
|
||||||
keycloakThemesJsonParsed.themes.filter(
|
|
||||||
({ name }) => name !== accountV1ThemeName
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
modifiedSourceCode: Buffer.from(
|
|
||||||
JSON.stringify(keycloakThemesJsonParsed, null, 2),
|
|
||||||
"utf8"
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const themeName of buildContext.themeNames) {
|
for (const themeName of buildContext.themeNames) {
|
||||||
if (
|
if (
|
||||||
fileRelativePath ===
|
fileRelativePath ===
|
||||||
@ -123,6 +105,21 @@ export async function buildJar(params: {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (keycloakAccountV1Version === null) {
|
||||||
|
writeMetaInfKeycloakThemes({
|
||||||
|
resourcesDirPath: tmpResourcesDirPath,
|
||||||
|
getNewMetaInfKeycloakTheme: ({ metaInfKeycloakTheme }) => {
|
||||||
|
assert(metaInfKeycloakTheme !== undefined);
|
||||||
|
|
||||||
|
metaInfKeycloakTheme.themes = metaInfKeycloakTheme.themes.filter(
|
||||||
|
({ name }) => name !== accountV1ThemeName
|
||||||
|
);
|
||||||
|
|
||||||
|
return metaInfKeycloakTheme;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
route_legacy_pages: {
|
route_legacy_pages: {
|
||||||
// NOTE: If there's no account theme there is no special target for keycloak 24 and up so we create
|
// NOTE: If there's no account theme there is no special target for keycloak 24 and up so we create
|
||||||
// the pages anyway. If there is an account pages, since we know that account-v1 is only support keycloak
|
// the pages anyway. If there is an account pages, since we know that account-v1 is only support keycloak
|
||||||
@ -168,8 +165,8 @@ export async function buildJar(params: {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
const modifiedFtlFileContent = ftlFileContent.replace(
|
const modifiedFtlFileContent = ftlFileContent.replace(
|
||||||
`out["pageId"] = "\${pageId}";`,
|
`kcContext.pageId = "\${pageId}";`,
|
||||||
`out["pageId"] = "${pageId}"; out["realPageId"] = "${realPageId}";`
|
`kcContext.pageId = "${pageId}"; kcContext.realPageId = "${realPageId}";`
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(modifiedFtlFileContent !== ftlFileContent);
|
assert(modifiedFtlFileContent !== ftlFileContent);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { exclude } from "tsafe/exclude";
|
|
||||||
import {
|
import {
|
||||||
keycloakAccountV1Versions,
|
keycloakAccountV1Versions,
|
||||||
keycloakThemeAdditionalInfoExtensionVersions
|
keycloakThemeAdditionalInfoExtensionVersions
|
||||||
@ -7,32 +6,29 @@ import {
|
|||||||
import { getKeycloakVersionRangeForJar } from "./getKeycloakVersionRangeForJar";
|
import { getKeycloakVersionRangeForJar } from "./getKeycloakVersionRangeForJar";
|
||||||
import { buildJar, BuildContextLike as BuildContextLike_buildJar } from "./buildJar";
|
import { buildJar, BuildContextLike as BuildContextLike_buildJar } from "./buildJar";
|
||||||
import type { BuildContext } from "../../shared/buildContext";
|
import type { BuildContext } from "../../shared/buildContext";
|
||||||
import { getJarFileBasename } from "../../shared/getJarFileBasename";
|
|
||||||
import { readMetaInfKeycloakThemes_fromResourcesDirPath } from "../../shared/metaInfKeycloakThemes";
|
|
||||||
import { accountV1ThemeName } from "../../shared/constants";
|
|
||||||
|
|
||||||
export type BuildContextLike = BuildContextLike_buildJar & {
|
export type BuildContextLike = BuildContextLike_buildJar & {
|
||||||
|
projectDirPath: string;
|
||||||
keycloakifyBuildDirPath: string;
|
keycloakifyBuildDirPath: string;
|
||||||
|
recordIsImplementedByThemeType: BuildContext["recordIsImplementedByThemeType"];
|
||||||
|
jarTargets: BuildContext["jarTargets"];
|
||||||
};
|
};
|
||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
export async function buildJars(params: {
|
export async function buildJars(params: {
|
||||||
resourcesDirPath: string;
|
resourcesDirPath: string;
|
||||||
onlyBuildJarFileBasename: string | undefined;
|
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { onlyBuildJarFileBasename, resourcesDirPath, buildContext } = params;
|
const { resourcesDirPath, buildContext } = params;
|
||||||
|
|
||||||
const doesImplementAccountTheme = readMetaInfKeycloakThemes_fromResourcesDirPath({
|
const doesImplementAccountTheme = buildContext.recordIsImplementedByThemeType.account;
|
||||||
resourcesDirPath
|
|
||||||
}).themes.some(({ name }) => name === accountV1ThemeName);
|
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
keycloakAccountV1Versions
|
keycloakAccountV1Versions
|
||||||
.map(keycloakAccountV1Version =>
|
.map(keycloakAccountV1Version =>
|
||||||
keycloakThemeAdditionalInfoExtensionVersions
|
keycloakThemeAdditionalInfoExtensionVersions.map(
|
||||||
.map(keycloakThemeAdditionalInfoExtensionVersion => {
|
keycloakThemeAdditionalInfoExtensionVersion => {
|
||||||
const keycloakVersionRange = getKeycloakVersionRangeForJar({
|
const keycloakVersionRange = getKeycloakVersionRangeForJar({
|
||||||
doesImplementAccountTheme,
|
doesImplementAccountTheme,
|
||||||
keycloakAccountV1Version,
|
keycloakAccountV1Version,
|
||||||
@ -43,48 +39,26 @@ export async function buildJars(params: {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const jarTarget = buildContext.jarTargets.find(
|
||||||
keycloakThemeAdditionalInfoExtensionVersion,
|
jarTarget =>
|
||||||
keycloakVersionRange
|
jarTarget.keycloakVersionRange === keycloakVersionRange
|
||||||
};
|
);
|
||||||
})
|
|
||||||
.filter(exclude(undefined))
|
|
||||||
.map(
|
|
||||||
({
|
|
||||||
keycloakThemeAdditionalInfoExtensionVersion,
|
|
||||||
keycloakVersionRange
|
|
||||||
}) => {
|
|
||||||
const { jarFileBasename } = getJarFileBasename({
|
|
||||||
keycloakVersionRange
|
|
||||||
});
|
|
||||||
|
|
||||||
if (
|
if (jarTarget === undefined) {
|
||||||
onlyBuildJarFileBasename !== undefined &&
|
return undefined;
|
||||||
onlyBuildJarFileBasename !== jarFileBasename
|
|
||||||
) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
keycloakThemeAdditionalInfoExtensionVersion,
|
|
||||||
jarFileBasename
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
.filter(exclude(undefined))
|
const { jarFileBasename } = jarTarget;
|
||||||
.map(
|
|
||||||
({
|
return buildJar({
|
||||||
|
jarFileBasename,
|
||||||
|
keycloakAccountV1Version,
|
||||||
keycloakThemeAdditionalInfoExtensionVersion,
|
keycloakThemeAdditionalInfoExtensionVersion,
|
||||||
jarFileBasename
|
resourcesDirPath,
|
||||||
}) =>
|
buildContext
|
||||||
buildJar({
|
});
|
||||||
jarFileBasename,
|
}
|
||||||
keycloakAccountV1Version,
|
)
|
||||||
keycloakThemeAdditionalInfoExtensionVersion,
|
|
||||||
resourcesDirPath,
|
|
||||||
buildContext
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.flat()
|
.flat()
|
||||||
);
|
);
|
||||||
|
@ -42,7 +42,7 @@ export function generatePom(params: {
|
|||||||
` <properties>`,
|
` <properties>`,
|
||||||
` <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>`,
|
` <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>`,
|
||||||
` </properties>`,
|
` </properties>`,
|
||||||
...(keycloakAccountV1Version !== null &&
|
...(keycloakAccountV1Version !== null ||
|
||||||
keycloakThemeAdditionalInfoExtensionVersion !== null
|
keycloakThemeAdditionalInfoExtensionVersion !== null
|
||||||
? [
|
? [
|
||||||
` <build>`,
|
` <build>`,
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import cheerio from "cheerio";
|
import cheerio from "cheerio";
|
||||||
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
||||||
import { generateCssCodeToDefineGlobals } from "../replacers/replaceImportsInCssCode";
|
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
||||||
import { replaceImportsInInlineCssCode } from "../replacers/replaceImportsInInlineCssCode";
|
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import type { BuildContext } from "../../shared/buildContext";
|
import type { BuildContext } from "../../shared/buildContext";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import {
|
import {
|
||||||
type ThemeType,
|
type ThemeType,
|
||||||
nameOfTheGlobal,
|
|
||||||
basenameOfTheKeycloakifyResourcesDir,
|
basenameOfTheKeycloakifyResourcesDir,
|
||||||
resources_common,
|
resources_common,
|
||||||
nameOfTheLocalizationRealmOverridesUserProfileProperty
|
nameOfTheLocalizationRealmOverridesUserProfileProperty
|
||||||
@ -29,7 +27,6 @@ assert<BuildContext extends BuildContextLike ? true : false>();
|
|||||||
export function generateFtlFilesCodeFactory(params: {
|
export function generateFtlFilesCodeFactory(params: {
|
||||||
themeName: string;
|
themeName: string;
|
||||||
indexHtmlCode: string;
|
indexHtmlCode: string;
|
||||||
cssGlobalsToDefine: Record<string, string>;
|
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
keycloakifyVersion: string;
|
keycloakifyVersion: string;
|
||||||
themeType: ThemeType;
|
themeType: ThemeType;
|
||||||
@ -37,7 +34,6 @@ export function generateFtlFilesCodeFactory(params: {
|
|||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
themeName,
|
themeName,
|
||||||
cssGlobalsToDefine,
|
|
||||||
indexHtmlCode,
|
indexHtmlCode,
|
||||||
buildContext,
|
buildContext,
|
||||||
keycloakifyVersion,
|
keycloakifyVersion,
|
||||||
@ -66,8 +62,9 @@ export function generateFtlFilesCodeFactory(params: {
|
|||||||
|
|
||||||
assert(cssCode !== null);
|
assert(cssCode !== null);
|
||||||
|
|
||||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
const { fixedCssCode } = replaceImportsInCssCode({
|
||||||
cssCode,
|
cssCode,
|
||||||
|
cssFileRelativeDirPath: undefined,
|
||||||
buildContext
|
buildContext
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -98,25 +95,10 @@ export function generateFtlFilesCodeFactory(params: {
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Object.keys(cssGlobalsToDefine).length !== 0) {
|
|
||||||
$("head").prepend(
|
|
||||||
[
|
|
||||||
"",
|
|
||||||
"<style>",
|
|
||||||
generateCssCodeToDefineGlobals({
|
|
||||||
cssGlobalsToDefine,
|
|
||||||
buildContext
|
|
||||||
}).cssCodeToPrependInHead,
|
|
||||||
"</style>",
|
|
||||||
""
|
|
||||||
].join("\n")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
|
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
|
||||||
const ftlObjectToJsCodeDeclaringAnObject = fs
|
const kcContextDeclarationTemplateFtl = fs
|
||||||
.readFileSync(
|
.readFileSync(
|
||||||
pathJoin(
|
pathJoin(
|
||||||
getThisCodebaseRootDirPath(),
|
getThisCodebaseRootDirPath(),
|
||||||
@ -124,11 +106,10 @@ export function generateFtlFilesCodeFactory(params: {
|
|||||||
"bin",
|
"bin",
|
||||||
"keycloakify",
|
"keycloakify",
|
||||||
"generateFtl",
|
"generateFtl",
|
||||||
"ftl_object_to_js_code_declaring_an_object.ftl"
|
"kcContextDeclarationTemplate.ftl"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.toString("utf8")
|
.toString("utf8")
|
||||||
.match(/^<script>const _=((?:.|\n)+)<\/script>[\n]?$/)![1]
|
|
||||||
.replace(
|
.replace(
|
||||||
"FIELD_NAMES_eKsIY4ZsZ4xeM",
|
"FIELD_NAMES_eKsIY4ZsZ4xeM",
|
||||||
fieldNames.map(name => `"${name}"`).join(", ")
|
fieldNames.map(name => `"${name}"`).join(", ")
|
||||||
@ -150,7 +131,7 @@ export function generateFtlFilesCodeFactory(params: {
|
|||||||
'{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }';
|
'{ "x": "vIdLqMeOed9sdLdIdOxdK0d" }';
|
||||||
|
|
||||||
$("head").prepend(
|
$("head").prepend(
|
||||||
`<script>\nwindow.${nameOfTheGlobal}=${ftlObjectToJsCodeDeclaringAnObjectPlaceholder}</script>`
|
`<script>\n${ftlObjectToJsCodeDeclaringAnObjectPlaceholder}\n</script>`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove part of the document marked as ignored.
|
// Remove part of the document marked as ignored.
|
||||||
@ -189,7 +170,7 @@ export function generateFtlFilesCodeFactory(params: {
|
|||||||
|
|
||||||
Object.entries({
|
Object.entries({
|
||||||
[ftlObjectToJsCodeDeclaringAnObjectPlaceholder]:
|
[ftlObjectToJsCodeDeclaringAnObjectPlaceholder]:
|
||||||
ftlObjectToJsCodeDeclaringAnObject,
|
kcContextDeclarationTemplateFtl,
|
||||||
PAGE_ID_xIgLsPgGId9D8e: pageId
|
PAGE_ID_xIgLsPgGId9D8e: pageId
|
||||||
}).map(
|
}).map(
|
||||||
([searchValue, replaceValue]) =>
|
([searchValue, replaceValue]) =>
|
||||||
|
@ -1,172 +1,40 @@
|
|||||||
<script>const _=
|
|
||||||
(()=>{
|
|
||||||
<#assign pageId="PAGE_ID_xIgLsPgGId9D8e">
|
<#assign pageId="PAGE_ID_xIgLsPgGId9D8e">
|
||||||
const out = ${ftl_object_to_js_code_declaring_an_object(.data_model, [])?no_esc};
|
const kcContext = ${ftl_object_to_js_code_declaring_an_object(.data_model, [])?no_esc};
|
||||||
out["messagesPerField"]= {
|
if( kcContext.messagesPerField ){
|
||||||
<#assign fieldNames = [ FIELD_NAMES_eKsIY4ZsZ4xeM ]>
|
var existsError_singleFieldName = kcContext.messagesPerField.existsError;
|
||||||
<#attempt>
|
kcContext.messagesPerField.existsError = function (){
|
||||||
<#if profile?? && profile.attributes?? && profile.attributes?is_enumerable>
|
|
||||||
<#list profile.attributes as attribute>
|
|
||||||
<#if fieldNames?seq_contains(attribute.name)>
|
|
||||||
<#continue>
|
|
||||||
</#if>
|
|
||||||
<#assign fieldNames += [attribute.name]>
|
|
||||||
</#list>
|
|
||||||
</#if>
|
|
||||||
<#recover>
|
|
||||||
</#attempt>
|
|
||||||
"printIfExists": function (fieldName, text) {
|
|
||||||
<#if !messagesPerField?? || !(messagesPerField?is_hash)>
|
|
||||||
throw new Error("You're not supposed to use messagesPerField.printIfExists in this page");
|
|
||||||
<#else>
|
|
||||||
<#list fieldNames as fieldName>
|
|
||||||
if(fieldName === "${fieldName}" ){
|
|
||||||
<#-- https://github.com/keycloakify/keycloakify/pull/218 -->
|
|
||||||
<#if ('${fieldName}' == 'username' || '${fieldName}' == 'password') && pageId != 'register.ftl' && pageId != 'register-user-profile.ftl'>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = "">
|
|
||||||
<#attempt>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = messagesPerField.existsError('username', 'password')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = true>
|
|
||||||
</#attempt>
|
|
||||||
return <#if doExistErrorOnUsernameOrPassword>text<#else>undefined</#if>
|
|
||||||
<#else>
|
|
||||||
<#assign doExistMessageForField = "">
|
|
||||||
<#attempt>
|
|
||||||
<#assign doExistMessageForField = messagesPerField.exists('${fieldName}')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistMessageForField = true>
|
|
||||||
</#attempt>
|
|
||||||
return <#if doExistMessageForField>text<#else>undefined</#if>;
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
</#list>
|
|
||||||
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
|
||||||
</#if>
|
|
||||||
},
|
|
||||||
"existsError": function (){
|
|
||||||
function existsError_singleFieldName(fieldName) {
|
|
||||||
<#if !messagesPerField?? || !(messagesPerField?is_hash)>
|
|
||||||
throw new Error("You're not supposed to use messagesPerField.printIfExists in this page");
|
|
||||||
<#else>
|
|
||||||
<#list fieldNames as fieldName>
|
|
||||||
if(fieldName === "${fieldName}" ){
|
|
||||||
<#-- https://github.com/keycloakify/keycloakify/pull/218 -->
|
|
||||||
<#if ('${fieldName}' == 'username' || '${fieldName}' == 'password') && pageId != 'register.ftl' && pageId != 'register-user-profile.ftl'>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = "">
|
|
||||||
<#attempt>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = messagesPerField.existsError('username', 'password')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = true>
|
|
||||||
</#attempt>
|
|
||||||
return <#if doExistErrorOnUsernameOrPassword>true<#else>false</#if>;
|
|
||||||
<#else>
|
|
||||||
<#assign doExistErrorMessageForField = "">
|
|
||||||
<#attempt>
|
|
||||||
<#assign doExistErrorMessageForField = messagesPerField.existsError('${fieldName}')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorMessageForField = true>
|
|
||||||
</#attempt>
|
|
||||||
return <#if doExistErrorMessageForField>true<#else>false</#if>;
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
</#list>
|
|
||||||
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
for( let i = 0; i < arguments.length; i++ ){
|
for( let i = 0; i < arguments.length; i++ ){
|
||||||
if( existsError_singleFieldName(arguments[i]) ){
|
if( existsError_singleFieldName(arguments[i]) ){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
};
|
||||||
"get": function (fieldName) {
|
kcContext.messagesPerField.exists = function (fieldName) {
|
||||||
<#if !messagesPerField?? || !(messagesPerField?is_hash)>
|
return kcContext.messagesPerField.get(fieldName) !== "";
|
||||||
throw new Error("You're not supposed to use messagesPerField.get in this page");
|
};
|
||||||
<#else>
|
kcContext.messagesPerField.printIfExists = function (fieldName, text) {
|
||||||
<#list fieldNames as fieldName>
|
return kcContext.messagesPerField.exists(fieldName) ? text : undefined;
|
||||||
if(fieldName === "${fieldName}" ){
|
};
|
||||||
<#-- https://github.com/keycloakify/keycloakify/pull/218 -->
|
kcContext.messagesPerField.getFirstError = function () {
|
||||||
<#if ('${fieldName}' == 'username' || '${fieldName}' == 'password') && pageId != 'register.ftl' && pageId != 'register-user-profile.ftl'>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = "">
|
|
||||||
<#attempt>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = messagesPerField.existsError('username', 'password')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = true>
|
|
||||||
</#attempt>
|
|
||||||
<#if doExistErrorOnUsernameOrPassword>
|
|
||||||
<#attempt>
|
|
||||||
return decodeHtmlEntities("${msg('invalidUserMessage')?js_string}");
|
|
||||||
<#recover>
|
|
||||||
return "Invalid username or password.";
|
|
||||||
</#attempt>
|
|
||||||
<#else>
|
|
||||||
return "";
|
|
||||||
</#if>
|
|
||||||
<#else>
|
|
||||||
<#attempt>
|
|
||||||
return decodeHtmlEntities("${messagesPerField.get('${fieldName}')?js_string}");
|
|
||||||
<#recover>
|
|
||||||
return "Invalid field";
|
|
||||||
</#attempt>
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
</#list>
|
|
||||||
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
|
||||||
</#if>
|
|
||||||
},
|
|
||||||
"exists": function (fieldName) {
|
|
||||||
<#if !messagesPerField?? || !(messagesPerField?is_hash)>
|
|
||||||
throw new Error("You're not supposed to use messagesPerField.exists in this page");
|
|
||||||
<#else>
|
|
||||||
<#list fieldNames as fieldName>
|
|
||||||
if(fieldName === "${fieldName}" ){
|
|
||||||
<#-- https://github.com/keycloakify/keycloakify/pull/218 -->
|
|
||||||
<#if ('${fieldName}' == 'username' || '${fieldName}' == 'password') && pageId != 'register.ftl' && pageId != 'register-user-profile.ftl'>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = "">
|
|
||||||
<#attempt>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = messagesPerField.existsError('username', 'password')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorOnUsernameOrPassword = true>
|
|
||||||
</#attempt>
|
|
||||||
return <#if doExistErrorOnUsernameOrPassword>true<#else>false</#if>;
|
|
||||||
<#else>
|
|
||||||
<#assign doExistErrorMessageForField = "">
|
|
||||||
<#attempt>
|
|
||||||
<#assign doExistErrorMessageForField = messagesPerField.exists('${fieldName}')>
|
|
||||||
<#recover>
|
|
||||||
<#assign doExistErrorMessageForField = true>
|
|
||||||
</#attempt>
|
|
||||||
return <#if doExistErrorMessageForField>true<#else>false</#if>;
|
|
||||||
</#if>
|
|
||||||
}
|
|
||||||
</#list>
|
|
||||||
throw new Error(fieldName + "is probably runtime generated, see: https://docs.keycloakify.dev/limitations#field-names-cant-be-runtime-generated");
|
|
||||||
</#if>
|
|
||||||
},
|
|
||||||
"getFirstError": function () {
|
|
||||||
for( let i = 0; i < arguments.length; i++ ){
|
for( let i = 0; i < arguments.length; i++ ){
|
||||||
const fieldName = arguments[i];
|
const fieldName = arguments[i];
|
||||||
if( out.messagesPerField.existsError(fieldName) ){
|
if( kcContext.messagesPerField.existsError(fieldName) ){
|
||||||
return out.messagesPerField.get(fieldName);
|
return kcContext.messagesPerField.get(fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
|
kcContext.keycloakifyVersion = "KEYCLOAKIFY_VERSION_xEdKd3xEdr";
|
||||||
out["keycloakifyVersion"] = "KEYCLOAKIFY_VERSION_xEdKd3xEdr";
|
kcContext.themeVersion = "KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx";
|
||||||
out["themeVersion"] = "KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx";
|
kcContext.themeType = "KEYCLOAKIFY_THEME_TYPE_dExKd3xEdr";
|
||||||
out["themeType"] = "KEYCLOAKIFY_THEME_TYPE_dExKd3xEdr";
|
kcContext.themeName = "KEYCLOAKIFY_THEME_NAME_cXxKd3xEer";
|
||||||
out["themeName"] = "KEYCLOAKIFY_THEME_NAME_cXxKd3xEer";
|
kcContext.pageId = "${pageId}";
|
||||||
out["pageId"] = "${pageId}";
|
if( kcContext.url && kcContext.url.resourcesPath ){
|
||||||
|
kcContext.url.resourcesCommonPath = kcContext.url.resourcesPath + "/" + "RESOURCES_COMMON_cLsLsMrtDkpVv";
|
||||||
try {
|
}
|
||||||
out["url"]["resourcesCommonPath"] = out["url"]["resourcesPath"] + "/" + "RESOURCES_COMMON_cLsLsMrtDkpVv";
|
|
||||||
} catch(error) { }
|
|
||||||
|
|
||||||
<#if profile?? && profile.attributes??>
|
<#if profile?? && profile.attributes??>
|
||||||
out["lOCALIZATION_REALM_OVERRIDES_USER_PROFILE_PROPERTY_KEY_aaGLsPgGIdeeX"] = {
|
kcContext.lOCALIZATION_REALM_OVERRIDES_USER_PROFILE_PROPERTY_KEY_aaGLsPgGIdeeX = {
|
||||||
<#list profile.attributes as attribute>
|
<#list profile.attributes as attribute>
|
||||||
<#if attribute.annotations?? && attribute.displayName??>
|
<#if attribute.annotations?? && attribute.displayName??>
|
||||||
"${attribute.displayName}": decodeHtmlEntities("${advancedMsg(attribute.displayName)?js_string}"),
|
"${attribute.displayName}": decodeHtmlEntities("${advancedMsg(attribute.displayName)?js_string}"),
|
||||||
@ -193,31 +61,21 @@ try {
|
|||||||
</#list>
|
</#list>
|
||||||
};
|
};
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
attributes_to_attributesByName: {
|
attributes_to_attributesByName: {
|
||||||
|
if( !kcContext.profile ){
|
||||||
if( !out["profile"] ){
|
|
||||||
break attributes_to_attributesByName;
|
break attributes_to_attributesByName;
|
||||||
}
|
}
|
||||||
|
if( !kcContext.profile.attributes ){
|
||||||
if( !out["profile"]["attributes"] ){
|
|
||||||
break attributes_to_attributesByName;
|
break attributes_to_attributesByName;
|
||||||
}
|
}
|
||||||
|
var attributes = kcContext.profile.attributes;
|
||||||
var attributes = out["profile"]["attributes"];
|
delete kcContext.profile.attributes;
|
||||||
|
kcContext.profile.attributesByName = {};
|
||||||
delete out["profile"]["attributes"];
|
|
||||||
|
|
||||||
out["profile"]["attributesByName"] = {};
|
|
||||||
|
|
||||||
attributes.forEach(function(attribute){
|
attributes.forEach(function(attribute){
|
||||||
out["profile"]["attributesByName"][attribute.name] = attribute;
|
kcContext.profile.attributesByName[attribute.name] = attribute;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
window.kcContext = kcContext;
|
||||||
return out;
|
|
||||||
|
|
||||||
function decodeHtmlEntities(htmlStr){
|
function decodeHtmlEntities(htmlStr){
|
||||||
var element = decodeHtmlEntities.element;
|
var element = decodeHtmlEntities.element;
|
||||||
if (!element) {
|
if (!element) {
|
||||||
@ -228,7 +86,6 @@ function decodeHtmlEntities(htmlStr){
|
|||||||
return element.value;
|
return element.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
|
||||||
<#function ftl_object_to_js_code_declaring_an_object object path>
|
<#function ftl_object_to_js_code_declaring_an_object object path>
|
||||||
|
|
||||||
<#local isHash = "">
|
<#local isHash = "">
|
||||||
@ -326,9 +183,24 @@ function decodeHtmlEntities(htmlStr){
|
|||||||
<#-- We already have the attributes in profile speedup the rendering by filtering it out from the register object -->
|
<#-- We already have the attributes in profile speedup the rendering by filtering it out from the register object -->
|
||||||
(key == "attributes" || key == "attributesByName") &&
|
(key == "attributes" || key == "attributesByName") &&
|
||||||
are_same_path(path, ["register"])
|
are_same_path(path, ["register"])
|
||||||
|
) || (
|
||||||
|
are_same_path(path, ["properties"]) &&
|
||||||
|
(
|
||||||
|
key?starts_with("kc") ||
|
||||||
|
key == "locales" ||
|
||||||
|
key == "import" ||
|
||||||
|
key == "parent" ||
|
||||||
|
key == "meta" ||
|
||||||
|
key == "stylesCommon" ||
|
||||||
|
key == "styles" ||
|
||||||
|
key == "accountResourceProvider"
|
||||||
|
)
|
||||||
|
) || (
|
||||||
|
key == "execution" &&
|
||||||
|
are_same_path(path, [])
|
||||||
)
|
)
|
||||||
>
|
>
|
||||||
<#local out_seq += ["/*" + path?join(".") + "." + key + " excluded*/"]>
|
<#-- <#local out_seq += ["/*" + path?join(".") + "." + key + " excluded*/"]> -->
|
||||||
<#continue>
|
<#continue>
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
@ -433,15 +305,121 @@ function decodeHtmlEntities(htmlStr){
|
|||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
<#if are_same_path(path, ["totp", "policy", "getAlgorithmKey"])>
|
<#if are_same_path(path, ["totp", "policy", "getAlgorithmKey"])>
|
||||||
<#local returnValue = "">
|
<#local returnValue = "error">
|
||||||
<#attempt>
|
<#if mode?? && mode = "manual">
|
||||||
<#local returnValue = totp.policy.getAlgorithmKey()>
|
<#attempt>
|
||||||
<#recover>
|
<#local returnValue = totp.policy.getAlgorithmKey()>
|
||||||
<#return "ABORT: Couldn't evaluate totp.policy.getAlgorithmKey()">
|
<#recover>
|
||||||
</#attempt>
|
<#return "ABORT: Couldn't evaluate totp.policy.getAlgorithmKey()">
|
||||||
|
</#attempt>
|
||||||
|
</#if>
|
||||||
<#return 'function(){ return "' + returnValue + '"; }'>
|
<#return 'function(){ return "' + returnValue + '"; }'>
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
|
<#assign fieldNames = [ FIELD_NAMES_eKsIY4ZsZ4xeM ]>
|
||||||
|
<#if profile?? && profile.attributes??>
|
||||||
|
<#list profile.attributes as attribute>
|
||||||
|
<#if fieldNames?seq_contains(attribute.name)>
|
||||||
|
<#continue>
|
||||||
|
</#if>
|
||||||
|
<#assign fieldNames += [attribute.name]>
|
||||||
|
</#list>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if are_same_path(path, ["messagesPerField", "get"])>
|
||||||
|
|
||||||
|
<#local jsFunctionCode = "function (fieldName) { ">
|
||||||
|
|
||||||
|
<#list fieldNames as fieldName>
|
||||||
|
|
||||||
|
<#-- See: https://github.com/keycloakify/keycloakify/issues/217 -->
|
||||||
|
<#if pageId == "login.ftl" >
|
||||||
|
|
||||||
|
<#if fieldName == "username">
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "if(fieldName === 'username' || fieldName === 'password' ){ ">
|
||||||
|
|
||||||
|
<#if messagesPerField.exists('username') || messagesPerField.exists('password')>
|
||||||
|
<#local jsFunctionCode += "return kcContext.message && kcContext.message.summary ? kcContext.message.summary : 'error'; ">
|
||||||
|
<#else>
|
||||||
|
<#local jsFunctionCode += "return ''; ">
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "} ">
|
||||||
|
|
||||||
|
<#continue>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if fieldName == "password">
|
||||||
|
<#continue>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "if(fieldName === '" + fieldName + "'){ ">
|
||||||
|
|
||||||
|
<#if messagesPerField.exists('${fieldName}')>
|
||||||
|
<#local jsFunctionCode += 'return decodeHtmlEntities("' + messagesPerField.get('${fieldName}')?js_string + '"); '>
|
||||||
|
<#else>
|
||||||
|
<#local jsFunctionCode += "return ''; ">
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "} ">
|
||||||
|
|
||||||
|
</#list>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "}">
|
||||||
|
|
||||||
|
<#return jsFunctionCode>
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if are_same_path(path, ["messagesPerField", "existsError"])>
|
||||||
|
|
||||||
|
<#local jsFunctionCode = "function (fieldName) { ">
|
||||||
|
|
||||||
|
<#list fieldNames as fieldName>
|
||||||
|
|
||||||
|
<#-- See: https://github.com/keycloakify/keycloakify/issues/217 -->
|
||||||
|
<#if pageId == "login.ftl" >
|
||||||
|
<#if fieldName == "username">
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "if(fieldName === 'username' || fieldName === 'password' ){ ">
|
||||||
|
|
||||||
|
<#if messagesPerField.existsError('username') || messagesPerField.existsError('password')>
|
||||||
|
<#local jsFunctionCode += "return true; ">
|
||||||
|
<#else>
|
||||||
|
<#local jsFunctionCode += "return false; ">
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "} ">
|
||||||
|
|
||||||
|
<#continue>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if fieldName == "password">
|
||||||
|
<#continue>
|
||||||
|
</#if>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "if(fieldName === '" + fieldName + "' ){ ">
|
||||||
|
|
||||||
|
<#if messagesPerField.existsError('${fieldName}')>
|
||||||
|
<#local jsFunctionCode += 'return true; '>
|
||||||
|
<#else>
|
||||||
|
<#local jsFunctionCode += "return false; ">
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "}">
|
||||||
|
|
||||||
|
</#list>
|
||||||
|
|
||||||
|
<#local jsFunctionCode += "}">
|
||||||
|
|
||||||
|
<#return jsFunctionCode>
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
||||||
<#return "ABORT: It's a method">
|
<#return "ABORT: It's a method">
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
@ -573,4 +551,3 @@ function decodeHtmlEntities(htmlStr){
|
|||||||
<#function are_same_path path searchedPath>
|
<#function are_same_path path searchedPath>
|
||||||
<#return path?size == searchedPath?size && is_subpath(path, searchedPath)>
|
<#return path?size == searchedPath?size && is_subpath(path, searchedPath)>
|
||||||
</#function>
|
</#function>
|
||||||
</script>
|
|
@ -1,20 +1,20 @@
|
|||||||
import type { BuildContext } from "../../shared/buildContext";
|
import type { BuildContext } from "../../shared/buildContext";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import {
|
import {
|
||||||
generateSrcMainResourcesForMainTheme,
|
generateResourcesForMainTheme,
|
||||||
type BuildContextLike as BuildContextLike_generateSrcMainResourcesForMainTheme
|
type BuildContextLike as BuildContextLike_generateResourcesForMainTheme
|
||||||
} from "./generateSrcMainResourcesForMainTheme";
|
} from "./generateResourcesForMainTheme";
|
||||||
import { generateSrcMainResourcesForThemeVariant } from "./generateSrcMainResourcesForThemeVariant";
|
import { generateResourcesForThemeVariant } from "./generateResourcesForThemeVariant";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { rmSync } from "../../tools/fs.rmSync";
|
import { rmSync } from "../../tools/fs.rmSync";
|
||||||
|
|
||||||
export type BuildContextLike = BuildContextLike_generateSrcMainResourcesForMainTheme & {
|
export type BuildContextLike = BuildContextLike_generateResourcesForMainTheme & {
|
||||||
themeNames: string[];
|
themeNames: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
export async function generateSrcMainResources(params: {
|
export async function generateResources(params: {
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
resourcesDirPath: string;
|
resourcesDirPath: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
@ -26,14 +26,14 @@ export async function generateSrcMainResources(params: {
|
|||||||
rmSync(resourcesDirPath, { recursive: true });
|
rmSync(resourcesDirPath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
await generateSrcMainResourcesForMainTheme({
|
await generateResourcesForMainTheme({
|
||||||
resourcesDirPath,
|
resourcesDirPath,
|
||||||
themeName,
|
themeName,
|
||||||
buildContext
|
buildContext
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const themeVariantName of themeVariantNames) {
|
for (const themeVariantName of themeVariantNames) {
|
||||||
generateSrcMainResourcesForThemeVariant({
|
generateResourcesForThemeVariant({
|
||||||
resourcesDirPath,
|
resourcesDirPath,
|
||||||
themeName,
|
themeName,
|
||||||
themeVariantName
|
themeVariantName
|
@ -1,6 +1,11 @@
|
|||||||
import { transformCodebase } from "../../tools/transformCodebase";
|
import { transformCodebase } from "../../tools/transformCodebase";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { join as pathJoin, resolve as pathResolve } from "path";
|
import {
|
||||||
|
join as pathJoin,
|
||||||
|
resolve as pathResolve,
|
||||||
|
relative as pathRelative,
|
||||||
|
dirname as pathDirname
|
||||||
|
} from "path";
|
||||||
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
||||||
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
||||||
import {
|
import {
|
||||||
@ -16,7 +21,6 @@ import {
|
|||||||
loginThemePageIds,
|
loginThemePageIds,
|
||||||
accountThemePageIds
|
accountThemePageIds
|
||||||
} from "../../shared/constants";
|
} from "../../shared/constants";
|
||||||
import { isInside } from "../../tools/isInside";
|
|
||||||
import type { BuildContext } from "../../shared/buildContext";
|
import type { BuildContext } from "../../shared/buildContext";
|
||||||
import { assert, type Equals } from "tsafe/assert";
|
import { assert, type Equals } from "tsafe/assert";
|
||||||
import {
|
import {
|
||||||
@ -30,7 +34,6 @@ import {
|
|||||||
bringInAccountV1,
|
bringInAccountV1,
|
||||||
type BuildContextLike as BuildContextLike_bringInAccountV1
|
type BuildContextLike as BuildContextLike_bringInAccountV1
|
||||||
} from "./bringInAccountV1";
|
} from "./bringInAccountV1";
|
||||||
import { getThemeSrcDirPath } from "../../shared/getThemeSrcDirPath";
|
|
||||||
import { rmSync } from "../../tools/fs.rmSync";
|
import { rmSync } from "../../tools/fs.rmSync";
|
||||||
import { readThisNpmPackageVersion } from "../../tools/readThisNpmPackageVersion";
|
import { readThisNpmPackageVersion } from "../../tools/readThisNpmPackageVersion";
|
||||||
import {
|
import {
|
||||||
@ -48,41 +51,29 @@ export type BuildContextLike = BuildContextLike_kcContextExclusionsFtlCode &
|
|||||||
projectDirPath: string;
|
projectDirPath: string;
|
||||||
projectBuildDirPath: string;
|
projectBuildDirPath: string;
|
||||||
environmentVariables: { name: string; default: string }[];
|
environmentVariables: { name: string; default: string }[];
|
||||||
|
recordIsImplementedByThemeType: BuildContext["recordIsImplementedByThemeType"];
|
||||||
|
themeSrcDirPath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
export async function generateSrcMainResourcesForMainTheme(params: {
|
export async function generateResourcesForMainTheme(params: {
|
||||||
themeName: string;
|
themeName: string;
|
||||||
resourcesDirPath: string;
|
resourcesDirPath: string;
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { themeName, resourcesDirPath, buildContext } = params;
|
const { themeName, resourcesDirPath, buildContext } = params;
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
|
||||||
projectDirPath: buildContext.projectDirPath
|
|
||||||
});
|
|
||||||
|
|
||||||
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => {
|
const getThemeTypeDirPath = (params: { themeType: ThemeType | "email" }) => {
|
||||||
const { themeType } = params;
|
const { themeType } = params;
|
||||||
return pathJoin(resourcesDirPath, "theme", themeName, themeType);
|
return pathJoin(resourcesDirPath, "theme", themeName, themeType);
|
||||||
};
|
};
|
||||||
|
|
||||||
const cssGlobalsToDefine: Record<string, string> = {};
|
|
||||||
|
|
||||||
const implementedThemeTypes: Record<ThemeType | "email", boolean> = {
|
|
||||||
login: false,
|
|
||||||
account: false,
|
|
||||||
email: false
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const themeType of ["login", "account"] as const) {
|
for (const themeType of ["login", "account"] as const) {
|
||||||
if (!fs.existsSync(pathJoin(themeSrcDirPath, themeType))) {
|
if (!buildContext.recordIsImplementedByThemeType[themeType]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
implementedThemeTypes[themeType] = true;
|
|
||||||
|
|
||||||
const themeTypeDirPath = getThemeTypeDirPath({ themeType });
|
const themeTypeDirPath = getThemeTypeDirPath({ themeType });
|
||||||
|
|
||||||
apply_replacers_and_move_to_theme_resources: {
|
apply_replacers_and_move_to_theme_resources: {
|
||||||
@ -95,7 +86,10 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
// NOTE: Prevent accumulation of files in the assets dir, as names are hashed they pile up.
|
// NOTE: Prevent accumulation of files in the assets dir, as names are hashed they pile up.
|
||||||
rmSync(destDirPath, { recursive: true, force: true });
|
rmSync(destDirPath, { recursive: true, force: true });
|
||||||
|
|
||||||
if (themeType === "account" && implementedThemeTypes.login) {
|
if (
|
||||||
|
themeType === "account" &&
|
||||||
|
buildContext.recordIsImplementedByThemeType.login
|
||||||
|
) {
|
||||||
// NOTE: We prevent doing it twice, it has been done for the login theme.
|
// NOTE: We prevent doing it twice, it has been done for the login theme.
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
@ -112,44 +106,44 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
break apply_replacers_and_move_to_theme_resources;
|
break apply_replacers_and_move_to_theme_resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const dirPath = pathJoin(
|
||||||
|
buildContext.projectBuildDirPath,
|
||||||
|
keycloak_resources
|
||||||
|
);
|
||||||
|
|
||||||
|
if (fs.existsSync(dirPath)) {
|
||||||
|
assert(buildContext.bundler === "webpack");
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
[
|
||||||
|
`Keycloakify build error: The ${keycloak_resources} directory shouldn't exist in your build directory.`,
|
||||||
|
`(${pathRelative(process.cwd(), dirPath)}).\n`,
|
||||||
|
`Theses assets are only required for local development with Storybook.",
|
||||||
|
"Please remove this directory as an additional step of your command.\n`,
|
||||||
|
`For example: \`"build": "... && rimraf ${pathRelative(buildContext.projectDirPath, dirPath)}"\``
|
||||||
|
].join(" ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: buildContext.projectBuildDirPath,
|
srcDirPath: buildContext.projectBuildDirPath,
|
||||||
destDirPath,
|
destDirPath,
|
||||||
transformSourceCode: ({ filePath, sourceCode }) => {
|
transformSourceCode: ({ filePath, fileRelativePath, sourceCode }) => {
|
||||||
//NOTE: Prevent cycles, excludes the folder we generated for debug in public/
|
if (filePath.endsWith(".css")) {
|
||||||
// This should not happen if users follow the new instruction setup but we keep it for retrocompatibility.
|
const { fixedCssCode } = replaceImportsInCssCode({
|
||||||
if (
|
cssCode: sourceCode.toString("utf8"),
|
||||||
isInside({
|
cssFileRelativeDirPath: pathDirname(fileRelativePath),
|
||||||
dirPath: pathJoin(
|
buildContext
|
||||||
buildContext.projectBuildDirPath,
|
|
||||||
keycloak_resources
|
|
||||||
),
|
|
||||||
filePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (/\.css?$/i.test(filePath)) {
|
|
||||||
const {
|
|
||||||
cssGlobalsToDefine: cssGlobalsToDefineForThisFile,
|
|
||||||
fixedCssCode
|
|
||||||
} = replaceImportsInCssCode({
|
|
||||||
cssCode: sourceCode.toString("utf8")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.entries(cssGlobalsToDefineForThisFile).forEach(
|
|
||||||
([key, value]) => {
|
|
||||||
cssGlobalsToDefine[key] = value;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
modifiedSourceCode: Buffer.from(fixedCssCode, "utf8")
|
modifiedSourceCode: Buffer.from(fixedCssCode, "utf8")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/\.js?$/i.test(filePath)) {
|
if (filePath.endsWith(".js")) {
|
||||||
const { fixedJsCode } = replaceImportsInJsCode({
|
const { fixedJsCode } = replaceImportsInJsCode({
|
||||||
jsCode: sourceCode.toString("utf8"),
|
jsCode: sourceCode.toString("utf8"),
|
||||||
buildContext
|
buildContext
|
||||||
@ -170,12 +164,11 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
indexHtmlCode: fs
|
indexHtmlCode: fs
|
||||||
.readFileSync(pathJoin(buildContext.projectBuildDirPath, "index.html"))
|
.readFileSync(pathJoin(buildContext.projectBuildDirPath, "index.html"))
|
||||||
.toString("utf8"),
|
.toString("utf8"),
|
||||||
cssGlobalsToDefine,
|
|
||||||
buildContext,
|
buildContext,
|
||||||
keycloakifyVersion: readThisNpmPackageVersion(),
|
keycloakifyVersion: readThisNpmPackageVersion(),
|
||||||
themeType,
|
themeType,
|
||||||
fieldNames: readFieldNameUsage({
|
fieldNames: readFieldNameUsage({
|
||||||
themeSrcDirPath,
|
themeSrcDirPath: buildContext.themeSrcDirPath,
|
||||||
themeType
|
themeType
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -191,7 +184,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
})(),
|
})(),
|
||||||
...readExtraPagesNames({
|
...readExtraPagesNames({
|
||||||
themeType,
|
themeType,
|
||||||
themeSrcDirPath
|
themeSrcDirPath: buildContext.themeSrcDirPath
|
||||||
})
|
})
|
||||||
].forEach(pageId => {
|
].forEach(pageId => {
|
||||||
const { ftlCode } = generateFtlFilesCode({ pageId });
|
const { ftlCode } = generateFtlFilesCode({ pageId });
|
||||||
@ -203,7 +196,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
generateMessageProperties({
|
generateMessageProperties({
|
||||||
themeSrcDirPath,
|
themeSrcDirPath: buildContext.themeSrcDirPath,
|
||||||
themeType
|
themeType
|
||||||
}).forEach(({ languageTag, propertiesFileSource }) => {
|
}).forEach(({ languageTag, propertiesFileSource }) => {
|
||||||
const messagesDirPath = pathJoin(themeTypeDirPath, "messages");
|
const messagesDirPath = pathJoin(themeTypeDirPath, "messages");
|
||||||
@ -251,7 +244,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
assert<Equals<typeof themeType, never>>(false);
|
assert<Equals<typeof themeType, never>>(false);
|
||||||
})()}`,
|
})()}`,
|
||||||
...(buildContext.extraThemeProperties ?? []),
|
...(buildContext.extraThemeProperties ?? []),
|
||||||
buildContext.environmentVariables.map(
|
...buildContext.environmentVariables.map(
|
||||||
({ name, default: defaultValue }) =>
|
({ name, default: defaultValue }) =>
|
||||||
`${name}=\${env.${name}:${escapeStringForPropertiesFile(defaultValue)}}`
|
`${name}=\${env.${name}:${escapeStringForPropertiesFile(defaultValue)}}`
|
||||||
)
|
)
|
||||||
@ -262,13 +255,11 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
email: {
|
email: {
|
||||||
const emailThemeSrcDirPath = pathJoin(themeSrcDirPath, "email");
|
if (!buildContext.recordIsImplementedByThemeType.email) {
|
||||||
|
|
||||||
if (!fs.existsSync(emailThemeSrcDirPath)) {
|
|
||||||
break email;
|
break email;
|
||||||
}
|
}
|
||||||
|
|
||||||
implementedThemeTypes.email = true;
|
const emailThemeSrcDirPath = pathJoin(buildContext.themeSrcDirPath, "email");
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
srcDirPath: emailThemeSrcDirPath,
|
srcDirPath: emailThemeSrcDirPath,
|
||||||
@ -276,7 +267,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (implementedThemeTypes.account) {
|
if (buildContext.recordIsImplementedByThemeType.account) {
|
||||||
await bringInAccountV1({
|
await bringInAccountV1({
|
||||||
resourcesDirPath,
|
resourcesDirPath,
|
||||||
buildContext
|
buildContext
|
||||||
@ -288,12 +279,12 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
|
|
||||||
metaInfKeycloakThemes.themes.push({
|
metaInfKeycloakThemes.themes.push({
|
||||||
name: themeName,
|
name: themeName,
|
||||||
types: objectEntries(implementedThemeTypes)
|
types: objectEntries(buildContext.recordIsImplementedByThemeType)
|
||||||
.filter(([, isImplemented]) => isImplemented)
|
.filter(([, isImplemented]) => isImplemented)
|
||||||
.map(([themeType]) => themeType)
|
.map(([themeType]) => themeType)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (implementedThemeTypes.account) {
|
if (buildContext.recordIsImplementedByThemeType.account) {
|
||||||
metaInfKeycloakThemes.themes.push({
|
metaInfKeycloakThemes.themes.push({
|
||||||
name: accountV1ThemeName,
|
name: accountV1ThemeName,
|
||||||
types: ["account"]
|
types: ["account"]
|
||||||
@ -302,7 +293,7 @@ export async function generateSrcMainResourcesForMainTheme(params: {
|
|||||||
|
|
||||||
writeMetaInfKeycloakThemes({
|
writeMetaInfKeycloakThemes({
|
||||||
resourcesDirPath,
|
resourcesDirPath,
|
||||||
metaInfKeycloakThemes
|
getNewMetaInfKeycloakTheme: () => metaInfKeycloakThemes
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,7 @@
|
|||||||
import { join as pathJoin, extname as pathExtname, sep as pathSep } from "path";
|
import { join as pathJoin, extname as pathExtname, sep as pathSep } from "path";
|
||||||
import { transformCodebase } from "../../tools/transformCodebase";
|
import { transformCodebase } from "../../tools/transformCodebase";
|
||||||
import type { BuildContext } from "../../shared/buildContext";
|
import type { BuildContext } from "../../shared/buildContext";
|
||||||
import {
|
import { writeMetaInfKeycloakThemes } from "../../shared/metaInfKeycloakThemes";
|
||||||
readMetaInfKeycloakThemes_fromResourcesDirPath,
|
|
||||||
writeMetaInfKeycloakThemes
|
|
||||||
} from "../../shared/metaInfKeycloakThemes";
|
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
|
|
||||||
export type BuildContextLike = {
|
export type BuildContextLike = {
|
||||||
@ -13,7 +10,7 @@ export type BuildContextLike = {
|
|||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
export function generateSrcMainResourcesForThemeVariant(params: {
|
export function generateResourcesForThemeVariant(params: {
|
||||||
resourcesDirPath: string;
|
resourcesDirPath: string;
|
||||||
themeName: string;
|
themeName: string;
|
||||||
themeVariantName: string;
|
themeVariantName: string;
|
||||||
@ -34,8 +31,8 @@ export function generateSrcMainResourcesForThemeVariant(params: {
|
|||||||
Buffer.from(sourceCode)
|
Buffer.from(sourceCode)
|
||||||
.toString("utf-8")
|
.toString("utf-8")
|
||||||
.replace(
|
.replace(
|
||||||
`out["themeName"] = "${themeName}";`,
|
`kcContext.themeName = "${themeName}";`,
|
||||||
`out["themeName"] = "${themeVariantName}";`
|
`kcContext.themeName = "${themeVariantName}";`
|
||||||
),
|
),
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
@ -49,26 +46,25 @@ export function generateSrcMainResourcesForThemeVariant(params: {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
writeMetaInfKeycloakThemes({
|
||||||
const updatedMetaInfKeycloakThemes =
|
resourcesDirPath,
|
||||||
readMetaInfKeycloakThemes_fromResourcesDirPath({
|
getNewMetaInfKeycloakTheme: ({ metaInfKeycloakTheme }) => {
|
||||||
resourcesDirPath
|
assert(metaInfKeycloakTheme !== undefined);
|
||||||
|
|
||||||
|
const newMetaInfKeycloakTheme = metaInfKeycloakTheme;
|
||||||
|
|
||||||
|
newMetaInfKeycloakTheme.themes.push({
|
||||||
|
name: themeVariantName,
|
||||||
|
types: (() => {
|
||||||
|
const theme = newMetaInfKeycloakTheme.themes.find(
|
||||||
|
({ name }) => name === themeName
|
||||||
|
);
|
||||||
|
assert(theme !== undefined);
|
||||||
|
return theme.types;
|
||||||
|
})()
|
||||||
});
|
});
|
||||||
|
|
||||||
updatedMetaInfKeycloakThemes.themes.push({
|
return newMetaInfKeycloakTheme;
|
||||||
name: themeVariantName,
|
}
|
||||||
types: (() => {
|
});
|
||||||
const theme = updatedMetaInfKeycloakThemes.themes.find(
|
|
||||||
({ name }) => name === themeName
|
|
||||||
);
|
|
||||||
assert(theme !== undefined);
|
|
||||||
return theme.types;
|
|
||||||
})()
|
|
||||||
});
|
|
||||||
|
|
||||||
writeMetaInfKeycloakThemes({
|
|
||||||
resourcesDirPath,
|
|
||||||
metaInfKeycloakThemes: updatedMetaInfKeycloakThemes
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
1
src/bin/keycloakify/generateResources/index.ts
Normal file
1
src/bin/keycloakify/generateResources/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from "./generateResources";
|
@ -1 +0,0 @@
|
|||||||
export * from "./generateSrcMainResources";
|
|
@ -1,12 +1,9 @@
|
|||||||
import { generateSrcMainResources } from "./generateSrcMainResources";
|
import { generateResources } from "./generateResources";
|
||||||
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { getBuildContext } from "../shared/buildContext";
|
import { getBuildContext } from "../shared/buildContext";
|
||||||
import {
|
import { vitePluginSubScriptEnvNames } from "../shared/constants";
|
||||||
vitePluginSubScriptEnvNames,
|
|
||||||
onlyBuildJarFileBasenameEnvName
|
|
||||||
} from "../shared/constants";
|
|
||||||
import { buildJars } from "./buildJars";
|
import { buildJars } from "./buildJars";
|
||||||
import type { CliCommandOptions } from "../main";
|
import type { CliCommandOptions } from "../main";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
@ -82,7 +79,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
const resourcesDirPath = pathJoin(buildContext.keycloakifyBuildDirPath, "resources");
|
const resourcesDirPath = pathJoin(buildContext.keycloakifyBuildDirPath, "resources");
|
||||||
|
|
||||||
await generateSrcMainResources({
|
await generateResources({
|
||||||
resourcesDirPath,
|
resourcesDirPath,
|
||||||
buildContext
|
buildContext
|
||||||
});
|
});
|
||||||
@ -96,16 +93,17 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
cwd: buildContext.projectDirPath,
|
cwd: buildContext.projectDirPath,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
[vitePluginSubScriptEnvNames.runPostBuildScript]:
|
[vitePluginSubScriptEnvNames.runPostBuildScript]: JSON.stringify({
|
||||||
JSON.stringify(buildContext)
|
resourcesDirPath,
|
||||||
|
buildContext
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await buildJars({
|
await buildJars({
|
||||||
resourcesDirPath,
|
resourcesDirPath,
|
||||||
buildContext,
|
buildContext
|
||||||
onlyBuildJarFileBasename: process.env[onlyBuildJarFileBasenameEnvName]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rmSync(resourcesDirPath, { recursive: true });
|
rmSync(resourcesDirPath, { recursive: true });
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as crypto from "crypto";
|
|
||||||
import type { BuildContext } from "../../shared/buildContext";
|
import type { BuildContext } from "../../shared/buildContext";
|
||||||
import { assert } from "tsafe/assert";
|
|
||||||
import { basenameOfTheKeycloakifyResourcesDir } from "../../shared/constants";
|
import { basenameOfTheKeycloakifyResourcesDir } from "../../shared/constants";
|
||||||
|
import { assert } from "tsafe/assert";
|
||||||
|
import { posix } from "path";
|
||||||
|
|
||||||
export type BuildContextLike = {
|
export type BuildContextLike = {
|
||||||
urlPathname: string | undefined;
|
urlPathname: string | undefined;
|
||||||
@ -9,68 +9,45 @@ export type BuildContextLike = {
|
|||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
export function replaceImportsInCssCode(params: { cssCode: string }): {
|
export function replaceImportsInCssCode(params: {
|
||||||
fixedCssCode: string;
|
cssCode: string;
|
||||||
cssGlobalsToDefine: Record<string, string>;
|
cssFileRelativeDirPath: string | undefined;
|
||||||
} {
|
|
||||||
const { cssCode } = params;
|
|
||||||
|
|
||||||
const cssGlobalsToDefine: Record<string, string> = {};
|
|
||||||
|
|
||||||
new Set(cssCode.match(/url\(["']?\/[^/][^)"']+["']?\)[^;}]*?/g) ?? []).forEach(
|
|
||||||
match =>
|
|
||||||
(cssGlobalsToDefine[
|
|
||||||
"url" +
|
|
||||||
crypto
|
|
||||||
.createHash("sha256")
|
|
||||||
.update(match)
|
|
||||||
.digest("hex")
|
|
||||||
.substring(0, 15)
|
|
||||||
] = match)
|
|
||||||
);
|
|
||||||
|
|
||||||
let fixedCssCode = cssCode;
|
|
||||||
|
|
||||||
Object.keys(cssGlobalsToDefine).forEach(
|
|
||||||
cssVariableName =>
|
|
||||||
//NOTE: split/join pattern ~ replace all
|
|
||||||
(fixedCssCode = fixedCssCode
|
|
||||||
.split(cssGlobalsToDefine[cssVariableName])
|
|
||||||
.join(`var(--${cssVariableName})`))
|
|
||||||
);
|
|
||||||
|
|
||||||
return { fixedCssCode, cssGlobalsToDefine };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateCssCodeToDefineGlobals(params: {
|
|
||||||
cssGlobalsToDefine: Record<string, string>;
|
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
}): {
|
}): {
|
||||||
cssCodeToPrependInHead: string;
|
fixedCssCode: string;
|
||||||
} {
|
} {
|
||||||
const { cssGlobalsToDefine, buildContext } = params;
|
const { cssCode, cssFileRelativeDirPath, buildContext } = params;
|
||||||
|
|
||||||
return {
|
const fixedCssCode = cssCode.replace(
|
||||||
cssCodeToPrependInHead: [
|
/url\(["']?(\/[^/][^)"']+)["']?\)/g,
|
||||||
":root {",
|
(match, assetFileAbsoluteUrlPathname) => {
|
||||||
...Object.keys(cssGlobalsToDefine)
|
if (buildContext.urlPathname !== undefined) {
|
||||||
.map(cssVariableName =>
|
if (!assetFileAbsoluteUrlPathname.startsWith(buildContext.urlPathname)) {
|
||||||
[
|
// NOTE: Should never happen
|
||||||
`--${cssVariableName}:`,
|
return match;
|
||||||
cssGlobalsToDefine[cssVariableName].replace(
|
}
|
||||||
new RegExp(
|
assetFileAbsoluteUrlPathname = assetFileAbsoluteUrlPathname.replace(
|
||||||
`url\\(${(buildContext.urlPathname ?? "/").replace(
|
buildContext.urlPathname,
|
||||||
/\//g,
|
"/"
|
||||||
"\\/"
|
);
|
||||||
)}`,
|
}
|
||||||
"g"
|
|
||||||
),
|
inline_style_in_html: {
|
||||||
`url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/`
|
if (cssFileRelativeDirPath !== undefined) {
|
||||||
)
|
break inline_style_in_html;
|
||||||
].join(" ")
|
}
|
||||||
)
|
|
||||||
.map(line => ` ${line};`),
|
return `url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}${assetFileAbsoluteUrlPathname})`;
|
||||||
"}"
|
}
|
||||||
].join("\n")
|
|
||||||
};
|
const assetFileRelativeUrlPathname = posix.relative(
|
||||||
|
cssFileRelativeDirPath.replace(/\\/g, "/"),
|
||||||
|
assetFileAbsoluteUrlPathname.replace(/^\//, "")
|
||||||
|
);
|
||||||
|
|
||||||
|
return `url(${assetFileRelativeUrlPathname})`;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return { fixedCssCode };
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import type { BuildContext } from "../../shared/buildContext";
|
|
||||||
import { assert } from "tsafe/assert";
|
|
||||||
import { basenameOfTheKeycloakifyResourcesDir } from "../../shared/constants";
|
|
||||||
|
|
||||||
export type BuildContextLike = {
|
|
||||||
urlPathname: string | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
|
||||||
|
|
||||||
export function replaceImportsInInlineCssCode(params: {
|
|
||||||
cssCode: string;
|
|
||||||
buildContext: BuildContextLike;
|
|
||||||
}): {
|
|
||||||
fixedCssCode: string;
|
|
||||||
} {
|
|
||||||
const { cssCode, buildContext } = params;
|
|
||||||
|
|
||||||
const fixedCssCode = cssCode.replace(
|
|
||||||
buildContext.urlPathname === undefined
|
|
||||||
? /url\(["']?\/([^/][^)"']+)["']?\)/g
|
|
||||||
: new RegExp(`url\\(["']?${buildContext.urlPathname}([^)"']+)["']?\\)`, "g"),
|
|
||||||
(...[, group]) =>
|
|
||||||
`url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/${group})`
|
|
||||||
);
|
|
||||||
|
|
||||||
return { fixedCssCode };
|
|
||||||
}
|
|
@ -1,7 +1,4 @@
|
|||||||
import {
|
import { basenameOfTheKeycloakifyResourcesDir } from "../../../shared/constants";
|
||||||
nameOfTheGlobal,
|
|
||||||
basenameOfTheKeycloakifyResourcesDir
|
|
||||||
} from "../../../shared/constants";
|
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import type { BuildContext } from "../../../shared/buildContext";
|
import type { BuildContext } from "../../../shared/buildContext";
|
||||||
import * as nodePath from "path";
|
import * as nodePath from "path";
|
||||||
@ -88,13 +85,13 @@ export function replaceImportsInJsCode_vite(params: {
|
|||||||
fixedJsCode = replaceAll(
|
fixedJsCode = replaceAll(
|
||||||
fixedJsCode,
|
fixedJsCode,
|
||||||
`"${relativePathOfAssetFile}"`,
|
`"${relativePathOfAssetFile}"`,
|
||||||
`(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")`
|
`(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")`
|
||||||
);
|
);
|
||||||
|
|
||||||
fixedJsCode = replaceAll(
|
fixedJsCode = replaceAll(
|
||||||
fixedJsCode,
|
fixedJsCode,
|
||||||
`"${buildContext.urlPathname ?? "/"}${relativePathOfAssetFile}"`,
|
`"${buildContext.urlPathname ?? "/"}${relativePathOfAssetFile}"`,
|
||||||
`(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")`
|
`(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${relativePathOfAssetFile}")`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import {
|
import { basenameOfTheKeycloakifyResourcesDir } from "../../../shared/constants";
|
||||||
nameOfTheGlobal,
|
|
||||||
basenameOfTheKeycloakifyResourcesDir
|
|
||||||
} from "../../../shared/constants";
|
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import type { BuildContext } from "../../../shared/buildContext";
|
import type { BuildContext } from "../../../shared/buildContext";
|
||||||
import * as nodePath from "path";
|
import * as nodePath from "path";
|
||||||
@ -86,7 +83,7 @@ export function replaceImportsInJsCode_webpack(params: {
|
|||||||
var pd = Object.getOwnPropertyDescriptor(${n}, "p");
|
var pd = Object.getOwnPropertyDescriptor(${n}, "p");
|
||||||
if( pd === undefined || pd.configurable ){
|
if( pd === undefined || pd.configurable ){
|
||||||
Object.defineProperty(${n}, "p", {
|
Object.defineProperty(${n}, "p", {
|
||||||
get: function() { return window.${nameOfTheGlobal}.url.resourcesPath; },
|
get: function() { return window.kcContext.url.resourcesPath; },
|
||||||
set: function() {}
|
set: function() {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -107,7 +104,7 @@ export function replaceImportsInJsCode_webpack(params: {
|
|||||||
`[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`,
|
`[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`,
|
||||||
"g"
|
"g"
|
||||||
),
|
),
|
||||||
`window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}`
|
`window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return { fixedJsCode };
|
return { fixedJsCode };
|
||||||
|
@ -5,9 +5,22 @@ import { getNpmWorkspaceRootDirPath } from "../tools/getNpmWorkspaceRootDirPath"
|
|||||||
import type { CliCommandOptions } from "../main";
|
import type { CliCommandOptions } from "../main";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { assert } from "tsafe";
|
import { assert, type Equals } from "tsafe/assert";
|
||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import { vitePluginSubScriptEnvNames } from "./constants";
|
import {
|
||||||
|
vitePluginSubScriptEnvNames,
|
||||||
|
buildForKeycloakMajorVersionEnvName
|
||||||
|
} from "./constants";
|
||||||
|
import type { KeycloakVersionRange } from "./KeycloakVersionRange";
|
||||||
|
import { exclude } from "tsafe";
|
||||||
|
import { crawl } from "../tools/crawl";
|
||||||
|
import { themeTypes } from "./constants";
|
||||||
|
import { objectFromEntries } from "tsafe/objectFromEntries";
|
||||||
|
import { objectEntries } from "tsafe/objectEntries";
|
||||||
|
import { type ThemeType } from "./constants";
|
||||||
|
import { id } from "tsafe/id";
|
||||||
|
import { symToStr } from "tsafe/symToStr";
|
||||||
|
import chalk from "chalk";
|
||||||
|
|
||||||
export type BuildContext = {
|
export type BuildContext = {
|
||||||
bundler: "vite" | "webpack";
|
bundler: "vite" | "webpack";
|
||||||
@ -30,10 +43,17 @@ export type BuildContext = {
|
|||||||
npmWorkspaceRootDirPath: string;
|
npmWorkspaceRootDirPath: string;
|
||||||
kcContextExclusionsFtlCode: string | undefined;
|
kcContextExclusionsFtlCode: string | undefined;
|
||||||
environmentVariables: { name: string; default: string }[];
|
environmentVariables: { name: string; default: string }[];
|
||||||
|
themeSrcDirPath: string;
|
||||||
|
recordIsImplementedByThemeType: Readonly<Record<ThemeType | "email", boolean>>;
|
||||||
|
jarTargets: {
|
||||||
|
keycloakVersionRange: KeycloakVersionRange;
|
||||||
|
jarFileBasename: string;
|
||||||
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BuildOptions = {
|
export type BuildOptions = {
|
||||||
themeName?: string | string[];
|
themeName?: string | string[];
|
||||||
|
themeVersion?: string;
|
||||||
environmentVariables?: { name: string; default: string }[];
|
environmentVariables?: { name: string; default: string }[];
|
||||||
extraThemeProperties?: string[];
|
extraThemeProperties?: string[];
|
||||||
artifactId?: string;
|
artifactId?: string;
|
||||||
@ -41,8 +61,22 @@ export type BuildOptions = {
|
|||||||
loginThemeResourcesFromKeycloakVersion?: string;
|
loginThemeResourcesFromKeycloakVersion?: string;
|
||||||
keycloakifyBuildDirPath?: string;
|
keycloakifyBuildDirPath?: string;
|
||||||
kcContextExclusionsFtl?: string;
|
kcContextExclusionsFtl?: string;
|
||||||
|
/** https://docs.keycloakify.dev/v/v10/targetting-specific-keycloak-versions */
|
||||||
|
keycloakVersionTargets?: BuildOptions.KeycloakVersionTargets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export namespace BuildOptions {
|
||||||
|
export type KeycloakVersionTargets =
|
||||||
|
| ({ hasAccountTheme: true } & Record<
|
||||||
|
KeycloakVersionRange.WithAccountTheme,
|
||||||
|
string | boolean
|
||||||
|
>)
|
||||||
|
| ({ hasAccountTheme: false } & Record<
|
||||||
|
KeycloakVersionRange.WithoutAccountTheme,
|
||||||
|
string | boolean
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
export type ResolvedViteConfig = {
|
export type ResolvedViteConfig = {
|
||||||
buildDir: string;
|
buildDir: string;
|
||||||
publicDir: string;
|
publicDir: string;
|
||||||
@ -102,37 +136,96 @@ export function getBuildContext(params: {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
const parsedPackageJson = (() => {
|
const parsedPackageJson = (() => {
|
||||||
|
type BuildOptions_packageJson = BuildOptions & {
|
||||||
|
projectBuildDirPath?: string;
|
||||||
|
staticDirPathInProjectBuildDirPath?: string;
|
||||||
|
publicDirPath?: string;
|
||||||
|
};
|
||||||
|
|
||||||
type ParsedPackageJson = {
|
type ParsedPackageJson = {
|
||||||
name: string;
|
name: string;
|
||||||
version?: string;
|
version?: string;
|
||||||
homepage?: string;
|
homepage?: string;
|
||||||
keycloakify?: BuildOptions & {
|
keycloakify?: BuildOptions_packageJson;
|
||||||
projectBuildDirPath?: string;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const zParsedPackageJson = z.object({
|
const zParsedPackageJson = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
version: z.string().optional(),
|
version: z.string().optional(),
|
||||||
homepage: z.string().optional(),
|
homepage: z.string().optional(),
|
||||||
keycloakify: z
|
keycloakify: id<z.ZodType<BuildOptions_packageJson>>(
|
||||||
.object({
|
(() => {
|
||||||
extraThemeProperties: z.array(z.string()).optional(),
|
const zBuildOptions_packageJson = z.object({
|
||||||
artifactId: z.string().optional(),
|
extraThemeProperties: z.array(z.string()).optional(),
|
||||||
groupId: z.string().optional(),
|
artifactId: z.string().optional(),
|
||||||
loginThemeResourcesFromKeycloakVersion: z.string().optional(),
|
groupId: z.string().optional(),
|
||||||
projectBuildDirPath: z.string().optional(),
|
loginThemeResourcesFromKeycloakVersion: z.string().optional(),
|
||||||
keycloakifyBuildDirPath: z.string().optional(),
|
projectBuildDirPath: z.string().optional(),
|
||||||
themeName: z.union([z.string(), z.array(z.string())]).optional()
|
keycloakifyBuildDirPath: z.string().optional(),
|
||||||
})
|
kcContextExclusionsFtl: z.string().optional(),
|
||||||
.optional()
|
environmentVariables: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
name: z.string(),
|
||||||
|
default: z.string()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
themeName: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
|
themeVersion: z.string().optional(),
|
||||||
|
staticDirPathInProjectBuildDirPath: z.string().optional(),
|
||||||
|
publicDirPath: z.string().optional(),
|
||||||
|
keycloakVersionTargets: id<
|
||||||
|
z.ZodType<BuildOptions.KeycloakVersionTargets>
|
||||||
|
>(
|
||||||
|
(() => {
|
||||||
|
const zKeycloakVersionTargets = z.union([
|
||||||
|
z.object({
|
||||||
|
hasAccountTheme: z.literal(true),
|
||||||
|
"21-and-below": z.union([
|
||||||
|
z.boolean(),
|
||||||
|
z.string()
|
||||||
|
]),
|
||||||
|
"23": z.union([z.boolean(), z.string()]),
|
||||||
|
"24": z.union([z.boolean(), z.string()]),
|
||||||
|
"25-and-above": z.union([z.boolean(), z.string()])
|
||||||
|
}),
|
||||||
|
z.object({
|
||||||
|
hasAccountTheme: z.literal(false),
|
||||||
|
"21-and-below": z.union([
|
||||||
|
z.boolean(),
|
||||||
|
z.string()
|
||||||
|
]),
|
||||||
|
"22-and-above": z.union([z.boolean(), z.string()])
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
{
|
||||||
|
type Got = z.infer<typeof zKeycloakVersionTargets>;
|
||||||
|
type Expected = BuildOptions.KeycloakVersionTargets;
|
||||||
|
assert<Equals<Got, Expected>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return zKeycloakVersionTargets;
|
||||||
|
})()
|
||||||
|
).optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
type Got = z.infer<typeof zBuildOptions_packageJson>;
|
||||||
|
type Expected = BuildOptions_packageJson;
|
||||||
|
assert<Equals<Got, Expected>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return zBuildOptions_packageJson;
|
||||||
|
})()
|
||||||
|
).optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
type Got = ReturnType<(typeof zParsedPackageJson)["parse"]>;
|
type Got = z.infer<typeof zParsedPackageJson>;
|
||||||
type Expected = ParsedPackageJson;
|
type Expected = ParsedPackageJson;
|
||||||
assert<Got extends Expected ? true : false>();
|
assert<Equals<Got, Expected>>();
|
||||||
assert<Expected extends Got ? true : false>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return zParsedPackageJson.parse(
|
return zParsedPackageJson.parse(
|
||||||
@ -142,11 +235,59 @@ export function getBuildContext(params: {
|
|||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const buildOptions: BuildOptions = {
|
const buildOptions = {
|
||||||
...parsedPackageJson.keycloakify,
|
...parsedPackageJson.keycloakify,
|
||||||
...resolvedViteConfig?.buildOptions
|
...resolvedViteConfig?.buildOptions
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { themeSrcDirPath } = (() => {
|
||||||
|
const srcDirPath = pathJoin(projectDirPath, "src");
|
||||||
|
|
||||||
|
const themeSrcDirPath: string | undefined = crawl({
|
||||||
|
dirPath: srcDirPath,
|
||||||
|
returnedPathsType: "relative to dirPath"
|
||||||
|
})
|
||||||
|
.map(fileRelativePath => {
|
||||||
|
for (const themeSrcDirBasename of ["keycloak-theme", "keycloak_theme"]) {
|
||||||
|
const split = fileRelativePath.split(themeSrcDirBasename);
|
||||||
|
if (split.length === 2) {
|
||||||
|
return pathJoin(srcDirPath, split[0] + themeSrcDirBasename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
})
|
||||||
|
.filter(exclude(undefined))[0];
|
||||||
|
|
||||||
|
if (themeSrcDirPath !== undefined) {
|
||||||
|
return { themeSrcDirPath };
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const themeType of [...themeTypes, "email"]) {
|
||||||
|
if (!fs.existsSync(pathJoin(srcDirPath, themeType))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return { themeSrcDirPath: srcDirPath };
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
chalk.red(
|
||||||
|
[
|
||||||
|
"Can't locate your keycloak theme source directory.",
|
||||||
|
"See: https://docs.keycloakify.dev/v/v10/keycloakify-in-my-app/collocation"
|
||||||
|
].join("\n")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
})();
|
||||||
|
|
||||||
|
const recordIsImplementedByThemeType = objectFromEntries(
|
||||||
|
(["login", "account", "email"] as const).map(themeType => [
|
||||||
|
themeType,
|
||||||
|
fs.existsSync(pathJoin(themeSrcDirPath, themeType))
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
const themeNames = ((): [string, ...string[]] => {
|
const themeNames = ((): [string, ...string[]] => {
|
||||||
if (buildOptions.themeName === undefined) {
|
if (buildOptions.themeName === undefined) {
|
||||||
return [
|
return [
|
||||||
@ -174,9 +315,9 @@ export function getBuildContext(params: {
|
|||||||
break webpack;
|
break webpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedPackageJson.keycloakify?.projectBuildDirPath !== undefined) {
|
if (buildOptions.projectBuildDirPath !== undefined) {
|
||||||
return getAbsoluteAndInOsFormatPath({
|
return getAbsoluteAndInOsFormatPath({
|
||||||
pathIsh: parsedPackageJson.keycloakify.projectBuildDirPath,
|
pathIsh: buildOptions.projectBuildDirPath,
|
||||||
cwd: projectDirPath
|
cwd: projectDirPath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -192,10 +333,11 @@ export function getBuildContext(params: {
|
|||||||
dependencyExpected: "keycloakify"
|
dependencyExpected: "keycloakify"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const bundler = resolvedViteConfig !== undefined ? "vite" : "webpack";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bundler: resolvedViteConfig !== undefined ? "vite" : "webpack",
|
bundler,
|
||||||
themeVersion:
|
themeVersion: buildOptions.themeVersion ?? parsedPackageJson.version ?? "0.0.0",
|
||||||
process.env.KEYCLOAKIFY_THEME_VERSION ?? parsedPackageJson.version ?? "0.0.0",
|
|
||||||
themeNames,
|
themeNames,
|
||||||
extraThemeProperties: buildOptions.extraThemeProperties,
|
extraThemeProperties: buildOptions.extraThemeProperties,
|
||||||
groupId: (() => {
|
groupId: (() => {
|
||||||
@ -237,14 +379,21 @@ export function getBuildContext(params: {
|
|||||||
);
|
);
|
||||||
})(),
|
})(),
|
||||||
publicDirPath: (() => {
|
publicDirPath: (() => {
|
||||||
|
if (process.env.PUBLIC_DIR_PATH !== undefined) {
|
||||||
|
return getAbsoluteAndInOsFormatPath({
|
||||||
|
pathIsh: process.env.PUBLIC_DIR_PATH,
|
||||||
|
cwd: projectDirPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
webpack: {
|
webpack: {
|
||||||
if (resolvedViteConfig !== undefined) {
|
if (resolvedViteConfig !== undefined) {
|
||||||
break webpack;
|
break webpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.PUBLIC_DIR_PATH !== undefined) {
|
if (buildOptions.publicDirPath !== undefined) {
|
||||||
return getAbsoluteAndInOsFormatPath({
|
return getAbsoluteAndInOsFormatPath({
|
||||||
pathIsh: process.env.PUBLIC_DIR_PATH,
|
pathIsh: buildOptions.publicDirPath,
|
||||||
cwd: projectDirPath
|
cwd: projectDirPath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -301,6 +450,13 @@ export function getBuildContext(params: {
|
|||||||
break webpack;
|
break webpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (buildOptions.staticDirPathInProjectBuildDirPath !== undefined) {
|
||||||
|
getAbsoluteAndInOsFormatPath({
|
||||||
|
pathIsh: buildOptions.staticDirPathInProjectBuildDirPath,
|
||||||
|
cwd: projectBuildDirPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return pathJoin(projectBuildDirPath, "static");
|
return pathJoin(projectBuildDirPath, "static");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +479,290 @@ export function getBuildContext(params: {
|
|||||||
|
|
||||||
return buildOptions.kcContextExclusionsFtl;
|
return buildOptions.kcContextExclusionsFtl;
|
||||||
})(),
|
})(),
|
||||||
environmentVariables: buildOptions.environmentVariables ?? []
|
environmentVariables: buildOptions.environmentVariables ?? [],
|
||||||
|
recordIsImplementedByThemeType,
|
||||||
|
themeSrcDirPath,
|
||||||
|
jarTargets: (() => {
|
||||||
|
const getDefaultJarFileBasename = (range: string) =>
|
||||||
|
`keycloak-theme-for-kc-${range}.jar`;
|
||||||
|
|
||||||
|
build_for_specific_keycloak_major_version: {
|
||||||
|
const buildForKeycloakMajorVersionNumber = (() => {
|
||||||
|
const envValue = process.env[buildForKeycloakMajorVersionEnvName];
|
||||||
|
|
||||||
|
if (envValue === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const major = parseInt(envValue);
|
||||||
|
|
||||||
|
assert(!isNaN(major));
|
||||||
|
|
||||||
|
return major;
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (buildForKeycloakMajorVersionNumber === undefined) {
|
||||||
|
break build_for_specific_keycloak_major_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
const keycloakVersionRange: KeycloakVersionRange = (() => {
|
||||||
|
const doesImplementAccountTheme =
|
||||||
|
recordIsImplementedByThemeType.account;
|
||||||
|
|
||||||
|
if (doesImplementAccountTheme) {
|
||||||
|
const keycloakVersionRange = (() => {
|
||||||
|
if (buildForKeycloakMajorVersionNumber <= 21) {
|
||||||
|
return "21-and-below" as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(buildForKeycloakMajorVersionNumber !== 22);
|
||||||
|
|
||||||
|
if (buildForKeycloakMajorVersionNumber === 23) {
|
||||||
|
return "23" as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildForKeycloakMajorVersionNumber === 24) {
|
||||||
|
return "24" as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "25-and-above" as const;
|
||||||
|
})();
|
||||||
|
|
||||||
|
assert<
|
||||||
|
Equals<
|
||||||
|
typeof keycloakVersionRange,
|
||||||
|
KeycloakVersionRange.WithAccountTheme
|
||||||
|
>
|
||||||
|
>();
|
||||||
|
|
||||||
|
return keycloakVersionRange;
|
||||||
|
} else {
|
||||||
|
const keycloakVersionRange = (() => {
|
||||||
|
if (buildForKeycloakMajorVersionNumber <= 21) {
|
||||||
|
return "21-and-below" as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "22-and-above" as const;
|
||||||
|
})();
|
||||||
|
|
||||||
|
assert<
|
||||||
|
Equals<
|
||||||
|
typeof keycloakVersionRange,
|
||||||
|
KeycloakVersionRange.WithoutAccountTheme
|
||||||
|
>
|
||||||
|
>();
|
||||||
|
|
||||||
|
return keycloakVersionRange;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const jarFileBasename = (() => {
|
||||||
|
use_custom_jar_basename: {
|
||||||
|
const { keycloakVersionTargets } = buildOptions;
|
||||||
|
|
||||||
|
if (keycloakVersionTargets === undefined) {
|
||||||
|
break use_custom_jar_basename;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry = objectEntries(keycloakVersionTargets).find(
|
||||||
|
([keycloakVersionRange_entry]) =>
|
||||||
|
keycloakVersionRange_entry === keycloakVersionRange
|
||||||
|
);
|
||||||
|
|
||||||
|
if (entry === undefined) {
|
||||||
|
break use_custom_jar_basename;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maybeJarFileBasename = entry[1];
|
||||||
|
|
||||||
|
if (typeof maybeJarFileBasename !== "string") {
|
||||||
|
break use_custom_jar_basename;
|
||||||
|
}
|
||||||
|
|
||||||
|
return maybeJarFileBasename;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDefaultJarFileBasename(keycloakVersionRange);
|
||||||
|
})();
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
keycloakVersionRange,
|
||||||
|
jarFileBasename
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
const jarTargets_default = (() => {
|
||||||
|
const jarTargets: BuildContext["jarTargets"] = [];
|
||||||
|
|
||||||
|
if (recordIsImplementedByThemeType.account) {
|
||||||
|
for (const keycloakVersionRange of [
|
||||||
|
"21-and-below",
|
||||||
|
"23",
|
||||||
|
"24",
|
||||||
|
"25-and-above"
|
||||||
|
] as const) {
|
||||||
|
assert<
|
||||||
|
Equals<
|
||||||
|
typeof keycloakVersionRange,
|
||||||
|
KeycloakVersionRange.WithAccountTheme
|
||||||
|
>
|
||||||
|
>(true);
|
||||||
|
jarTargets.push({
|
||||||
|
keycloakVersionRange,
|
||||||
|
jarFileBasename:
|
||||||
|
getDefaultJarFileBasename(keycloakVersionRange)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const keycloakVersionRange of [
|
||||||
|
"21-and-below",
|
||||||
|
"22-and-above"
|
||||||
|
] as const) {
|
||||||
|
assert<
|
||||||
|
Equals<
|
||||||
|
typeof keycloakVersionRange,
|
||||||
|
KeycloakVersionRange.WithoutAccountTheme
|
||||||
|
>
|
||||||
|
>(true);
|
||||||
|
jarTargets.push({
|
||||||
|
keycloakVersionRange,
|
||||||
|
jarFileBasename:
|
||||||
|
getDefaultJarFileBasename(keycloakVersionRange)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return jarTargets;
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (buildOptions.keycloakVersionTargets === undefined) {
|
||||||
|
return jarTargets_default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
buildOptions.keycloakVersionTargets.hasAccountTheme !==
|
||||||
|
recordIsImplementedByThemeType.account
|
||||||
|
) {
|
||||||
|
console.log(
|
||||||
|
chalk.red(
|
||||||
|
(() => {
|
||||||
|
const { keycloakVersionTargets } = buildOptions;
|
||||||
|
|
||||||
|
let message = `Bad ${symToStr({ keycloakVersionTargets })} configuration.\n`;
|
||||||
|
|
||||||
|
if (keycloakVersionTargets.hasAccountTheme) {
|
||||||
|
message +=
|
||||||
|
"Your codebase does not seem to implement an account theme ";
|
||||||
|
} else {
|
||||||
|
message += "Your codebase implements an account theme ";
|
||||||
|
}
|
||||||
|
|
||||||
|
const { hasAccountTheme } = keycloakVersionTargets;
|
||||||
|
|
||||||
|
message += `but you have set ${symToStr({ keycloakVersionTargets })}.${symToStr({ hasAccountTheme })}`;
|
||||||
|
message += ` to ${hasAccountTheme} in your `;
|
||||||
|
message += (() => {
|
||||||
|
switch (bundler) {
|
||||||
|
case "vite":
|
||||||
|
return "vite.config.ts";
|
||||||
|
case "webpack":
|
||||||
|
return "package.json";
|
||||||
|
}
|
||||||
|
assert<Equals<typeof bundler, never>>(false);
|
||||||
|
})();
|
||||||
|
message += `. Please set it to ${!hasAccountTheme} `;
|
||||||
|
message +=
|
||||||
|
"and fill up the relevant keycloak version ranges.\n";
|
||||||
|
message += "Example:\n";
|
||||||
|
message += JSON.stringify(
|
||||||
|
id<Pick<BuildOptions, "keycloakVersionTargets">>({
|
||||||
|
keycloakVersionTargets: {
|
||||||
|
hasAccountTheme:
|
||||||
|
recordIsImplementedByThemeType.account,
|
||||||
|
...objectFromEntries(
|
||||||
|
jarTargets_default.map(
|
||||||
|
({
|
||||||
|
keycloakVersionRange,
|
||||||
|
jarFileBasename
|
||||||
|
}) => [
|
||||||
|
keycloakVersionRange,
|
||||||
|
jarFileBasename
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
message +=
|
||||||
|
"\nSee: https://docs.keycloakify.dev/v/v10/targetting-specific-keycloak-versions";
|
||||||
|
|
||||||
|
return message;
|
||||||
|
})()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const jarTargets: BuildContext["jarTargets"] = [];
|
||||||
|
|
||||||
|
const { hasAccountTheme, ...rest } = buildOptions.keycloakVersionTargets;
|
||||||
|
|
||||||
|
for (const [keycloakVersionRange, jarNameOrBoolean] of objectEntries(rest)) {
|
||||||
|
if (jarNameOrBoolean === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jarNameOrBoolean === true) {
|
||||||
|
jarTargets.push({
|
||||||
|
keycloakVersionRange: keycloakVersionRange,
|
||||||
|
jarFileBasename: getDefaultJarFileBasename(keycloakVersionRange)
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const jarFileBasename = jarNameOrBoolean;
|
||||||
|
|
||||||
|
if (!jarFileBasename.endsWith(".jar")) {
|
||||||
|
console.log(
|
||||||
|
chalk.red(`Bad ${jarFileBasename} should end with '.jar'\n`)
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jarFileBasename.includes("/") || jarFileBasename.includes("\\")) {
|
||||||
|
console.log(
|
||||||
|
chalk.red(
|
||||||
|
[
|
||||||
|
`Invalid ${jarFileBasename}. It's not supposed to be a path,`,
|
||||||
|
`Only the basename of the jar file is expected.`,
|
||||||
|
`Example: keycloak-theme.jar`
|
||||||
|
].join(" ")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
jarTargets.push({
|
||||||
|
keycloakVersionRange: keycloakVersionRange,
|
||||||
|
jarFileBasename: jarNameOrBoolean
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jarTargets.length === 0) {
|
||||||
|
console.log(
|
||||||
|
chalk.red(
|
||||||
|
"All jar targets are disabled. Please enable at least one jar target."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return jarTargets;
|
||||||
|
})()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
export const nameOfTheGlobal = "kcContext";
|
|
||||||
export const nameOfTheLocalizationRealmOverridesUserProfileProperty =
|
export const nameOfTheLocalizationRealmOverridesUserProfileProperty =
|
||||||
"__localizationRealmOverridesUserProfile";
|
"__localizationRealmOverridesUserProfile";
|
||||||
export const keycloak_resources = "keycloak-resources";
|
export const keycloak_resources = "keycloak-resources";
|
||||||
export const resources_common = "resources-common";
|
export const resources_common = "resources-common";
|
||||||
export const lastKeycloakVersionWithAccountV1 = "21.1.2";
|
export const lastKeycloakVersionWithAccountV1 = "21.1.2";
|
||||||
export const basenameOfTheKeycloakifyResourcesDir = "build";
|
export const basenameOfTheKeycloakifyResourcesDir = "dist";
|
||||||
|
|
||||||
export const themeTypes = ["login", "account"] as const;
|
export const themeTypes = ["login", "account"] as const;
|
||||||
export const accountV1ThemeName = "account-v1";
|
export const accountV1ThemeName = "account-v1";
|
||||||
@ -16,7 +15,8 @@ export const vitePluginSubScriptEnvNames = {
|
|||||||
resolveViteConfig: "KEYCLOAKIFY_RESOLVE_VITE_CONFIG"
|
resolveViteConfig: "KEYCLOAKIFY_RESOLVE_VITE_CONFIG"
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const onlyBuildJarFileBasenameEnvName = "KEYCLOAKIFY_ONLY_BUILD_JAR_FILE_BASENAME";
|
export const buildForKeycloakMajorVersionEnvName =
|
||||||
|
"KEYCLOAKIFY_BUILD_FOR_KEYCLOAK_MAJOR_VERSION";
|
||||||
|
|
||||||
export const loginThemePageIds = [
|
export const loginThemePageIds = [
|
||||||
"login.ftl",
|
"login.ftl",
|
||||||
|
@ -3,7 +3,6 @@ import { type BuildContext } from "./buildContext";
|
|||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { lastKeycloakVersionWithAccountV1 } from "./constants";
|
import { lastKeycloakVersionWithAccountV1 } from "./constants";
|
||||||
import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
|
import { downloadAndExtractArchive } from "../tools/downloadAndExtractArchive";
|
||||||
import { isInside } from "../tools/isInside";
|
|
||||||
|
|
||||||
export type BuildContextLike = {
|
export type BuildContextLike = {
|
||||||
cacheDirPath: string;
|
cacheDirPath: string;
|
||||||
@ -18,27 +17,25 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
}): Promise<{ defaultThemeDirPath: string }> {
|
}): Promise<{ defaultThemeDirPath: string }> {
|
||||||
const { keycloakVersion, buildContext } = params;
|
const { keycloakVersion, buildContext } = params;
|
||||||
|
|
||||||
|
let kcNodeModulesKeepFilePaths: string[] | undefined = undefined;
|
||||||
|
let kcNodeModulesKeepFilePaths_lastAccountV1: string[] | undefined = undefined;
|
||||||
|
|
||||||
const { extractedDirPath } = await downloadAndExtractArchive({
|
const { extractedDirPath } = await downloadAndExtractArchive({
|
||||||
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
|
||||||
cacheDirPath: buildContext.cacheDirPath,
|
cacheDirPath: buildContext.cacheDirPath,
|
||||||
npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath,
|
npmWorkspaceRootDirPath: buildContext.npmWorkspaceRootDirPath,
|
||||||
uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
|
uniqueIdOfOnOnArchiveFile: "downloadKeycloakDefaultTheme",
|
||||||
onArchiveFile: async params => {
|
onArchiveFile: async params => {
|
||||||
if (!isInside({ dirPath: "theme", filePath: params.fileRelativePath })) {
|
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
|
||||||
|
|
||||||
|
if (fileRelativePath.startsWith("..")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { readFile, writeFile } = params;
|
const { readFile, writeFile } = params;
|
||||||
|
|
||||||
const fileRelativePath = pathRelative("theme", params.fileRelativePath);
|
|
||||||
|
|
||||||
skip_keycloak_v2: {
|
skip_keycloak_v2: {
|
||||||
if (
|
if (!fileRelativePath.startsWith(pathJoin("keycloak.v2"))) {
|
||||||
!isInside({
|
|
||||||
dirPath: pathJoin("keycloak.v2"),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
break skip_keycloak_v2;
|
break skip_keycloak_v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +47,96 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
break last_account_v1_transformations;
|
break last_account_v1_transformations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skip_web_modules: {
|
||||||
|
if (
|
||||||
|
!fileRelativePath.startsWith(
|
||||||
|
pathJoin("keycloak", "common", "resources", "web_modules")
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
break skip_web_modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
skip_lib: {
|
||||||
|
if (
|
||||||
|
!fileRelativePath.startsWith(
|
||||||
|
pathJoin("keycloak", "common", "resources", "lib")
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
break skip_lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
skip_node_modules: {
|
||||||
|
if (
|
||||||
|
!fileRelativePath.startsWith(
|
||||||
|
pathJoin("keycloak", "common", "resources", "node_modules")
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
break skip_node_modules;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kcNodeModulesKeepFilePaths_lastAccountV1 === undefined) {
|
||||||
|
kcNodeModulesKeepFilePaths_lastAccountV1 = [
|
||||||
|
pathJoin("patternfly", "dist", "css", "patternfly.min.css"),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"css",
|
||||||
|
"patternfly-additions.min.css"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Regular-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Bold-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Light-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Semibold-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"PatternFlyIcons-webfont.ttf"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"PatternFlyIcons-webfont.woff"
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const keepPath of kcNodeModulesKeepFilePaths_lastAccountV1) {
|
||||||
|
if (fileRelativePath.endsWith(keepPath)) {
|
||||||
|
break skip_node_modules;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
patch_account_css: {
|
patch_account_css: {
|
||||||
if (
|
if (
|
||||||
fileRelativePath !==
|
fileRelativePath !==
|
||||||
@ -70,69 +157,6 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_web_modules: {
|
|
||||||
if (
|
|
||||||
!isInside({
|
|
||||||
dirPath: pathJoin(
|
|
||||||
"keycloak",
|
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"web_modules"
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
break skip_web_modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
skip_unused_node_modules: {
|
|
||||||
const nodeModulesDirPath = pathJoin(
|
|
||||||
"keycloak",
|
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"node_modules"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
|
||||||
!isInside({
|
|
||||||
dirPath: nodeModulesDirPath,
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
break skip_unused_node_modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
const toKeepPrefixes = [
|
|
||||||
...[
|
|
||||||
"patternfly.min.css",
|
|
||||||
"patternfly-additions.min.css",
|
|
||||||
"patternfly-additions.min.css"
|
|
||||||
].map(fileBasename =>
|
|
||||||
pathJoin(
|
|
||||||
nodeModulesDirPath,
|
|
||||||
"patternfly",
|
|
||||||
"dist",
|
|
||||||
"css",
|
|
||||||
fileBasename
|
|
||||||
)
|
|
||||||
),
|
|
||||||
pathJoin(nodeModulesDirPath, "patternfly", "dist", "fonts")
|
|
||||||
];
|
|
||||||
|
|
||||||
if (
|
|
||||||
toKeepPrefixes.find(prefix =>
|
|
||||||
fileRelativePath.startsWith(prefix)
|
|
||||||
) !== undefined
|
|
||||||
) {
|
|
||||||
break skip_unused_node_modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_unused_resources: {
|
skip_unused_resources: {
|
||||||
@ -140,61 +164,106 @@ export async function downloadKeycloakDefaultTheme(params: {
|
|||||||
break skip_unused_resources;
|
break skip_unused_resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const dirBasename of [
|
skip_node_modules: {
|
||||||
"@patternfly-v5",
|
|
||||||
"@rollup",
|
|
||||||
"rollup",
|
|
||||||
"react",
|
|
||||||
"react-dom",
|
|
||||||
"shx",
|
|
||||||
".pnpm"
|
|
||||||
]) {
|
|
||||||
if (
|
if (
|
||||||
isInside({
|
!fileRelativePath.startsWith(
|
||||||
dirPath: pathJoin(
|
pathJoin("keycloak", "common", "resources", "node_modules")
|
||||||
"keycloak",
|
)
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"node_modules",
|
|
||||||
dirBasename
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
) {
|
||||||
return;
|
break skip_node_modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (kcNodeModulesKeepFilePaths === undefined) {
|
||||||
|
kcNodeModulesKeepFilePaths = [
|
||||||
|
pathJoin("@patternfly", "patternfly", "patternfly.min.css"),
|
||||||
|
pathJoin("patternfly", "dist", "css", "patternfly.min.css"),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"css",
|
||||||
|
"patternfly-additions.min.css"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Regular-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Light-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Bold-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Bold-webfont.woff"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"OpenSans-Bold-webfont.ttf"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"fontawesome-webfont.woff2"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"PatternFlyIcons-webfont.ttf"
|
||||||
|
),
|
||||||
|
pathJoin(
|
||||||
|
"patternfly",
|
||||||
|
"dist",
|
||||||
|
"fonts",
|
||||||
|
"PatternFlyIcons-webfont.woff"
|
||||||
|
),
|
||||||
|
pathJoin("jquery", "dist", "jquery.min.js")
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const keepPath of kcNodeModulesKeepFilePaths) {
|
||||||
|
if (fileRelativePath.endsWith(keepPath)) {
|
||||||
|
break skip_node_modules;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const dirBasename of ["react", "react-dom"]) {
|
skip_vendor: {
|
||||||
if (
|
if (
|
||||||
isInside({
|
!fileRelativePath.startsWith(
|
||||||
dirPath: pathJoin(
|
pathJoin("keycloak", "common", "resources", "vendor")
|
||||||
"keycloak",
|
)
|
||||||
"common",
|
|
||||||
"resources",
|
|
||||||
"vendor",
|
|
||||||
dirBasename
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
) {
|
||||||
return;
|
break skip_vendor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
skip_rollup_config: {
|
||||||
isInside({
|
if (
|
||||||
dirPath: pathJoin(
|
fileRelativePath !==
|
||||||
"keycloak",
|
pathJoin("keycloak", "common", "resources", "rollup.config.js")
|
||||||
"common",
|
) {
|
||||||
"resources",
|
break skip_rollup_config;
|
||||||
"node_modules",
|
}
|
||||||
"@patternfly",
|
|
||||||
"react-core"
|
|
||||||
),
|
|
||||||
filePath: fileRelativePath
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import type { BuildContext } from "./buildContext";
|
import type { BuildContext } from "./buildContext";
|
||||||
import { getThemeSrcDirPath } from "./getThemeSrcDirPath";
|
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { existsAsync } from "../tools/fs.existsAsync";
|
import { existsAsync } from "../tools/fs.existsAsync";
|
||||||
@ -9,6 +8,7 @@ export type BuildContextLike = {
|
|||||||
projectDirPath: string;
|
projectDirPath: string;
|
||||||
themeNames: string[];
|
themeNames: string[];
|
||||||
environmentVariables: { name: string; default: string }[];
|
environmentVariables: { name: string; default: string }[];
|
||||||
|
themeSrcDirPath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
@ -18,11 +18,7 @@ export async function generateKcGenTs(params: {
|
|||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { buildContext } = params;
|
const { buildContext } = params;
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({
|
const filePath = pathJoin(buildContext.themeSrcDirPath, "kc.gen.ts");
|
||||||
projectDirPath: buildContext.projectDirPath
|
|
||||||
});
|
|
||||||
|
|
||||||
const filePath = pathJoin(themeSrcDirPath, "kc.gen.ts");
|
|
||||||
|
|
||||||
const currentContent = (await existsAsync(filePath))
|
const currentContent = (await existsAsync(filePath))
|
||||||
? await fs.readFile(filePath)
|
? await fs.readFile(filePath)
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
import type { KeycloakVersionRange } from "./KeycloakVersionRange";
|
|
||||||
|
|
||||||
export function getJarFileBasename(params: {
|
|
||||||
keycloakVersionRange: KeycloakVersionRange;
|
|
||||||
}) {
|
|
||||||
const { keycloakVersionRange } = params;
|
|
||||||
|
|
||||||
const jarFileBasename = `keycloak-theme-for-kc-${keycloakVersionRange}.jar`;
|
|
||||||
|
|
||||||
return { jarFileBasename };
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
import * as fs from "fs";
|
|
||||||
import { exclude } from "tsafe";
|
|
||||||
import { crawl } from "../tools/crawl";
|
|
||||||
import { join as pathJoin } from "path";
|
|
||||||
import { themeTypes } from "./constants";
|
|
||||||
|
|
||||||
const themeSrcDirBasenames = ["keycloak-theme", "keycloak_theme"];
|
|
||||||
|
|
||||||
/** Can't catch error, if the directory isn't found, this function will just exit the process with an error message. */
|
|
||||||
export function getThemeSrcDirPath(params: { projectDirPath: string }) {
|
|
||||||
const { projectDirPath } = params;
|
|
||||||
|
|
||||||
const srcDirPath = pathJoin(projectDirPath, "src");
|
|
||||||
|
|
||||||
const themeSrcDirPath: string | undefined = crawl({
|
|
||||||
dirPath: srcDirPath,
|
|
||||||
returnedPathsType: "relative to dirPath"
|
|
||||||
})
|
|
||||||
.map(fileRelativePath => {
|
|
||||||
for (const themeSrcDirBasename of themeSrcDirBasenames) {
|
|
||||||
const split = fileRelativePath.split(themeSrcDirBasename);
|
|
||||||
if (split.length === 2) {
|
|
||||||
return pathJoin(srcDirPath, split[0] + themeSrcDirBasename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
})
|
|
||||||
.filter(exclude(undefined))[0];
|
|
||||||
|
|
||||||
if (themeSrcDirPath !== undefined) {
|
|
||||||
return { themeSrcDirPath };
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const themeType of [...themeTypes, "email"]) {
|
|
||||||
if (!fs.existsSync(pathJoin(srcDirPath, themeType))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return { themeSrcDirPath: srcDirPath };
|
|
||||||
}
|
|
||||||
|
|
||||||
console.error(
|
|
||||||
[
|
|
||||||
"Can't locate your theme source directory. It should be either: ",
|
|
||||||
"src/ or src/keycloak-theme or src/keycloak_theme.",
|
|
||||||
"Example in the starter: https://github.com/keycloakify/keycloakify-starter/tree/main/src/keycloak-theme"
|
|
||||||
].join("\n")
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit(-1);
|
|
||||||
}
|
|
@ -1,84 +1,40 @@
|
|||||||
import { join as pathJoin, dirname as pathDirname } from "path";
|
import { join as pathJoin, dirname as pathDirname } from "path";
|
||||||
import type { ThemeType } from "./constants";
|
import type { ThemeType } from "./constants";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { assert } from "tsafe/assert";
|
|
||||||
import { extractArchive } from "../tools/extractArchive";
|
|
||||||
|
|
||||||
export type MetaInfKeycloakTheme = {
|
export type MetaInfKeycloakTheme = {
|
||||||
themes: { name: string; types: (ThemeType | "email")[] }[];
|
themes: { name: string; types: (ThemeType | "email")[] }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getMetaInfKeycloakThemesJsonFilePath(params: {
|
|
||||||
resourcesDirPath: string;
|
|
||||||
}) {
|
|
||||||
const { resourcesDirPath } = params;
|
|
||||||
|
|
||||||
return pathJoin(
|
|
||||||
resourcesDirPath === "." ? "" : resourcesDirPath,
|
|
||||||
"META-INF",
|
|
||||||
"keycloak-themes.json"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function readMetaInfKeycloakThemes_fromResourcesDirPath(params: {
|
|
||||||
resourcesDirPath: string;
|
|
||||||
}) {
|
|
||||||
const { resourcesDirPath } = params;
|
|
||||||
|
|
||||||
return JSON.parse(
|
|
||||||
fs
|
|
||||||
.readFileSync(
|
|
||||||
getMetaInfKeycloakThemesJsonFilePath({
|
|
||||||
resourcesDirPath
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.toString("utf8")
|
|
||||||
) as MetaInfKeycloakTheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function readMetaInfKeycloakThemes_fromJar(params: {
|
|
||||||
jarFilePath: string;
|
|
||||||
}): Promise<MetaInfKeycloakTheme> {
|
|
||||||
const { jarFilePath } = params;
|
|
||||||
let metaInfKeycloakThemes: MetaInfKeycloakTheme | undefined = undefined;
|
|
||||||
|
|
||||||
await extractArchive({
|
|
||||||
archiveFilePath: jarFilePath,
|
|
||||||
onArchiveFile: async ({ relativeFilePathInArchive, readFile, earlyExit }) => {
|
|
||||||
if (
|
|
||||||
relativeFilePathInArchive ===
|
|
||||||
getMetaInfKeycloakThemesJsonFilePath({ resourcesDirPath: "." })
|
|
||||||
) {
|
|
||||||
metaInfKeycloakThemes = JSON.parse((await readFile()).toString("utf8"));
|
|
||||||
earlyExit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
assert(metaInfKeycloakThemes !== undefined);
|
|
||||||
|
|
||||||
return metaInfKeycloakThemes;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function writeMetaInfKeycloakThemes(params: {
|
export function writeMetaInfKeycloakThemes(params: {
|
||||||
resourcesDirPath: string;
|
resourcesDirPath: string;
|
||||||
metaInfKeycloakThemes: MetaInfKeycloakTheme;
|
getNewMetaInfKeycloakTheme: (params: {
|
||||||
|
metaInfKeycloakTheme: MetaInfKeycloakTheme | undefined;
|
||||||
|
}) => MetaInfKeycloakTheme;
|
||||||
}) {
|
}) {
|
||||||
const { resourcesDirPath, metaInfKeycloakThemes } = params;
|
const { resourcesDirPath, getNewMetaInfKeycloakTheme } = params;
|
||||||
|
|
||||||
const metaInfKeycloakThemesJsonPath = getMetaInfKeycloakThemesJsonFilePath({
|
const filePath = pathJoin(resourcesDirPath, "META-INF", "keycloak-themes.json");
|
||||||
resourcesDirPath
|
|
||||||
|
const currentMetaInfKeycloakTheme = !fs.existsSync(filePath)
|
||||||
|
? undefined
|
||||||
|
: (JSON.parse(
|
||||||
|
fs.readFileSync(filePath).toString("utf8")
|
||||||
|
) as MetaInfKeycloakTheme);
|
||||||
|
|
||||||
|
const newMetaInfKeycloakThemes = getNewMetaInfKeycloakTheme({
|
||||||
|
metaInfKeycloakTheme: currentMetaInfKeycloakTheme
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const dirPath = pathDirname(metaInfKeycloakThemesJsonPath);
|
const dirPath = pathDirname(filePath);
|
||||||
if (!fs.existsSync(dirPath)) {
|
if (!fs.existsSync(dirPath)) {
|
||||||
fs.mkdirSync(dirPath, { recursive: true });
|
fs.mkdirSync(dirPath, { recursive: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
metaInfKeycloakThemesJsonPath,
|
filePath,
|
||||||
Buffer.from(JSON.stringify(metaInfKeycloakThemes, null, 2), "utf8")
|
Buffer.from(JSON.stringify(newMetaInfKeycloakThemes, null, 2), "utf8")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ export async function appBuild(params: {
|
|||||||
|
|
||||||
const dResult = new Deferred<{ isSuccess: boolean }>();
|
const dResult = new Deferred<{ isSuccess: boolean }>();
|
||||||
|
|
||||||
const child = child_process.spawn(command, args, { cwd });
|
const child = child_process.spawn(command, args, { cwd, shell: true });
|
||||||
|
|
||||||
child.stdout.on("data", data => {
|
child.stdout.on("data", data => {
|
||||||
if (data.toString("utf8").includes("gzip:")) {
|
if (data.toString("utf8").includes("gzip:")) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { onlyBuildJarFileBasenameEnvName } from "../shared/constants";
|
import { buildForKeycloakMajorVersionEnvName } from "../shared/constants";
|
||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import { Deferred } from "evt/tools/Deferred";
|
import { Deferred } from "evt/tools/Deferred";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
@ -14,10 +14,10 @@ export type BuildContextLike = {
|
|||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
export async function keycloakifyBuild(params: {
|
export async function keycloakifyBuild(params: {
|
||||||
onlyBuildJarFileBasename: string | undefined;
|
buildForKeycloakMajorVersionNumber: number;
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
}): Promise<{ isKeycloakifyBuildSuccess: boolean }> {
|
}): Promise<{ isKeycloakifyBuildSuccess: boolean }> {
|
||||||
const { buildContext, onlyBuildJarFileBasename } = params;
|
const { buildForKeycloakMajorVersionNumber, buildContext } = params;
|
||||||
|
|
||||||
const dResult = new Deferred<{ isSuccess: boolean }>();
|
const dResult = new Deferred<{ isSuccess: boolean }>();
|
||||||
|
|
||||||
@ -25,8 +25,9 @@ export async function keycloakifyBuild(params: {
|
|||||||
cwd: buildContext.projectDirPath,
|
cwd: buildContext.projectDirPath,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
[onlyBuildJarFileBasenameEnvName]: onlyBuildJarFileBasename
|
[buildForKeycloakMajorVersionEnvName]: `${buildForKeycloakMajorVersionNumber}`
|
||||||
}
|
},
|
||||||
|
shell: true
|
||||||
});
|
});
|
||||||
|
|
||||||
child.stdout.on("data", data => process.stdout.write(data));
|
child.stdout.on("data", data => process.stdout.write(data));
|
||||||
|
@ -2,14 +2,16 @@ import { getBuildContext } from "../shared/buildContext";
|
|||||||
import { exclude } from "tsafe/exclude";
|
import { exclude } from "tsafe/exclude";
|
||||||
import type { CliCommandOptions as CliCommandOptions_common } from "../main";
|
import type { CliCommandOptions as CliCommandOptions_common } from "../main";
|
||||||
import { promptKeycloakVersion } from "../shared/promptKeycloakVersion";
|
import { promptKeycloakVersion } from "../shared/promptKeycloakVersion";
|
||||||
import { readMetaInfKeycloakThemes_fromJar } from "../shared/metaInfKeycloakThemes";
|
|
||||||
import { accountV1ThemeName, containerName } from "../shared/constants";
|
import { accountV1ThemeName, containerName } from "../shared/constants";
|
||||||
import { SemVer } from "../tools/SemVer";
|
import { SemVer } from "../tools/SemVer";
|
||||||
import type { KeycloakVersionRange } from "../shared/KeycloakVersionRange";
|
import { assert } from "tsafe/assert";
|
||||||
import { getJarFileBasename } from "../shared/getJarFileBasename";
|
|
||||||
import { assert, type Equals } from "tsafe/assert";
|
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
import {
|
||||||
|
join as pathJoin,
|
||||||
|
relative as pathRelative,
|
||||||
|
sep as pathSep,
|
||||||
|
basename as pathBasename
|
||||||
|
} from "path";
|
||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import chokidar from "chokidar";
|
import chokidar from "chokidar";
|
||||||
@ -86,6 +88,31 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
const buildContext = getBuildContext({ cliCommandOptions });
|
const buildContext = getBuildContext({ cliCommandOptions });
|
||||||
|
|
||||||
|
const { keycloakVersion } = await (async () => {
|
||||||
|
if (cliCommandOptions.keycloakVersion !== undefined) {
|
||||||
|
return {
|
||||||
|
keycloakVersion: cliCommandOptions.keycloakVersion,
|
||||||
|
keycloakMajorNumber: SemVer.parse(cliCommandOptions.keycloakVersion).major
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
chalk.cyan("On which version of Keycloak do you want to test your theme?")
|
||||||
|
);
|
||||||
|
|
||||||
|
const { keycloakVersion } = await promptKeycloakVersion({
|
||||||
|
startingFromMajor: 18,
|
||||||
|
excludeMajorVersions: [22],
|
||||||
|
cacheDirPath: buildContext.cacheDirPath
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`→ ${keycloakVersion}`);
|
||||||
|
|
||||||
|
return { keycloakVersion };
|
||||||
|
})();
|
||||||
|
|
||||||
|
const keycloakMajorVersionNumber = SemVer.parse(keycloakVersion).major;
|
||||||
|
|
||||||
{
|
{
|
||||||
const { isAppBuildSuccess } = await appBuild({
|
const { isAppBuildSuccess } = await appBuild({
|
||||||
buildContext
|
buildContext
|
||||||
@ -94,141 +121,36 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
if (!isAppBuildSuccess) {
|
if (!isAppBuildSuccess) {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.red(
|
chalk.red(
|
||||||
`App build failed, exiting. Try running 'yarn build-keycloak-theme' and see what's wrong.`
|
`App build failed, exiting. Try running 'npm run build' and see what's wrong.`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isKeycloakifyBuildSuccess } = await keycloakifyBuild({
|
const { isKeycloakifyBuildSuccess } = await keycloakifyBuild({
|
||||||
onlyBuildJarFileBasename: undefined,
|
buildForKeycloakMajorVersionNumber: keycloakMajorVersionNumber,
|
||||||
buildContext
|
buildContext
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isKeycloakifyBuildSuccess) {
|
if (!isKeycloakifyBuildSuccess) {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.red(
|
chalk.red(
|
||||||
`Keycloakify build failed, exiting. Try running 'yarn build-keycloak-theme' and see what's wrong.`
|
`Keycloakify build failed, exiting. Try running 'npx keycloakify build' and see what's wrong.`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { doesImplementAccountTheme } = await (async () => {
|
const jarFilePath = fs
|
||||||
const latestJarFilePath = fs
|
.readdirSync(buildContext.keycloakifyBuildDirPath)
|
||||||
.readdirSync(buildContext.keycloakifyBuildDirPath)
|
.filter(fileBasename => fileBasename.endsWith(".jar"))
|
||||||
.filter(fileBasename => fileBasename.endsWith(".jar"))
|
.map(fileBasename => pathJoin(buildContext.keycloakifyBuildDirPath, fileBasename))
|
||||||
.map(fileBasename =>
|
.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs)[0];
|
||||||
pathJoin(buildContext.keycloakifyBuildDirPath, fileBasename)
|
|
||||||
)
|
|
||||||
.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs)[0];
|
|
||||||
|
|
||||||
assert(latestJarFilePath !== undefined);
|
assert(jarFilePath !== undefined);
|
||||||
|
|
||||||
const metaInfKeycloakThemes = await readMetaInfKeycloakThemes_fromJar({
|
console.log(`Using ${chalk.bold(pathBasename(jarFilePath))}`);
|
||||||
jarFilePath: latestJarFilePath
|
|
||||||
});
|
|
||||||
|
|
||||||
const mainThemeEntry = metaInfKeycloakThemes.themes.find(
|
|
||||||
({ name }) => name === buildContext.themeNames[0]
|
|
||||||
);
|
|
||||||
|
|
||||||
assert(mainThemeEntry !== undefined);
|
|
||||||
|
|
||||||
const doesImplementAccountTheme = mainThemeEntry.types.includes("account");
|
|
||||||
|
|
||||||
return { doesImplementAccountTheme };
|
|
||||||
})();
|
|
||||||
|
|
||||||
const { keycloakVersion, keycloakMajorNumber: keycloakMajorVersionNumber } =
|
|
||||||
await (async function getKeycloakMajor(): Promise<{
|
|
||||||
keycloakVersion: string;
|
|
||||||
keycloakMajorNumber: number;
|
|
||||||
}> {
|
|
||||||
if (cliCommandOptions.keycloakVersion !== undefined) {
|
|
||||||
return {
|
|
||||||
keycloakVersion: cliCommandOptions.keycloakVersion,
|
|
||||||
keycloakMajorNumber: SemVer.parse(cliCommandOptions.keycloakVersion)
|
|
||||||
.major
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
chalk.cyan("On which version of Keycloak do you want to test your theme?")
|
|
||||||
);
|
|
||||||
|
|
||||||
const { keycloakVersion } = await promptKeycloakVersion({
|
|
||||||
startingFromMajor: 18,
|
|
||||||
excludeMajorVersions: [22],
|
|
||||||
cacheDirPath: buildContext.cacheDirPath
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`→ ${keycloakVersion}`);
|
|
||||||
|
|
||||||
const keycloakMajorNumber = SemVer.parse(keycloakVersion).major;
|
|
||||||
|
|
||||||
if (doesImplementAccountTheme && keycloakMajorNumber === 22) {
|
|
||||||
console.log(
|
|
||||||
[
|
|
||||||
"Unfortunately, Keycloakify themes that implements an account theme do not work on Keycloak 22",
|
|
||||||
"Please select any other Keycloak version"
|
|
||||||
].join(" ")
|
|
||||||
);
|
|
||||||
return getKeycloakMajor();
|
|
||||||
}
|
|
||||||
|
|
||||||
return { keycloakVersion, keycloakMajorNumber };
|
|
||||||
})();
|
|
||||||
|
|
||||||
const keycloakVersionRange: KeycloakVersionRange = (() => {
|
|
||||||
if (doesImplementAccountTheme) {
|
|
||||||
const keycloakVersionRange = (() => {
|
|
||||||
if (keycloakMajorVersionNumber <= 21) {
|
|
||||||
return "21-and-below" as const;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(keycloakMajorVersionNumber !== 22);
|
|
||||||
|
|
||||||
if (keycloakMajorVersionNumber === 23) {
|
|
||||||
return "23" as const;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keycloakMajorVersionNumber === 24) {
|
|
||||||
return "24" as const;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "25-and-above" as const;
|
|
||||||
})();
|
|
||||||
|
|
||||||
assert<
|
|
||||||
Equals<typeof keycloakVersionRange, KeycloakVersionRange.WithAccountTheme>
|
|
||||||
>();
|
|
||||||
|
|
||||||
return keycloakVersionRange;
|
|
||||||
} else {
|
|
||||||
const keycloakVersionRange = (() => {
|
|
||||||
if (keycloakMajorVersionNumber <= 21) {
|
|
||||||
return "21-and-below" as const;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "22-and-above" as const;
|
|
||||||
})();
|
|
||||||
|
|
||||||
assert<
|
|
||||||
Equals<
|
|
||||||
typeof keycloakVersionRange,
|
|
||||||
KeycloakVersionRange.WithoutAccountTheme
|
|
||||||
>
|
|
||||||
>();
|
|
||||||
|
|
||||||
return keycloakVersionRange;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
const { jarFileBasename } = getJarFileBasename({ keycloakVersionRange });
|
|
||||||
|
|
||||||
console.log(`Using Keycloak ${chalk.bold(jarFileBasename)}`);
|
|
||||||
|
|
||||||
const realmJsonFilePath = await (async () => {
|
const realmJsonFilePath = await (async () => {
|
||||||
if (cliCommandOptions.realmJsonFilePath !== undefined) {
|
if (cliCommandOptions.realmJsonFilePath !== undefined) {
|
||||||
@ -248,49 +170,71 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const dirPath = pathJoin(
|
const internalFilePath = await (async () => {
|
||||||
getThisCodebaseRootDirPath(),
|
const dirPath = pathJoin(
|
||||||
"src",
|
getThisCodebaseRootDirPath(),
|
||||||
"bin",
|
"src",
|
||||||
"start-keycloak"
|
"bin",
|
||||||
);
|
"start-keycloak"
|
||||||
|
);
|
||||||
|
|
||||||
const filePath = pathJoin(
|
const filePath = pathJoin(
|
||||||
dirPath,
|
dirPath,
|
||||||
`myrealm-realm-${keycloakMajorVersionNumber}.json`
|
`myrealm-realm-${keycloakMajorVersionNumber}.json`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`${chalk.yellow(
|
`${chalk.yellow(
|
||||||
`Keycloakify do not have a realm configuration for Keycloak ${keycloakMajorVersionNumber} yet.`
|
`Keycloakify do not have a realm configuration for Keycloak ${keycloakMajorVersionNumber} yet.`
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(chalk.cyan("Select what configuration to use:"));
|
console.log(chalk.cyan("Select what configuration to use:"));
|
||||||
|
|
||||||
const { value } = await cliSelect<string>({
|
const { value } = await cliSelect<string>({
|
||||||
values: [
|
values: [
|
||||||
...fs
|
...fs
|
||||||
.readdirSync(dirPath)
|
.readdirSync(dirPath)
|
||||||
.filter(fileBasename => fileBasename.endsWith(".json")),
|
.filter(fileBasename => fileBasename.endsWith(".json")),
|
||||||
"none"
|
"none"
|
||||||
]
|
]
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (value === "none") {
|
if (value === "none") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathJoin(dirPath, value);
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (internalFilePath === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathJoin(dirPath, value);
|
const filePath = pathJoin(
|
||||||
})();
|
buildContext.cacheDirPath,
|
||||||
|
pathBasename(internalFilePath)
|
||||||
|
);
|
||||||
|
|
||||||
const jarFilePath = pathJoin(buildContext.keycloakifyBuildDirPath, jarFileBasename);
|
fs.writeFileSync(
|
||||||
|
filePath,
|
||||||
|
Buffer.from(
|
||||||
|
fs
|
||||||
|
.readFileSync(internalFilePath)
|
||||||
|
.toString("utf8")
|
||||||
|
.replace(/keycloakify\-starter/g, buildContext.themeNames[0])
|
||||||
|
),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
|
||||||
|
return filePath;
|
||||||
|
})();
|
||||||
|
|
||||||
async function extractThemeResourcesFromJar() {
|
async function extractThemeResourcesFromJar() {
|
||||||
await extractArchive({
|
await extractArchive({
|
||||||
@ -317,7 +261,10 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
await extractThemeResourcesFromJar();
|
await extractThemeResourcesFromJar();
|
||||||
|
|
||||||
const jarFilePath_cacheDir = pathJoin(buildContext.cacheDirPath, jarFileBasename);
|
const jarFilePath_cacheDir = pathJoin(
|
||||||
|
buildContext.cacheDirPath,
|
||||||
|
pathBasename(jarFilePath)
|
||||||
|
);
|
||||||
|
|
||||||
fs.copyFileSync(jarFilePath, jarFilePath_cacheDir);
|
fs.copyFileSync(jarFilePath, jarFilePath_cacheDir);
|
||||||
|
|
||||||
@ -392,7 +339,8 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
...(realmJsonFilePath === undefined ? [] : ["--import-realm"])
|
...(realmJsonFilePath === undefined ? [] : ["--import-realm"])
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
cwd: buildContext.keycloakifyBuildDirPath
|
cwd: buildContext.keycloakifyBuildDirPath,
|
||||||
|
shell: true
|
||||||
}
|
}
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
@ -418,6 +366,10 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
[
|
[
|
||||||
|
"",
|
||||||
|
`The ftl files from ${chalk.bold(
|
||||||
|
`.${pathSep}${pathRelative(process.cwd(), pathJoin(buildContext.keycloakifyBuildDirPath, "theme"))}`
|
||||||
|
)} are mounted in the Keycloak container.`,
|
||||||
"",
|
"",
|
||||||
`Keycloak Admin console: ${chalk.cyan.bold(
|
`Keycloak Admin console: ${chalk.cyan.bold(
|
||||||
`http://localhost:${cliCommandOptions.port}`
|
`http://localhost:${cliCommandOptions.port}`
|
||||||
@ -458,7 +410,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { isKeycloakifyBuildSuccess } = await keycloakifyBuild({
|
const { isKeycloakifyBuildSuccess } = await keycloakifyBuild({
|
||||||
onlyBuildJarFileBasename: jarFileBasename,
|
buildForKeycloakMajorVersionNumber: keycloakMajorVersionNumber,
|
||||||
buildContext
|
buildContext
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -79,8 +79,16 @@ export async function getProxyFetchOptions(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cafileContent = await readFile(cafile, "utf-8");
|
const cafileContent = await readFile(cafile, "utf-8");
|
||||||
|
|
||||||
|
const newLinePlaceholder = "NEW_LINE_PLACEHOLDER_xIsPsK23svt";
|
||||||
|
|
||||||
return chunks(cafileContent.split(/(-----END CERTIFICATE-----)/), 2).map(
|
return chunks(cafileContent.split(/(-----END CERTIFICATE-----)/), 2).map(
|
||||||
ca => ca.join("").replace(/^\n/, "").replace(/\n/g, "\\n")
|
ca =>
|
||||||
|
ca
|
||||||
|
.join("")
|
||||||
|
.replace(/\r?\n/g, newLinePlaceholder)
|
||||||
|
.replace(new RegExp(`^${newLinePlaceholder}`), "")
|
||||||
|
.replace(new RegExp(newLinePlaceholder, "g"), "\\n")
|
||||||
);
|
);
|
||||||
})())
|
})())
|
||||||
);
|
);
|
||||||
|
@ -109,7 +109,7 @@ export async function extractArchive(params: {
|
|||||||
zipFile.on("entry", async (entry: yauzl.Entry) => {
|
zipFile.on("entry", async (entry: yauzl.Entry) => {
|
||||||
handle_file: {
|
handle_file: {
|
||||||
// NOTE: Skip directories
|
// NOTE: Skip directories
|
||||||
if (entry.fileName.endsWith(pathSep)) {
|
if (entry.fileName.endsWith("/")) {
|
||||||
break handle_file;
|
break handle_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
import { exec as execCallback } from "child_process";
|
|
||||||
import { readFile } from "fs/promises";
|
|
||||||
import { type FetchOptions } from "make-fetch-happen";
|
|
||||||
import { promisify } from "util";
|
|
||||||
|
|
||||||
function ensureArray<T>(arg0: T | T[]) {
|
|
||||||
return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0];
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensureSingleOrNone<T>(arg0: T | T[]) {
|
|
||||||
if (!Array.isArray(arg0)) return arg0;
|
|
||||||
if (arg0.length === 0) return undefined;
|
|
||||||
if (arg0.length === 1) return arg0[0];
|
|
||||||
throw new Error(
|
|
||||||
"Illegal configuration, expected a single value but found multiple: " +
|
|
||||||
arg0.map(String).join(", ")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type NPMConfig = Record<string, string | string[]>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get npm configuration as map
|
|
||||||
*/
|
|
||||||
async function getNmpConfig(params: { npmWorkspaceRootDirPath: string }) {
|
|
||||||
const { npmWorkspaceRootDirPath } = params;
|
|
||||||
|
|
||||||
const exec = promisify(execCallback);
|
|
||||||
|
|
||||||
const stdout = await exec("npm config get", {
|
|
||||||
encoding: "utf8",
|
|
||||||
cwd: npmWorkspaceRootDirPath
|
|
||||||
}).then(({ stdout }) => stdout);
|
|
||||||
|
|
||||||
const npmConfigReducer = (cfg: NPMConfig, [key, value]: [string, string]) =>
|
|
||||||
key in cfg
|
|
||||||
? { ...cfg, [key]: [...ensureArray(cfg[key]), value] }
|
|
||||||
: { ...cfg, [key]: value };
|
|
||||||
|
|
||||||
return stdout
|
|
||||||
.split("\n")
|
|
||||||
.filter(line => !line.startsWith(";"))
|
|
||||||
.map(line => line.trim())
|
|
||||||
.map(line => line.split("=", 2) as [string, string])
|
|
||||||
.reduce(npmConfigReducer, {} as NPMConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ProxyFetchOptions = Pick<
|
|
||||||
FetchOptions,
|
|
||||||
"proxy" | "noProxy" | "strictSSL" | "cert" | "ca"
|
|
||||||
>;
|
|
||||||
|
|
||||||
export async function getProxyFetchOptions(params: {
|
|
||||||
npmWorkspaceRootDirPath: string;
|
|
||||||
}): Promise<ProxyFetchOptions> {
|
|
||||||
const { npmWorkspaceRootDirPath } = params;
|
|
||||||
|
|
||||||
const cfg = await getNmpConfig({ npmWorkspaceRootDirPath });
|
|
||||||
|
|
||||||
const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]);
|
|
||||||
const noProxy = cfg["noproxy"] ?? cfg["no-proxy"];
|
|
||||||
|
|
||||||
function maybeBoolean(arg0: string | undefined) {
|
|
||||||
return typeof arg0 === "undefined" ? undefined : Boolean(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const strictSSL = maybeBoolean(ensureSingleOrNone(cfg["strict-ssl"]));
|
|
||||||
const cert = cfg["cert"];
|
|
||||||
const ca = ensureArray(cfg["ca"] ?? cfg["ca[]"]);
|
|
||||||
const cafile = ensureSingleOrNone(cfg["cafile"]);
|
|
||||||
|
|
||||||
if (typeof cafile !== "undefined" && cafile !== "null") {
|
|
||||||
ca.push(
|
|
||||||
...(await (async () => {
|
|
||||||
function chunks<T>(arr: T[], size: number = 2) {
|
|
||||||
return arr
|
|
||||||
.map((_, i) => i % size == 0 && arr.slice(i, i + size))
|
|
||||||
.filter(Boolean) as T[][];
|
|
||||||
}
|
|
||||||
|
|
||||||
const cafileContent = await readFile(cafile, "utf-8");
|
|
||||||
return chunks(cafileContent.split(/(-----END CERTIFICATE-----)/), 2).map(
|
|
||||||
ca => ca.join("").replace(/^\n/, "").replace(/\n/g, "\\n")
|
|
||||||
);
|
|
||||||
})())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
proxy,
|
|
||||||
noProxy,
|
|
||||||
strictSSL,
|
|
||||||
cert,
|
|
||||||
ca: ca.length === 0 ? undefined : ca
|
|
||||||
};
|
|
||||||
}
|
|
@ -42,7 +42,7 @@ const LoginX509Info = lazy(() => import("keycloakify/login/pages/LoginX509Info")
|
|||||||
const WebauthnError = lazy(() => import("keycloakify/login/pages/WebauthnError"));
|
const WebauthnError = lazy(() => import("keycloakify/login/pages/WebauthnError"));
|
||||||
|
|
||||||
type DefaultPageProps = PageProps<KcContext, I18n> & {
|
type DefaultPageProps = PageProps<KcContext, I18n> & {
|
||||||
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps<KcContext, I18n>) => JSX.Element>;
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
|
||||||
doMakeUserConfirmPassword: boolean;
|
doMakeUserConfirmPassword: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,17 +209,13 @@ export declare namespace KcContext {
|
|||||||
export type Register = Common & {
|
export type Register = Common & {
|
||||||
pageId: "register.ftl";
|
pageId: "register.ftl";
|
||||||
profile: UserProfile;
|
profile: UserProfile;
|
||||||
|
passwordPolicies?: PasswordPolicies;
|
||||||
url: {
|
url: {
|
||||||
registrationAction: string;
|
registrationAction: string;
|
||||||
};
|
};
|
||||||
passwordRequired: boolean;
|
passwordRequired: boolean;
|
||||||
recaptchaRequired: boolean;
|
recaptchaRequired: boolean;
|
||||||
recaptchaSiteKey?: string;
|
recaptchaSiteKey?: string;
|
||||||
/**
|
|
||||||
* Theses values are added by: https://github.com/jcputney/keycloak-theme-additional-info-extension
|
|
||||||
* A Keycloak Java extension used as dependency in Keycloakify.
|
|
||||||
*/
|
|
||||||
passwordPolicies?: PasswordPolicies;
|
|
||||||
termsAcceptanceRequired?: boolean;
|
termsAcceptanceRequired?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -233,6 +229,7 @@ export declare namespace KcContext {
|
|||||||
client: {
|
client: {
|
||||||
baseUrl?: string;
|
baseUrl?: string;
|
||||||
};
|
};
|
||||||
|
message: NonNullable<Common["message"]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Error = Common & {
|
export type Error = Common & {
|
||||||
@ -479,16 +476,19 @@ export declare namespace KcContext {
|
|||||||
export type LoginUpdateProfile = Common & {
|
export type LoginUpdateProfile = Common & {
|
||||||
pageId: "login-update-profile.ftl";
|
pageId: "login-update-profile.ftl";
|
||||||
profile: UserProfile;
|
profile: UserProfile;
|
||||||
|
passwordPolicies?: PasswordPolicies;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IdpReviewUserProfile = Common & {
|
export type IdpReviewUserProfile = Common & {
|
||||||
pageId: "idp-review-user-profile.ftl";
|
pageId: "idp-review-user-profile.ftl";
|
||||||
profile: UserProfile;
|
profile: UserProfile;
|
||||||
|
passwordPolicies?: PasswordPolicies;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpdateEmail = Common & {
|
export type UpdateEmail = Common & {
|
||||||
pageId: "update-email.ftl";
|
pageId: "update-email.ftl";
|
||||||
profile: UserProfile;
|
profile: UserProfile;
|
||||||
|
passwordPolicies?: PasswordPolicies;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SelectAuthenticator = Common & {
|
export type SelectAuthenticator = Common & {
|
||||||
@ -752,6 +752,10 @@ export declare namespace Validators {
|
|||||||
assert<Equals<OnlyInExpected, never>>();
|
assert<Equals<OnlyInExpected, never>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Theses values are added by: https://github.com/jcputney/keycloak-theme-additional-info-extension
|
||||||
|
* A Keycloak Java extension used as dependency in Keycloakify.
|
||||||
|
*/
|
||||||
export type PasswordPolicies = {
|
export type PasswordPolicies = {
|
||||||
/** The minimum length of the password */
|
/** The minimum length of the password */
|
||||||
length?: number;
|
length?: number;
|
||||||
|
@ -99,13 +99,22 @@ export const kcContextCommonMock: KcContext.Common = {
|
|||||||
registrationEmailAsUsername: false
|
registrationEmailAsUsername: false
|
||||||
},
|
},
|
||||||
messagesPerField: {
|
messagesPerField: {
|
||||||
printIfExists: () => {
|
get: () => "",
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
existsError: () => false,
|
existsError: () => false,
|
||||||
get: fieldName => `Fake error for ${fieldName}`,
|
printIfExists: function <T>(fieldName: string, text: T) {
|
||||||
exists: () => false,
|
return this.get(fieldName) !== "" ? text : undefined;
|
||||||
getFirstError: fieldName => `Fake error for ${fieldName}`
|
},
|
||||||
|
exists: function (fieldName) {
|
||||||
|
return this.get(fieldName) !== "";
|
||||||
|
},
|
||||||
|
getFirstError: function (...fieldNames) {
|
||||||
|
for (const fieldName of fieldNames) {
|
||||||
|
if (this.existsError(fieldName)) {
|
||||||
|
return this.get(fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
locale: {
|
locale: {
|
||||||
supported: [
|
supported: [
|
||||||
@ -212,6 +221,11 @@ export const kcContextMocks = [
|
|||||||
clientId: "myApp",
|
clientId: "myApp",
|
||||||
baseUrl: "#",
|
baseUrl: "#",
|
||||||
attributes: {}
|
attributes: {}
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
type: "info",
|
||||||
|
summary:
|
||||||
|
"This is the info message from the Keycloak server (in real environment, this message is localized)"
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
id<KcContext.Error>({
|
id<KcContext.Error>({
|
||||||
@ -224,7 +238,8 @@ export const kcContextMocks = [
|
|||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
type: "error",
|
type: "error",
|
||||||
summary: "This is the error message"
|
summary:
|
||||||
|
"This is the error message from the Keycloak server (in real environment, this message is localized)"
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
id<KcContext.LoginResetPassword>({
|
id<KcContext.LoginResetPassword>({
|
||||||
|
@ -2,7 +2,7 @@ import { type FormAction, type FormFieldError } from "keycloakify/login/lib/useU
|
|||||||
import type { KcClsx } from "keycloakify/login/lib/kcClsx";
|
import type { KcClsx } from "keycloakify/login/lib/kcClsx";
|
||||||
import type { Attribute } from "keycloakify/login/KcContext";
|
import type { Attribute } from "keycloakify/login/KcContext";
|
||||||
|
|
||||||
export type UserProfileFormFieldsProps<KcContext, I18n> = {
|
export type UserProfileFormFieldsProps<KcContext = any, I18n = any> = {
|
||||||
kcContext: Extract<KcContext, { profile: unknown }>;
|
kcContext: Extract<KcContext, { profile: unknown }>;
|
||||||
i18n: I18n;
|
i18n: I18n;
|
||||||
kcClsx: KcClsx;
|
kcClsx: KcClsx;
|
||||||
|
@ -7,7 +7,7 @@ import type { KcContext } from "../KcContext";
|
|||||||
import type { I18n } from "../i18n";
|
import type { I18n } from "../i18n";
|
||||||
|
|
||||||
type IdpReviewUserProfileProps = PageProps<Extract<KcContext, { pageId: "idp-review-user-profile.ftl" }>, I18n> & {
|
type IdpReviewUserProfileProps = PageProps<Extract<KcContext, { pageId: "idp-review-user-profile.ftl" }>, I18n> & {
|
||||||
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps<KcContext, I18n>) => JSX.Element>;
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
|
||||||
doMakeUserConfirmPassword: boolean;
|
doMakeUserConfirmPassword: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { assert } from "keycloakify/tools/assert";
|
|
||||||
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
||||||
import type { KcContext } from "../KcContext";
|
import type { KcContext } from "../KcContext";
|
||||||
import type { I18n } from "../i18n";
|
import type { I18n } from "../i18n";
|
||||||
@ -8,11 +7,6 @@ export default function Info(props: PageProps<Extract<KcContext, { pageId: "info
|
|||||||
|
|
||||||
const { msgStr, msg } = i18n;
|
const { msgStr, msg } = i18n;
|
||||||
|
|
||||||
assert(
|
|
||||||
kcContext.message !== undefined,
|
|
||||||
"No message in kcContext.message, there will always be a message in production context, add it in your mock"
|
|
||||||
);
|
|
||||||
|
|
||||||
const { messageHeader, message, requiredActions, skipLink, pageRedirectUri, actionUri, client } = kcContext;
|
const { messageHeader, message, requiredActions, skipLink, pageRedirectUri, actionUri, client } = kcContext;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -16,7 +16,14 @@ export default function LoginConfigTotp(props: PageProps<Extract<KcContext, { pa
|
|||||||
const { msg, msgStr, advancedMsg } = i18n;
|
const { msg, msgStr, advancedMsg } = i18n;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Template kcContext={kcContext} i18n={i18n} doUseDefaultCss={doUseDefaultCss} classes={classes} headerNode={msg("loginTotpTitle")}>
|
<Template
|
||||||
|
kcContext={kcContext}
|
||||||
|
i18n={i18n}
|
||||||
|
doUseDefaultCss={doUseDefaultCss}
|
||||||
|
classes={classes}
|
||||||
|
headerNode={msg("loginTotpTitle")}
|
||||||
|
displayMessage={!messagesPerField.existsError("totp", "userLabel")}
|
||||||
|
>
|
||||||
<>
|
<>
|
||||||
<ol id="kc-totp-settings">
|
<ol id="kc-totp-settings">
|
||||||
<li>
|
<li>
|
||||||
|
@ -7,7 +7,7 @@ import type { KcContext } from "../KcContext";
|
|||||||
import type { I18n } from "../i18n";
|
import type { I18n } from "../i18n";
|
||||||
|
|
||||||
type LoginUpdateProfileProps = PageProps<Extract<KcContext, { pageId: "login-update-profile.ftl" }>, I18n> & {
|
type LoginUpdateProfileProps = PageProps<Extract<KcContext, { pageId: "login-update-profile.ftl" }>, I18n> & {
|
||||||
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps<KcContext, I18n>) => JSX.Element>;
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
|
||||||
doMakeUserConfirmPassword: boolean;
|
doMakeUserConfirmPassword: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ export default function LoginUpdateProfile(props: LoginUpdateProfileProps) {
|
|||||||
classes
|
classes
|
||||||
});
|
});
|
||||||
|
|
||||||
const { url, isAppInitiatedAction } = kcContext;
|
const { messagesPerField, url, isAppInitiatedAction } = kcContext;
|
||||||
|
|
||||||
const { msg, msgStr } = i18n;
|
const { msg, msgStr } = i18n;
|
||||||
|
|
||||||
@ -33,6 +33,7 @@ export default function LoginUpdateProfile(props: LoginUpdateProfileProps) {
|
|||||||
classes={classes}
|
classes={classes}
|
||||||
displayRequiredFields
|
displayRequiredFields
|
||||||
headerNode={msg("loginProfileTitle")}
|
headerNode={msg("loginProfileTitle")}
|
||||||
|
displayMessage={messagesPerField.exists("global")}
|
||||||
>
|
>
|
||||||
<form id="kc-update-profile-form" className={kcClsx("kcFormClass")} action={url.loginAction} method="post">
|
<form id="kc-update-profile-form" className={kcClsx("kcFormClass")} action={url.loginAction} method="post">
|
||||||
<UserProfileFormFields
|
<UserProfileFormFields
|
||||||
|
@ -9,7 +9,7 @@ import type { KcContext } from "../KcContext";
|
|||||||
import type { I18n } from "../i18n";
|
import type { I18n } from "../i18n";
|
||||||
|
|
||||||
type RegisterProps = PageProps<Extract<KcContext, { pageId: "register.ftl" }>, I18n> & {
|
type RegisterProps = PageProps<Extract<KcContext, { pageId: "register.ftl" }>, I18n> & {
|
||||||
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps<KcContext, I18n>) => JSX.Element>;
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
|
||||||
doMakeUserConfirmPassword: boolean;
|
doMakeUserConfirmPassword: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ export default function Register(props: RegisterProps) {
|
|||||||
doUseDefaultCss={doUseDefaultCss}
|
doUseDefaultCss={doUseDefaultCss}
|
||||||
classes={classes}
|
classes={classes}
|
||||||
headerNode={msg("registerTitle")}
|
headerNode={msg("registerTitle")}
|
||||||
|
displayMessage={messagesPerField.exists("global")}
|
||||||
displayRequiredFields
|
displayRequiredFields
|
||||||
>
|
>
|
||||||
<form id="kc-register-form" className={kcClsx("kcFormClass")} action={url.registrationAction} method="post">
|
<form id="kc-register-form" className={kcClsx("kcFormClass")} action={url.registrationAction} method="post">
|
||||||
|
@ -7,7 +7,7 @@ import type { KcContext } from "../KcContext";
|
|||||||
import type { I18n } from "../i18n";
|
import type { I18n } from "../i18n";
|
||||||
|
|
||||||
type UpdateEmailProps = PageProps<Extract<KcContext, { pageId: "update-email.ftl" }>, I18n> & {
|
type UpdateEmailProps = PageProps<Extract<KcContext, { pageId: "update-email.ftl" }>, I18n> & {
|
||||||
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps<KcContext, I18n>) => JSX.Element>;
|
UserProfileFormFields: LazyOrNot<(props: UserProfileFormFieldsProps) => JSX.Element>;
|
||||||
doMakeUserConfirmPassword: boolean;
|
doMakeUserConfirmPassword: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
||||||
import type { Plugin } from "vite";
|
import type { Plugin } from "vite";
|
||||||
import {
|
import {
|
||||||
nameOfTheGlobal,
|
|
||||||
basenameOfTheKeycloakifyResourcesDir,
|
basenameOfTheKeycloakifyResourcesDir,
|
||||||
keycloak_resources,
|
keycloak_resources,
|
||||||
vitePluginSubScriptEnvNames
|
vitePluginSubScriptEnvNames
|
||||||
@ -45,11 +44,12 @@ export function keycloakify(params?: Params) {
|
|||||||
break run_post_build_script_case;
|
break run_post_build_script_case;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildContext = JSON.parse(envValue) as BuildContext;
|
const { buildContext, resourcesDirPath } = JSON.parse(envValue) as {
|
||||||
|
buildContext: BuildContext;
|
||||||
|
resourcesDirPath: string;
|
||||||
|
};
|
||||||
|
|
||||||
process.chdir(
|
process.chdir(resourcesDirPath);
|
||||||
pathJoin(buildContext.keycloakifyBuildDirPath, "resources")
|
|
||||||
);
|
|
||||||
|
|
||||||
await postBuild?.(buildContext);
|
await postBuild?.(buildContext);
|
||||||
|
|
||||||
@ -170,9 +170,9 @@ export function keycloakify(params?: Params) {
|
|||||||
/import\.meta\.env(?:(?:\.BASE_URL)|(?:\["BASE_URL"\]))/g,
|
/import\.meta\.env(?:(?:\.BASE_URL)|(?:\["BASE_URL"\]))/g,
|
||||||
[
|
[
|
||||||
`(`,
|
`(`,
|
||||||
`(window.${nameOfTheGlobal} === undefined || import.meta.env.MODE === "development")?`,
|
`(window.kcContext === undefined || import.meta.env.MODE === "development")?`,
|
||||||
`"${urlPathname ?? "/"}":`,
|
`"${urlPathname ?? "/"}":`,
|
||||||
`(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/")`,
|
`(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/")`,
|
||||||
`)`
|
`)`
|
||||||
].join("")
|
].join("")
|
||||||
);
|
);
|
||||||
|
@ -17,6 +17,32 @@ export const Default: Story = {
|
|||||||
render: () => <KcPageStory />
|
render: () => <KcPageStory />
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const WithInvalidCredential: Story = {
|
||||||
|
render: () => (
|
||||||
|
<KcPageStory
|
||||||
|
kcContext={{
|
||||||
|
login: {
|
||||||
|
username: "johndoe"
|
||||||
|
},
|
||||||
|
messagesPerField: {
|
||||||
|
// NOTE: The other functions of messagesPerField are derived from get() and
|
||||||
|
// existsError() so they are the only ones that need to mock.
|
||||||
|
existsError: (fieldName: string, ...otherFieldNames: string[]) => {
|
||||||
|
const fieldNames = [fieldName, ...otherFieldNames];
|
||||||
|
return fieldNames.includes("username") || fieldNames.includes("password");
|
||||||
|
},
|
||||||
|
get: (fieldName: string) => {
|
||||||
|
if (fieldName === "username" || fieldName === "password") {
|
||||||
|
return "Invalid username or password.";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
export const WithoutRegistration: Story = {
|
export const WithoutRegistration: Story = {
|
||||||
render: () => (
|
render: () => (
|
||||||
<KcPageStory
|
<KcPageStory
|
||||||
@ -180,3 +206,16 @@ export const WithoutPasswordField: Story = {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const WithErrorMessage: Story = {
|
||||||
|
render: () => (
|
||||||
|
<KcPageStory
|
||||||
|
kcContext={{
|
||||||
|
message: {
|
||||||
|
summary: "The time allotted for the connection has elapsed. The login process will restart from the beginning.",
|
||||||
|
type: "error"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
@ -14,5 +14,17 @@ export default meta;
|
|||||||
type Story = StoryObj<typeof meta>;
|
type Story = StoryObj<typeof meta>;
|
||||||
|
|
||||||
export const Default: Story = {
|
export const Default: Story = {
|
||||||
render: () => <KcPageStory />
|
render: () => (
|
||||||
|
<KcPageStory
|
||||||
|
kcContext={{
|
||||||
|
message: {
|
||||||
|
summary: "You need to verify your email to activate your account.",
|
||||||
|
type: "warning"
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
email: "john.doe@gmail.com"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
@ -17,22 +17,31 @@ export const Default: Story = {
|
|||||||
render: () => <KcPageStory />
|
render: () => <KcPageStory />
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithFieldError: Story = {
|
export const WithEmailAlreadyExists: Story = {
|
||||||
render: () => (
|
render: () => (
|
||||||
<KcPageStory
|
<KcPageStory
|
||||||
kcContext={{
|
kcContext={{
|
||||||
profile: {
|
profile: {
|
||||||
attributesByName: {
|
attributesByName: {
|
||||||
|
username: {
|
||||||
|
value: "johndoe"
|
||||||
|
},
|
||||||
email: {
|
email: {
|
||||||
value: "max.mustermann@gmail.com"
|
value: "jhon.doe@gmail.com"
|
||||||
|
},
|
||||||
|
firstName: {
|
||||||
|
value: "John"
|
||||||
|
},
|
||||||
|
lastName: {
|
||||||
|
value: "Doe"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
messagesPerField: {
|
messagesPerField: {
|
||||||
existsError: (fieldName: string) => fieldName === "email",
|
// NOTE: The other functions of messagesPerField are derived from get() and
|
||||||
exists: (fieldName: string) => fieldName === "email",
|
// existsError() so they are the only ones that need to mock.
|
||||||
get: (fieldName: string) => (fieldName === "email" ? "I don't like your email address" : undefined),
|
existsError: (fieldName: string, ...otherFieldNames: string[]) => [fieldName, ...otherFieldNames].includes("email"),
|
||||||
printIfExists: <T,>(fieldName: string, x: T) => (fieldName === "email" ? x : undefined)
|
get: (fieldName: string) => (fieldName === "email" ? "Email already exists." : undefined)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -112,3 +121,15 @@ export const WithPresets: Story = {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const WithPasswordMinLength8: Story = {
|
||||||
|
render: () => (
|
||||||
|
<KcPageStory
|
||||||
|
kcContext={{
|
||||||
|
passwordPolicies: {
|
||||||
|
length: 8
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
import { replaceImportsInJsCode_vite } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/vite";
|
import { replaceImportsInJsCode_vite } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/vite";
|
||||||
import { replaceImportsInJsCode_webpack } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/webpack";
|
import { replaceImportsInJsCode_webpack } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/webpack";
|
||||||
import {
|
import { replaceImportsInCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInCssCode";
|
||||||
generateCssCodeToDefineGlobals,
|
|
||||||
replaceImportsInCssCode
|
|
||||||
} from "keycloakify/bin/keycloakify/replacers/replaceImportsInCssCode";
|
|
||||||
import { replaceImportsInInlineCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInInlineCssCode";
|
|
||||||
import { same } from "evt/tools/inDepth/same";
|
|
||||||
import { expect, it, describe } from "vitest";
|
import { expect, it, describe } from "vitest";
|
||||||
import {
|
import { basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/shared/constants";
|
||||||
basenameOfTheKeycloakifyResourcesDir,
|
|
||||||
nameOfTheGlobal
|
|
||||||
} from "keycloakify/bin/shared/constants";
|
|
||||||
|
|
||||||
describe("js replacer - vite", () => {
|
describe("js replacer - vite", () => {
|
||||||
it("replaceImportsInJsCode_vite - 1", () => {
|
it("replaceImportsInJsCode_vite - 1", () => {
|
||||||
@ -95,13 +87,13 @@ describe("js replacer - vite", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const fixedJsCodeExpected = `
|
const fixedJsCodeExpected = `
|
||||||
S=(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||||
|
|
||||||
function __vite__mapDeps(indexes) {
|
function __vite__mapDeps(indexes) {
|
||||||
if (!__vite__mapDeps.viteFileDeps) {
|
if (!__vite__mapDeps.viteFileDeps) {
|
||||||
__vite__mapDeps.viteFileDeps = [
|
__vite__mapDeps.viteFileDeps = [
|
||||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
||||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
||||||
@ -154,13 +146,13 @@ describe("js replacer - vite", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const fixedJsCodeExpected = `
|
const fixedJsCodeExpected = `
|
||||||
S=(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||||
|
|
||||||
function __vite__mapDeps(indexes) {
|
function __vite__mapDeps(indexes) {
|
||||||
if (!__vite__mapDeps.viteFileDeps) {
|
if (!__vite__mapDeps.viteFileDeps) {
|
||||||
__vite__mapDeps.viteFileDeps = [
|
__vite__mapDeps.viteFileDeps = [
|
||||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js"),
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js"),
|
||||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js")
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js")
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
||||||
@ -213,13 +205,13 @@ describe("js replacer - vite", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const fixedJsCodeExpected = `
|
const fixedJsCodeExpected = `
|
||||||
S=(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
S=(window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||||
|
|
||||||
function __vite__mapDeps(indexes) {
|
function __vite__mapDeps(indexes) {
|
||||||
if (!__vite__mapDeps.viteFileDeps) {
|
if (!__vite__mapDeps.viteFileDeps) {
|
||||||
__vite__mapDeps.viteFileDeps = [
|
__vite__mapDeps.viteFileDeps = [
|
||||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
||||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
(window.kcContext.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
||||||
@ -275,13 +267,13 @@ describe("js replacer - webpack", () => {
|
|||||||
|
|
||||||
const fixedJsCodeExpected = `
|
const fixedJsCodeExpected = `
|
||||||
function f() {
|
function f() {
|
||||||
return window.kcContext.url.resourcesPath + "/build/static/js/" + ({}[e] || e) + "." + {
|
return window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + {
|
||||||
3: "0664cdc0"
|
3: "0664cdc0"
|
||||||
}[e] + ".chunk.js"
|
}[e] + ".chunk.js"
|
||||||
}
|
}
|
||||||
|
|
||||||
function sameAsF() {
|
function sameAsF() {
|
||||||
return window.kcContext.url.resourcesPath + "/build/static/js/" + ({}[e] || e) + "." + {
|
return window.kcContext.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + ({}[e] || e) + "." + {
|
||||||
3: "0664cdc0"
|
3: "0664cdc0"
|
||||||
}[e] + ".chunk.js"
|
}[e] + ".chunk.js"
|
||||||
}
|
}
|
||||||
@ -296,7 +288,7 @@ describe("js replacer - webpack", () => {
|
|||||||
}
|
}
|
||||||
return "u";
|
return "u";
|
||||||
})()] = function(e) {
|
})()] = function(e) {
|
||||||
return "/build/static/js/" + e + "." + {
|
return "/${basenameOfTheKeycloakifyResourcesDir}/static/js/" + e + "." + {
|
||||||
147: "6c5cee76",
|
147: "6c5cee76",
|
||||||
787: "8da10fcf",
|
787: "8da10fcf",
|
||||||
922: "be170a73"
|
922: "be170a73"
|
||||||
@ -313,7 +305,7 @@ describe("js replacer - webpack", () => {
|
|||||||
}
|
}
|
||||||
return "miniCssF";
|
return "miniCssF";
|
||||||
})()] = function(e) {
|
})()] = function(e) {
|
||||||
return "/build/static/css/" + e + "." + {
|
return "/${basenameOfTheKeycloakifyResourcesDir}/static/css/" + e + "." + {
|
||||||
164:"dcfd7749",
|
164:"dcfd7749",
|
||||||
908:"67c9ed2c"
|
908:"67c9ed2c"
|
||||||
} [e] + ".chunk.css"
|
} [e] + ".chunk.css"
|
||||||
@ -328,7 +320,7 @@ describe("js replacer - webpack", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return "u";
|
return "u";
|
||||||
})()] = e => "/build/static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js"
|
})()] = e => "/${basenameOfTheKeycloakifyResourcesDir}/static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js"
|
||||||
|
|
||||||
t[(function(){
|
t[(function(){
|
||||||
var pd = Object.getOwnPropertyDescriptor(t, "p");
|
var pd = Object.getOwnPropertyDescriptor(t, "p");
|
||||||
@ -339,7 +331,7 @@ describe("js replacer - webpack", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return "miniCssF";
|
return "miniCssF";
|
||||||
})()] = e => "/build/static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css"
|
})()] = e => "/${basenameOfTheKeycloakifyResourcesDir}/static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
||||||
@ -388,279 +380,156 @@ describe("js replacer - webpack", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("css replacer", () => {
|
describe("css replacer", () => {
|
||||||
it("transforms absolute urls to css globals properly with no urlPathname", () => {
|
it("replaceImportsInCssCode - 1", () => {
|
||||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
const { fixedCssCode } = replaceImportsInCssCode({
|
||||||
cssCode: `
|
cssCode: `
|
||||||
.my-div {
|
.my-div {
|
||||||
background: url(/logo192.png) no-repeat center center;
|
background: url(/background.png) no-repeat center center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div2 {
|
.my-div2 {
|
||||||
background: url(/logo192.png) repeat center center;
|
background: url(/assets/background.png) repeat center center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div {
|
.my-div3 {
|
||||||
background-image: url(/static/media/something.svg);
|
background-image: url(/assets/media/something.svg);
|
||||||
}
|
}
|
||||||
`
|
`,
|
||||||
});
|
cssFileRelativeDirPath: "assets/",
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
|
||||||
.my-div {
|
|
||||||
background: var(--urla882a969fd39473) no-repeat center center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-div2 {
|
|
||||||
background: var(--urla882a969fd39473) repeat center center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-div {
|
|
||||||
background-image: var(--urldd75cab58377c19);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
|
||||||
|
|
||||||
const cssGlobalsToDefineExpected = {
|
|
||||||
urla882a969fd39473: "url(/logo192.png)",
|
|
||||||
urldd75cab58377c19: "url(/static/media/something.svg)"
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
|
||||||
|
|
||||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
|
||||||
cssGlobalsToDefine,
|
|
||||||
buildContext: {
|
buildContext: {
|
||||||
urlPathname: undefined
|
urlPathname: undefined
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const cssCodeToPrependInHeadExpected = `
|
|
||||||
:root {
|
|
||||||
--urla882a969fd39473: url(\${url.resourcesPath}/build/logo192.png);
|
|
||||||
--urldd75cab58377c19: url(\${url.resourcesPath}/build/static/media/something.svg);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(
|
|
||||||
true
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it("transforms absolute urls to css globals properly with custom urlPathname", () => {
|
|
||||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
|
||||||
cssCode: `
|
|
||||||
.my-div {
|
|
||||||
background: url(/x/y/z/logo192.png) no-repeat center center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-div2 {
|
|
||||||
background: url(/x/y/z/logo192.png) no-repeat center center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-div {
|
|
||||||
background-image: url(/x/y/z/static/media/something.svg);
|
|
||||||
}
|
|
||||||
`
|
|
||||||
});
|
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
const fixedCssCodeExpected = `
|
||||||
.my-div {
|
.my-div {
|
||||||
background: var(--url749a3139386b2c8) no-repeat center center;
|
background: url(../background.png) no-repeat center center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div2 {
|
.my-div2 {
|
||||||
background: var(--url749a3139386b2c8) no-repeat center center;
|
background: url(background.png) repeat center center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div {
|
.my-div3 {
|
||||||
background-image: var(--url8bdc0887b97ac9a);
|
background-image: url(media/something.svg);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
const cssGlobalsToDefineExpected = {
|
it("replaceImportsInCssCode - 2", () => {
|
||||||
url749a3139386b2c8: "url(/x/y/z/logo192.png)",
|
const { fixedCssCode } = replaceImportsInCssCode({
|
||||||
url8bdc0887b97ac9a: "url(/x/y/z/static/media/something.svg)"
|
cssCode: `
|
||||||
};
|
.my-div {
|
||||||
|
background: url(/a/b/background.png) no-repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
.my-div2 {
|
||||||
|
background: url(/a/b/assets/background.png) repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
.my-div3 {
|
||||||
cssGlobalsToDefine,
|
background-image: url(/a/b/assets/media/something.svg);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
cssFileRelativeDirPath: "assets/",
|
||||||
buildContext: {
|
buildContext: {
|
||||||
urlPathname: "/x/y/z/"
|
urlPathname: "/a/b/"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const cssCodeToPrependInHeadExpected = `
|
const fixedCssCodeExpected = `
|
||||||
:root {
|
.my-div {
|
||||||
--url749a3139386b2c8: url(\${url.resourcesPath}/build/logo192.png);
|
background: url(../background.png) no-repeat center center;
|
||||||
--url8bdc0887b97ac9a: url(\${url.resourcesPath}/build/static/media/something.svg);
|
}
|
||||||
|
|
||||||
|
.my-div2 {
|
||||||
|
background: url(background.png) repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-div3 {
|
||||||
|
background-image: url(media/something.svg);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe("inline css replacer", () => {
|
it("replaceImportsInCssCode - 3", () => {
|
||||||
describe("no url pathName", () => {
|
const { fixedCssCode } = replaceImportsInCssCode({
|
||||||
const cssCode = `
|
cssCode: `
|
||||||
@font-face {
|
.my-div {
|
||||||
font-family: "Work Sans";
|
background: url(/a/b/background.png) no-repeat center center;
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/fonts/WorkSans/worksans-regular-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 500;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/fonts/WorkSans/worksans-medium-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 600;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/fonts/WorkSans/worksans-semibold-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 700;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
it("transforms css for standalone app properly", () => {
|
|
||||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
|
||||||
cssCode,
|
|
||||||
buildContext: {
|
|
||||||
urlPathname: undefined
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
.my-div2 {
|
||||||
@font-face {
|
background: url(/a/b/assets/background.png) repeat center center;
|
||||||
font-family: "Work Sans";
|
}
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
.my-div3 {
|
||||||
font-display: swap;
|
background-image: url(/a/b/assets/media/something.svg);
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-regular-webfont.woff2)
|
}
|
||||||
format("woff2");
|
`,
|
||||||
|
cssFileRelativeDirPath: undefined,
|
||||||
|
buildContext: {
|
||||||
|
urlPathname: "/a/b/"
|
||||||
}
|
}
|
||||||
@font-face {
|
});
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
const fixedCssCodeExpected = `
|
||||||
font-weight: 500;
|
.my-div {
|
||||||
font-display: swap;
|
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center;
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-medium-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
}
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
.my-div2 {
|
||||||
font-style: normal;
|
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center;
|
||||||
font-weight: 600;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-semibold-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
}
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
.my-div3 {
|
||||||
font-style: normal;
|
background-image: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg);
|
||||||
font-weight: 700;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-bold-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with url pathName", () => {
|
it("replaceImportsInCssCode - 4", () => {
|
||||||
const cssCode = `
|
const { fixedCssCode } = replaceImportsInCssCode({
|
||||||
@font-face {
|
cssCode: `
|
||||||
font-family: "Work Sans";
|
.my-div {
|
||||||
font-style: normal;
|
background: url(/background.png) no-repeat center center;
|
||||||
font-weight: 400;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/x/y/z/fonts/WorkSans/worksans-regular-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 500;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/x/y/z/fonts/WorkSans/worksans-medium-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 600;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/x/y/z/fonts/WorkSans/worksans-semibold-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 700;
|
|
||||||
font-display: swap;
|
|
||||||
src: url("/x/y/z/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
it("transforms css for standalone app properly", () => {
|
|
||||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
|
||||||
cssCode,
|
|
||||||
buildContext: {
|
|
||||||
urlPathname: "/x/y/z/"
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
.my-div2 {
|
||||||
@font-face {
|
background: url(/assets/background.png) repeat center center;
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-regular-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
}
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 500;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-medium-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 600;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-semibold-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 700;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-bold-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
.my-div3 {
|
||||||
|
background-image: url(/assets/media/something.svg);
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
cssFileRelativeDirPath: undefined,
|
||||||
|
buildContext: {
|
||||||
|
urlPathname: undefined
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fixedCssCodeExpected = `
|
||||||
|
.my-div {
|
||||||
|
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/background.png) no-repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-div2 {
|
||||||
|
background: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/background.png) repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-div3 {
|
||||||
|
background-image: url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/assets/media/something.svg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import path from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { it, describe, expect, vi, beforeAll, afterAll } from "vitest";
|
import { it, describe, expect, vi, beforeAll, afterAll } from "vitest";
|
||||||
import { crawl } from "keycloakify/bin/tools/crawl";
|
import { crawl } from "keycloakify/bin/tools/crawl";
|
||||||
|
|
||||||
@ -13,11 +13,11 @@ describe("crawl", () => {
|
|||||||
switch (dir_path) {
|
switch (dir_path) {
|
||||||
case "root_dir":
|
case "root_dir":
|
||||||
return ["sub_1_dir", "file_1", "sub_2_dir", "file_2"];
|
return ["sub_1_dir", "file_1", "sub_2_dir", "file_2"];
|
||||||
case path.join("root_dir", "sub_1_dir"):
|
case pathJoin("root_dir", "sub_1_dir"):
|
||||||
return ["file_3", "sub_3_dir", "file_4"];
|
return ["file_3", "sub_3_dir", "file_4"];
|
||||||
case path.join("root_dir", "sub_1_dir", "sub_3_dir"):
|
case pathJoin("root_dir", "sub_1_dir", "sub_3_dir"):
|
||||||
return ["file_5"];
|
return ["file_5"];
|
||||||
case path.join("root_dir", "sub_2_dir"):
|
case pathJoin("root_dir", "sub_2_dir"):
|
||||||
return [];
|
return [];
|
||||||
default: {
|
default: {
|
||||||
const enoent = new Error(
|
const enoent = new Error(
|
||||||
@ -46,10 +46,12 @@ describe("crawl", () => {
|
|||||||
});
|
});
|
||||||
it("returns files under a given dir_path", async () => {
|
it("returns files under a given dir_path", async () => {
|
||||||
const paths = crawl({
|
const paths = crawl({
|
||||||
dirPath: "root_dir/sub_1_dir/sub_3_dir",
|
dirPath: pathJoin("root_dir", "sub_1_dir", "sub_3_dir"),
|
||||||
returnedPathsType: "absolute"
|
returnedPathsType: "absolute"
|
||||||
});
|
});
|
||||||
expect(paths).toEqual(["root_dir/sub_1_dir/sub_3_dir/file_5"]);
|
expect(paths).toEqual([
|
||||||
|
pathJoin("root_dir", "sub_1_dir", "sub_3_dir", "file_5")
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
it("returns files recursively under a given dir_path", async () => {
|
it("returns files recursively under a given dir_path", async () => {
|
||||||
const paths = crawl({
|
const paths = crawl({
|
||||||
@ -57,11 +59,11 @@ describe("crawl", () => {
|
|||||||
returnedPathsType: "absolute"
|
returnedPathsType: "absolute"
|
||||||
});
|
});
|
||||||
expect(paths).toEqual([
|
expect(paths).toEqual([
|
||||||
"root_dir/sub_1_dir/file_3",
|
pathJoin("root_dir", "sub_1_dir", "file_3"),
|
||||||
"root_dir/sub_1_dir/sub_3_dir/file_5",
|
pathJoin("root_dir", "sub_1_dir", "sub_3_dir", "file_5"),
|
||||||
"root_dir/sub_1_dir/file_4",
|
pathJoin("root_dir", "sub_1_dir", "file_4"),
|
||||||
"root_dir/file_1",
|
pathJoin("root_dir", "file_1"),
|
||||||
"root_dir/file_2"
|
pathJoin("root_dir", "file_2")
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
it("throw dir_path does not exist", async () => {
|
it("throw dir_path does not exist", async () => {
|
||||||
|
Reference in New Issue
Block a user