Feat scrip: download-builtin-keycloak-theme for downloading any version of the builtin themes

This commit is contained in:
garronej 2021-10-07 21:00:53 +02:00
parent fb5f358686
commit c52b8cc98e
7 changed files with 161 additions and 22 deletions

1
.gitignore vendored
View File

@ -43,3 +43,4 @@ jspm_packages
/dist /dist
/sample_react_project/ /sample_react_project/
/.yarn_home/

View File

@ -14,11 +14,12 @@
"grant-exec-perms": "node dist/bin/tools/grant-exec-perms.js", "grant-exec-perms": "node dist/bin/tools/grant-exec-perms.js",
"test": "node dist/test/bin/main && node dist/test/lib", "test": "node dist/test/bin/main && node dist/test/lib",
"copy-files": "copyfiles -u 1 src/**/*.ftl src/**/*.xml src/**/*.js dist/", "copy-files": "copyfiles -u 1 src/**/*.ftl src/**/*.xml src/**/*.js dist/",
"generate-messages": "node dist/bin/generate-i18n-messages.js" "generate-messages": "node dist/bin/generate-i18n-messages.js",
"link_in_test_app": "node dist/bin/link_in_test_app.js"
}, },
"bin": { "bin": {
"build-keycloak-theme": "dist/bin/build-keycloak-theme/index.js", "build-keycloak-theme": "dist/bin/build-keycloak-theme/index.js",
"install-builtin-keycloak-themes": "dist/bin/install-builtin-keycloak-themes.js" "download-builtin-keycloak-theme": "dist/bin/download-builtin-keycloak-theme.js"
}, },
"author": "u/garronej", "author": "u/garronej",
"license": "MIT", "license": "MIT",

View File

