Compare commits
9 Commits
v9.4.0-rc.
...
v9.4.0-rc.
Author | SHA1 | Date | |
---|---|---|---|
4ee0823acb | |||
d466123b1c | |||
21cbc14a48 | |||
b2f2c3e386 | |||
b03340ed10 | |||
5b563d8e9b | |||
2790487fc7 | |||
ad5a368065 | |||
7c0a631a9a |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "9.4.0-rc.12",
|
||||
"version": "9.4.0-rc.15",
|
||||
"description": "Create Keycloak themes using React",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -81,8 +81,7 @@ async function main() {
|
||||
|
||||
const generatedFileHeader = [
|
||||
`//This code was automatically generated by running ${pathRelative(thisCodebaseRootDirPath, __filename)}`,
|
||||
"//PLEASE DO NOT EDIT MANUALLY",
|
||||
""
|
||||
"//PLEASE DO NOT EDIT MANUALLY"
|
||||
].join("\n");
|
||||
|
||||
languages.forEach(language => {
|
||||
@ -95,6 +94,7 @@ async function main() {
|
||||
Buffer.from(
|
||||
[
|
||||
generatedFileHeader,
|
||||
"",
|
||||
"/* spell-checker: disable */",
|
||||
`const messages= ${JSON.stringify(recordForPageType[language], null, 2)};`,
|
||||
"",
|
||||
@ -113,10 +113,15 @@ async function main() {
|
||||
Buffer.from(
|
||||
[
|
||||
generatedFileHeader,
|
||||
`import * as en from "./en";`,
|
||||
"",
|
||||
"export async function getMessages(currentLanguageTag: string) {",
|
||||
" const { default: messages } = await (() => {",
|
||||
" switch (currentLanguageTag) {",
|
||||
...languages.map(language => ` case "${language}": return import("./${language}");`),
|
||||
` case "en": return en;`,
|
||||
...languages
|
||||
.filter(language => language !== "en")
|
||||
.map(language => ` case "${language}": return import("./${language}");`),
|
||||
' default: return { "default": {} };',
|
||||
" }",
|
||||
" })();",
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { downloadKeycloakStaticResources, type BuildOptionsLike } from "./keycloakify/generateTheme/downloadKeycloakStaticResources";
|
||||
import { join as pathJoin } from "path";
|
||||
import { join as pathJoin, relative as pathRelative } from "path";
|
||||
import { readBuildOptions } from "./keycloakify/buildOptions";
|
||||
import { themeTypes, keycloak_resources, lastKeycloakVersionWithAccountV1 } from "./constants";
|
||||
import { readThisNpmProjectVersion } from "./tools/readThisNpmProjectVersion";
|
||||
@ -19,6 +19,7 @@ export async function copyKeycloakResourcesToPublic(params: { processArgv: strin
|
||||
const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo");
|
||||
|
||||
const { keycloakifyBuildinfoRaw } = generateKeycloakifyBuildinfoRaw({
|
||||
destDirPath,
|
||||
"keycloakifyVersion": readThisNpmProjectVersion(),
|
||||
buildOptions
|
||||
});
|
||||
@ -72,12 +73,13 @@ export async function copyKeycloakResourcesToPublic(params: { processArgv: strin
|
||||
}
|
||||
|
||||
export function generateKeycloakifyBuildinfoRaw(params: {
|
||||
destDirPath: string;
|
||||
keycloakifyVersion: string;
|
||||
buildOptions: BuildOptionsLike & {
|
||||
loginThemeResourcesFromKeycloakVersion: string;
|
||||
};
|
||||
}) {
|
||||
const { keycloakifyVersion, buildOptions } = params;
|
||||
const { destDirPath, keycloakifyVersion, buildOptions } = params;
|
||||
|
||||
const { cacheDirPath, npmWorkspaceRootDirPath, loginThemeResourcesFromKeycloakVersion, ...rest } = buildOptions;
|
||||
|
||||
@ -88,8 +90,8 @@ export function generateKeycloakifyBuildinfoRaw(params: {
|
||||
keycloakifyVersion,
|
||||
"buildOptions": {
|
||||
loginThemeResourcesFromKeycloakVersion,
|
||||
cacheDirPath,
|
||||
npmWorkspaceRootDirPath
|
||||
"cacheDirPath": pathRelative(destDirPath, cacheDirPath),
|
||||
"npmWorkspaceRootDirPath": pathRelative(destDirPath, npmWorkspaceRootDirPath)
|
||||
}
|
||||
},
|
||||
null,
|
||||
|
@ -59,7 +59,7 @@ export async function main() {
|
||||
);
|
||||
}
|
||||
|
||||
const containerKeycloakVersion = "23.0.0";
|
||||
const containerKeycloakVersion = "23.0.6";
|
||||
|
||||
generateStartKeycloakTestingContainer({
|
||||
"keycloakVersion": containerKeycloakVersion,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
||||
import type { Plugin } from "vite";
|
||||
import { assert } from "tsafe/assert";
|
||||
import * as fs from "fs";
|
||||
import { resolvedViteConfigJsonBasename, nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir, keycloak_resources } from "../bin/constants";
|
||||
import type { ResolvedViteConfig } from "../bin/keycloakify/buildOptions/resolvedViteConfig";
|
||||
@ -9,20 +8,32 @@ import { replaceAll } from "../bin/tools/String.prototype.replaceAll";
|
||||
import { id } from "tsafe/id";
|
||||
import { rm } from "../bin/tools/fs.rm";
|
||||
import { copyKeycloakResourcesToPublic } from "../bin/copy-keycloak-resources-to-public";
|
||||
import { assert } from "tsafe/assert";
|
||||
|
||||
export function keycloakify(): Plugin {
|
||||
export function keycloakify() {
|
||||
let reactAppRootDirPath: string | undefined = undefined;
|
||||
let urlPathname: string | undefined = undefined;
|
||||
let buildDirPath: string | undefined = undefined;
|
||||
let command: "build" | "serve" | undefined = undefined;
|
||||
|
||||
return {
|
||||
"name": "keycloakify",
|
||||
"apply": "build",
|
||||
const plugin = {
|
||||
"name": "keycloakify" as const,
|
||||
"configResolved": async resolvedConfig => {
|
||||
command = resolvedConfig.command;
|
||||
|
||||
reactAppRootDirPath = resolvedConfig.root;
|
||||
urlPathname = (() => {
|
||||
let out = resolvedConfig.env.BASE_URL;
|
||||
|
||||
if (out.startsWith(".") && command === "build") {
|
||||
throw new Error(
|
||||
[
|
||||
`BASE_URL=${out} is not supported By Keycloakify. Use an absolute URL instead.`,
|
||||
`If this is a problem, please open an issue at https://github.com/keycloakify/keycloakify/issues/new`
|
||||
].join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
if (out === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
@ -45,7 +56,7 @@ export function keycloakify(): Plugin {
|
||||
});
|
||||
|
||||
if (!fs.existsSync(cacheDirPath)) {
|
||||
fs.mkdirSync(cacheDirPath);
|
||||
fs.mkdirSync(cacheDirPath, { "recursive": true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
@ -70,6 +81,12 @@ export function keycloakify(): Plugin {
|
||||
});
|
||||
},
|
||||
"transform": (code, id) => {
|
||||
assert(command !== undefined);
|
||||
|
||||
if (command !== "build") {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(reactAppRootDirPath !== undefined);
|
||||
|
||||
let transformedCode: string | undefined = undefined;
|
||||
@ -83,9 +100,8 @@ export function keycloakify(): Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
const isJavascriptFile = id.endsWith(".js") || id.endsWith(".jsx");
|
||||
|
||||
{
|
||||
const isJavascriptFile = id.endsWith(".js") || id.endsWith(".jsx");
|
||||
const isTypeScriptFile = id.endsWith(".ts") || id.endsWith(".tsx");
|
||||
|
||||
if (!isTypeScriptFile && !isJavascriptFile) {
|
||||
@ -93,8 +109,6 @@ export function keycloakify(): Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
const windowToken = isJavascriptFile ? "window" : "(window as any)";
|
||||
|
||||
if (transformedCode === undefined) {
|
||||
transformedCode = code;
|
||||
}
|
||||
@ -104,9 +118,9 @@ export function keycloakify(): Plugin {
|
||||
"import.meta.env.BASE_URL",
|
||||
[
|
||||
`(`,
|
||||
`(${windowToken}.${nameOfTheGlobal} === undefined || import.meta.env.MODE === "development") ?`,
|
||||
` "${urlPathname ?? "/"}" :`,
|
||||
` \`\${${windowToken}.${nameOfTheGlobal}.url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/\``,
|
||||
`(window.${nameOfTheGlobal} === undefined || import.meta.env.MODE === "development")?`,
|
||||
`"${urlPathname ?? "/"}":`,
|
||||
`(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/")`,
|
||||
`)`
|
||||
].join("")
|
||||
);
|
||||
@ -120,10 +134,18 @@ export function keycloakify(): Plugin {
|
||||
"code": transformedCode
|
||||
};
|
||||
},
|
||||
"buildEnd": async () => {
|
||||
"closeBundle": async () => {
|
||||
assert(command !== undefined);
|
||||
|
||||
if (command !== "build") {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(buildDirPath !== undefined);
|
||||
|
||||
await rm(pathJoin(buildDirPath, keycloak_resources), { "recursive": true, "force": true });
|
||||
}
|
||||
};
|
||||
} satisfies Plugin;
|
||||
|
||||
return plugin as any;
|
||||
}
|
||||
|
Reference in New Issue
Block a user