keycloakify-test
Version:
Keycloak theme generator for Reacts app
159 lines • 8.45 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = exports.keycloakThemeEmailDirPath = exports.keycloakThemeBuildingDirPath = void 0;
var generateKeycloakThemeResources_1 = require("./generateKeycloakThemeResources");
var generateJavaStackFiles_1 = require("./generateJavaStackFiles");
var path_1 = require("path");
var child_process = __importStar(require("child_process"));
var generateStartKeycloakTestingContainer_1 = require("./generateStartKeycloakTestingContainer");
var url_1 = require("url");
var reactProjectDirPath = process.cwd();
var doUseExternalAssets = ((_a = process.argv[2]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "--external-assets";
var parsedPackageJson = require((0, path_1.join)(reactProjectDirPath, "package.json"));
exports.keycloakThemeBuildingDirPath = (0, path_1.join)(reactProjectDirPath, "dist/keycloak");
exports.keycloakThemeEmailDirPath = (0, path_1.join)(exports.keycloakThemeBuildingDirPath, "..", "keycloak_email");
function sanitizeThemeName(name) {
return name
.replace(/^@(.*)/, "$1")
.split("/")
.join("-");
}
function main() {
var _a, _b, _c, _d;
console.log("🔏 Building the keycloak theme...⌚");
var extraPagesId = (_b = (_a = parsedPackageJson["keycloakify"]) === null || _a === void 0 ? void 0 : _a["extraPages"]) !== null && _b !== void 0 ? _b : [];
var extraThemeProperties = (_d = (_c = parsedPackageJson["keycloakify"]) === null || _c === void 0 ? void 0 : _c["extraThemeProperties"]) !== null && _d !== void 0 ? _d : [];
var themeName = sanitizeThemeName(parsedPackageJson.name);
var doBundleEmailTemplate = (0, generateKeycloakThemeResources_1.generateKeycloakThemeResources)(__assign(__assign({ keycloakThemeBuildingDirPath: exports.keycloakThemeBuildingDirPath, keycloakThemeEmailDirPath: exports.keycloakThemeEmailDirPath, "reactAppBuildDirPath": (0, path_1.join)(reactProjectDirPath, "dist"), themeName: themeName }, (function () {
var _a;
var url = (function () {
var homepage = parsedPackageJson.homepage;
if (homepage !== undefined) {
return new url_1.URL(homepage);
}
return undefined;
})();
var baseAuthenticationUrl = (_a = parsedPackageJson.authUrl) !== null && _a !== void 0 ? _a : '';
return {
"urlPathname": url === undefined ? "/" : url.pathname.replace(/([^/])$/, "$1/"),
"baseAuthenticationUrl": baseAuthenticationUrl,
"urlOrigin": !doUseExternalAssets
? undefined
: (function () {
if (url === undefined) {
console.error("ERROR: You must specify 'homepage' in your package.json");
process.exit(-1);
}
return url.origin;
})(),
};
})()), { extraPagesId: extraPagesId, extraThemeProperties: extraThemeProperties,
//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
//will still be available on the newer keycloak version.
"keycloakVersion": "11.0.3" })).doBundleEmailTemplate;
var jarFilePath = (0, generateJavaStackFiles_1.generateJavaStackFiles)({
"version": parsedPackageJson.version,
themeName: themeName,
"homepage": parsedPackageJson.homepage,
keycloakThemeBuildingDirPath: exports.keycloakThemeBuildingDirPath,
doBundleEmailTemplate: doBundleEmailTemplate,
}).jarFilePath;
child_process.execSync("mvn package", {
"cwd": exports.keycloakThemeBuildingDirPath,
});
//We want, however to test in a container running the latest Keycloak version
var containerKeycloakVersion = "18.0.0";
(0, generateStartKeycloakTestingContainer_1.generateStartKeycloakTestingContainer)({
keycloakThemeBuildingDirPath: exports.keycloakThemeBuildingDirPath,
themeName: themeName,
"keycloakVersion": containerKeycloakVersion,
});
console.log([
"",
"\u2705 Your keycloak theme has been generated and bundled into ./".concat((0, path_1.relative)(reactProjectDirPath, jarFilePath), " \uD83D\uDE80"),
"It is to be placed in \"/opt/keycloak/providers\" in the container running a quay.io/keycloak/keycloak Docker image.",
"",
//TODO: Restore when we find a good Helm chart for Keycloak.
//"Using Helm (https://github.com/codecentric/helm-charts), edit to reflect:",
"",
"value.yaml: ",
" extraInitContainers: |",
" - name: realm-ext-provider",
" image: curlimages/curl",
" imagePullPolicy: IfNotPresent",
" command:",
" - sh",
" args:",
" - -c",
" - curl -L -f -S -o /extensions/".concat((0, path_1.basename)(jarFilePath), " https://AN.URL.FOR/").concat((0, path_1.basename)(jarFilePath)),
" volumeMounts:",
" - name: extensions",
" mountPath: /extensions",
" ",
" extraVolumeMounts: |",
" - name: extensions",
" mountPath: /opt/keycloak/providers",
" extraEnv: |",
" - name: KEYCLOAK_USER",
" value: admin",
" - name: KEYCLOAK_PASSWORD",
" value: xxxxxxxxx",
" - name: JAVA_OPTS",
" value: -Dkeycloak.profile=preview",
"",
"",
"To test your theme locally you can spin up a Keycloak ".concat(containerKeycloakVersion, " container image with the theme pre loaded by running:"),
"",
"\uD83D\uDC49 $ ./".concat((0, path_1.relative)(reactProjectDirPath, (0, path_1.join)(exports.keycloakThemeBuildingDirPath, generateStartKeycloakTestingContainer_1.generateStartKeycloakTestingContainer.basename)), " \uD83D\uDC48"),
"",
"Test with different Keycloak versions by editing the .sh file. see available versions here: https://quay.io/repository/keycloak/keycloak?tab=tags",
"",
"Once your container is up and running: ",
"- Log into the admin console 👉 http://localhost:8080/admin username: admin, password: admin 👈",
'- Create a realm named "myrealm"',
'- Create a client with ID: "myclient", "Root URL": "https://www.keycloak.org/app/" and "Valid redirect URIs": "https://www.keycloak.org/app/*"',
"- Select Login Theme: ".concat(themeName, " (don't forget to save at the bottom of the page)"),
"- Go to \uD83D\uDC49 https://www.keycloak.org/app/ \uD83D\uDC48 Click \"Save\" then \"Sign in\". You should see your login page",
"",
"Video demoing this process: https://youtu.be/N3wlBoH4hKg",
"",
].join("\n"));
}
exports.main = main;
//# sourceMappingURL=build-keycloak-theme.js.map