@ -4,7 +4,6 @@ import { join as pathJoin, relative as pathRelative, basename as pathBasename }
import * as child_process from "child_process"; import * as child_process from "child_process";
import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles"; import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles";
import { URL } from "url"; import { URL } from "url";
import type { KeycloakVersion } from "../KeycloakVersion";
type ParsedPackageJson = { type ParsedPackageJson = {
name: string; name: string;
@ -12,8 +11,6 @@ type ParsedPackageJson = {
homepage?: string; homepage?: string;
}; };
const keycloakVersion: KeycloakVersion = "15.0.2";
const reactProjectDirPath = process.cwd(); const reactProjectDirPath = process.cwd();
const doUseExternalAssets = process.argv[2]?.toLowerCase() === "--external-assets"; const doUseExternalAssets = process.argv[2]?.toLowerCase() === "--external-assets";
@ -70,7 +67,10 @@ export function main() {
})(), })(),
extraPagesId, extraPagesId,
extraThemeProperties, extraThemeProperties,
keycloakVersion //We have to leave it at that otherwise we break our default theme.
//Problem is that we can't guarantee that the the old resources common
//will still be available on the newer keycloak version.
"keycloakVersion": "11.0.3"
}); });
const { jarFilePath } = generateJavaStackFiles({ const { jarFilePath } = generateJavaStackFiles({
@ -88,7 +88,7 @@ export function main() {
generateDebugFiles({ generateDebugFiles({
keycloakThemeBuildingDirPath, keycloakThemeBuildingDirPath,
themeName, themeName,
keycloakVersion "keycloakVersion": "15.0.2"
}); });
console.log([ console.log([

View File

@ -7,7 +7,7 @@ import {
replaceImportsFromStaticInJsCode replaceImportsFromStaticInJsCode
} from "./replaceImportFromStatic"; } from "./replaceImportFromStatic";
import { generateFtlFilesCodeFactory, pageIds } from "./generateFtl"; import { generateFtlFilesCodeFactory, pageIds } from "./generateFtl";
import { downloadBuiltinKeycloakTheme } from "../install-builtin-keycloak-themes"; import { downloadBuiltinKeycloakTheme } from "../download-builtin-keycloak-theme";
import * as child_process from "child_process"; import * as child_process from "child_process";
import { resourcesCommonPath, resourcesPath, subDirOfPublicDirBasename } from "../../lib/getKcContext/kcContextMocks/urlResourcesPath"; import { resourcesCommonPath, resourcesPath, subDirOfPublicDirBasename } from "../../lib/getKcContext/kcContextMocks/urlResourcesPath";
import { isInside } from "../tools/isInside"; import { isInside } from "../tools/isInside";

View File

@ -3,7 +3,7 @@
import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme"; import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme";
import { join as pathJoin } from "path"; import { join as pathJoin } from "path";
import { downloadAndUnzip } from "./tools/downloadAndUnzip" import { downloadAndUnzip } from "./tools/downloadAndUnzip"
import type { KeycloakVersion } from "../bin/KeycloakVersion"; import type { KeycloakVersion } from "./KeycloakVersion";
export function downloadBuiltinKeycloakTheme( export function downloadBuiltinKeycloakTheme(
params: { params: {
@ -28,19 +28,25 @@ export function downloadBuiltinKeycloakTheme(
if (require.main === module) { if (require.main === module) {
const keycloakVersion = (() => {
const keycloakVersion = process.argv[2] as (KeycloakVersion | undefined);
if (keycloakVersion === undefined) {
return "15.0.2";
}
return keycloakVersion;
})();
const destDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme");
console.log(`Downloading builtins theme of Keycloak ${keycloakVersion} here ${destDirPath}`);
downloadBuiltinKeycloakTheme({ downloadBuiltinKeycloakTheme({
"keycloakVersion": (() => { keycloakVersion,
destDirPath
const keycloakVersion = process.argv[2] as (KeycloakVersion | undefined);
if (keycloakVersion === undefined) {
return "15.0.2";
}
return keycloakVersion;
})(),
"destDirPath": pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme")
}); });
} }

View File

@ -2,7 +2,7 @@ import "minimal-polyfills/Object.fromEntries";
import * as fs from "fs"; import * as fs from "fs";
import { join as pathJoin, relative as pathRelative } from "path"; import { join as pathJoin, relative as pathRelative } from "path";
import { crawl } from "./tools/crawl"; import { crawl } from "./tools/crawl";
import { downloadBuiltinKeycloakTheme } from "./install-builtin-keycloak-themes"; import { downloadBuiltinKeycloakTheme } from "./download-builtin-keycloak-theme";
import { getProjectRoot } from "./tools/getProjectRoot"; import { getProjectRoot } from "./tools/getProjectRoot";
import { rm_rf, rm_r } from "./tools/rm"; import { rm_rf, rm_r } from "./tools/rm";
import { keycloakVersions } from "./KeycloakVersion"; import { keycloakVersions } from "./KeycloakVersion";

131
src/bin/link_in_test_app.ts Normal file
View File

@ -0,0 +1,131 @@
import { execSync } from "child_process";
import { join as pathJoin, relative as pathRelative } from "path";
import * as fs from "fs";
const keycloakifyDirPath = pathJoin(__dirname, "..", "..");
fs.writeFileSync(
pathJoin(keycloakifyDirPath, "dist", "package.json"),
Buffer.from(
JSON.stringify(
(() => {
const packageJsonParsed = JSON.parse(
fs
.readFileSync(pathJoin(keycloakifyDirPath, "package.json"))
.toString("utf8"),
);
return {
...packageJsonParsed,
"main": packageJsonParsed["main"].replace(/^dist\//, ""),
"types": packageJsonParsed["types"].replace(/^dist\//, ""),
};
})(),
null,
2,
),
"utf8",
),
);
const commonThirdPartyDeps = (() => {
const namespaceModuleNames = ["@emotion"];
const standaloneModuleNames = ["react", "@types/react", "powerhooks", "tss-react", "evt"];
return [
...namespaceModuleNames
.map(namespaceModuleName =>
fs
.readdirSync(
pathJoin(
keycloakifyDirPath,
"node_modules",
namespaceModuleName,
),
)
.map(
submoduleName =>
`${namespaceModuleName}/${submoduleName}`,
),
)
.reduce((prev, curr) => [...prev, ...curr], []),
...standaloneModuleNames,
];
})();
const yarnHomeDirPath = pathJoin(keycloakifyDirPath, ".yarn_home");
execSync(
["rm -rf", "mkdir"].map(cmd => `${cmd} ${yarnHomeDirPath}`).join(" && "),
);
const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => {
const { targetModuleName, cwd } = params;
const cmd = [
"yarn",
"link",
...(targetModuleName !== undefined ? [targetModuleName] : []),
].join(" ");
console.log(`$ cd ${pathRelative(keycloakifyDirPath, cwd) || "."} && ${cmd}`);
execSync(cmd, {
cwd,
"env": {
...process.env,
"HOME": yarnHomeDirPath,
},
});
};
const testAppNames = ["keycloakify-demo-app"] as const;
const getTestAppPath = (testAppName: typeof testAppNames[number]) =>
pathJoin(keycloakifyDirPath, "..", testAppName);
testAppNames.forEach(testAppName =>
execSync("yarn install", { "cwd": getTestAppPath(testAppName) }),
);
console.log("=== Linking common dependencies ===");
const total = commonThirdPartyDeps.length;
let current = 0;
commonThirdPartyDeps.forEach(commonThirdPartyDep => {
current++;
console.log(`${current}/${total} ${commonThirdPartyDep}`);
const localInstallPath = pathJoin(
...[
keycloakifyDirPath,
"node_modules",
...(commonThirdPartyDep.startsWith("@")
? commonThirdPartyDep.split("/")
: [commonThirdPartyDep]),
],
);
execYarnLink({ "cwd": localInstallPath });
testAppNames.forEach(testAppName =>
execYarnLink({
"cwd": getTestAppPath(testAppName),
"targetModuleName": commonThirdPartyDep,
}),
);
});
console.log("=== Linking in house dependencies ===");
execYarnLink({ "cwd": pathJoin(keycloakifyDirPath, "dist") });
testAppNames.forEach(testAppName =>
execYarnLink({
"cwd": getTestAppPath(testAppName),
"targetModuleName": "keycloakify",
}),
);