keycloakify
Version:
Framework to create custom Keycloak UIs
898 lines (836 loc) • 42.5 kB
JavaScript
;
exports.id = 254;
exports.ids = [254];
exports.modules = {
/***/ 2254:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "command": () => (/* binding */ command)
/* harmony export */ });
/* harmony import */ var _shared_customHandler_delegate__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(72138);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(71017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(73292);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(29041);
/* harmony import */ var tsafe_id__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(38469);
/* harmony import */ var _shared_addSyncExtensionsToPostinstallScript__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(80339);
/* harmony import */ var _tools_runPrettier__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(48433);
/* harmony import */ var _tools_npmInstall__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(63046);
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(32081);
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var zod__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(52300);
/* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(78818);
/* harmony import */ var chalk__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(chalk__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var cli_select__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(99398);
/* harmony import */ var cli_select__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(cli_select__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _tools_fs_existsAsync__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(43765);
/* harmony import */ var _sync_extensions_extensionModuleMeta__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(77372);
async function command(params) {
var _a, _b, _c, _d;
const { buildContext } = params;
const { hasBeenHandled } = await (0,_shared_customHandler_delegate__WEBPACK_IMPORTED_MODULE_0__/* .maybeDelegateCommandToCustomHandler */ .q)({
commandName: "initialize-login-theme",
buildContext
});
if (hasBeenHandled) {
return;
}
if (buildContext.implementedThemeTypes.login.isImplemented ||
buildContext.implementedThemeTypes.login.isImplemented_native) {
console.warn(chalk__WEBPACK_IMPORTED_MODULE_8___default().red("There is already a login theme in your project"));
process.exit(-1);
}
const parsedPackageJson = await (async () => {
const zParsedPackageJson = (() => {
const zTargetType = zod__WEBPACK_IMPORTED_MODULE_12__.z.object({
scripts: zod__WEBPACK_IMPORTED_MODULE_12__.z.record(zod__WEBPACK_IMPORTED_MODULE_12__.z.union([zod__WEBPACK_IMPORTED_MODULE_12__.z.string(), zod__WEBPACK_IMPORTED_MODULE_12__.z.undefined()])).optional(),
dependencies: zod__WEBPACK_IMPORTED_MODULE_12__.z.record(zod__WEBPACK_IMPORTED_MODULE_12__.z.union([zod__WEBPACK_IMPORTED_MODULE_12__.z.string(), zod__WEBPACK_IMPORTED_MODULE_12__.z.undefined()])).optional(),
devDependencies: zod__WEBPACK_IMPORTED_MODULE_12__.z.record(zod__WEBPACK_IMPORTED_MODULE_12__.z.union([zod__WEBPACK_IMPORTED_MODULE_12__.z.string(), zod__WEBPACK_IMPORTED_MODULE_12__.z.undefined()])).optional()
});
tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .h;
return (0,tsafe_id__WEBPACK_IMPORTED_MODULE_13__.id)(zTargetType);
})();
const parsedPackageJson = JSON.parse((await fs_promises__WEBPACK_IMPORTED_MODULE_2__.readFile(buildContext.packageJsonFilePath)).toString("utf8"));
zParsedPackageJson.parse(parsedPackageJson);
(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .h)((0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__.is)(parsedPackageJson));
return parsedPackageJson;
})();
(0,_shared_addSyncExtensionsToPostinstallScript__WEBPACK_IMPORTED_MODULE_4__/* .addSyncExtensionsToPostinstallScript */ .N)({
parsedPackageJson,
buildContext
});
const doInstallStories = await (async () => {
console.log(chalk__WEBPACK_IMPORTED_MODULE_8___default().cyan(`\nDo you want to install the Stories?`));
const YES = "Yes (Recommended)";
const NO = "No";
const { value } = await cli_select__WEBPACK_IMPORTED_MODULE_9___default()({
values: [YES, NO]
}).catch(() => {
process.exit(-1);
});
console.log(`${value}\n`);
return value === YES;
})();
install_storybook: {
if (!doInstallStories) {
break install_storybook;
}
if (buildContext.bundler !== "vite") {
break install_storybook;
}
if (Object.keys(Object.assign(Object.assign({}, parsedPackageJson.dependencies), parsedPackageJson.devDependencies)).includes("storybook")) {
break install_storybook;
}
((_a = parsedPackageJson.scripts) !== null && _a !== void 0 ? _a : (parsedPackageJson.scripts = {}))["storybook"] = "storybook dev -p 6006";
parsedPackageJson.scripts["build-storybook"] = "storybook build";
((_b = parsedPackageJson.devDependencies) !== null && _b !== void 0 ? _b : (parsedPackageJson.devDependencies = {}))["storybook"] = "^10.4.2";
parsedPackageJson.devDependencies["@storybook/react-vite"] = "^10.4.2";
const files = [
{
relativeFilePath: "main.ts",
fileContent: [
`import type { StorybookConfig } from "@storybook/react-vite";`,
``,
`const config: StorybookConfig = {`,
` stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],`,
` addons: [],`,
` framework: {`,
` name: "@storybook/react-vite",`,
` options: {}`,
` },`,
`};`,
`export default config;`,
``
].join("\n")
},
{
relativeFilePath: "preview.ts",
fileContent: storybookPreviewTsFileContent
}
];
for (let { relativeFilePath, fileContent } of files) {
const filePath = (0,path__WEBPACK_IMPORTED_MODULE_1__.join)(buildContext.projectDirPath, ".storybook", relativeFilePath);
{
const dirPath = (0,path__WEBPACK_IMPORTED_MODULE_1__.dirname)(filePath);
if (!(await (0,_tools_fs_existsAsync__WEBPACK_IMPORTED_MODULE_10__/* .existsAsync */ .o)(dirPath))) {
await fs_promises__WEBPACK_IMPORTED_MODULE_2__.mkdir(dirPath, { recursive: true });
}
}
run_prettier: {
if (!(await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_5__/* .getIsPrettierAvailable */ .MT)())) {
break run_prettier;
}
fileContent = await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_5__/* .runPrettier */ .eY)({
filePath: filePath,
sourceCode: fileContent
});
}
await fs_promises__WEBPACK_IMPORTED_MODULE_2__.writeFile(filePath, Buffer.from(fileContent, "utf8"));
}
}
{
const moduleName = "@keycloakify/login-ui";
const latestVersion = getModuleLatestVersion({ moduleName });
((_c = parsedPackageJson.dependencies) !== null && _c !== void 0 ? _c : (parsedPackageJson.dependencies = {}))[moduleName] = `~${latestVersion}`;
if (parsedPackageJson.devDependencies !== undefined) {
delete parsedPackageJson.devDependencies[moduleName];
}
}
install_stories: {
if (!doInstallStories) {
break install_stories;
}
const moduleName = "@keycloakify/login-ui-storybook";
const extensionModuleMetas = await (0,_sync_extensions_extensionModuleMeta__WEBPACK_IMPORTED_MODULE_11__/* .getExtensionModuleMetas */ .f)({ buildContext });
const hasLoginStoriesProvidedFromOtherModule = extensionModuleMetas.find(meta => meta.files.find(file => file.fileRelativePath.startsWith(`login${path__WEBPACK_IMPORTED_MODULE_1__.sep}pages${path__WEBPACK_IMPORTED_MODULE_1__.sep}`) && file.copyableFilePath.endsWith(".stories.tsx")) !== undefined) !== undefined;
if (hasLoginStoriesProvidedFromOtherModule) {
break install_stories;
}
const latestVersion = getModuleLatestVersion({ moduleName });
((_d = parsedPackageJson.devDependencies) !== null && _d !== void 0 ? _d : (parsedPackageJson.devDependencies = {}))[moduleName] = `~${latestVersion}`;
delete parsedPackageJson.dependencies[moduleName];
}
for (const fileBasename of ["main-kc.dev.tsx", "main.dev.tsx"]) {
const filePath = (0,path__WEBPACK_IMPORTED_MODULE_1__.join)(buildContext.themeSrcDirPath, fileBasename);
if (!(await (0,_tools_fs_existsAsync__WEBPACK_IMPORTED_MODULE_10__/* .existsAsync */ .o)(filePath))) {
continue;
}
const content = (await fs_promises__WEBPACK_IMPORTED_MODULE_2__.readFile(filePath)).toString("utf8");
if (!content.includes("export {}")) {
break;
}
let content_new = [
`import { createRoot } from "react-dom/client";`,
`import { StrictMode } from "react";`,
`import { KcPage } from "./kc.gen";`,
`import { getKcContextMock } from "./login/mocks/getKcContextMock";`,
``,
`const kcContext = getKcContextMock({`,
` pageId: "login.ftl",`,
` overrides: {}`,
`});`,
``,
`createRoot(document.getElementById("root")!).render(`,
` <StrictMode>`,
` <KcPage kcContext={kcContext} />`,
` </StrictMode>`,
`);`,
``
].join("\n");
if (await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_5__/* .getIsPrettierAvailable */ .MT)()) {
content_new = await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_5__/* .runPrettier */ .eY)({
sourceCode: content_new,
filePath
});
}
await fs_promises__WEBPACK_IMPORTED_MODULE_2__.writeFile(filePath, content_new);
break;
}
{
let sourceCode = JSON.stringify(parsedPackageJson, null, 2);
if (await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_5__/* .getIsPrettierAvailable */ .MT)()) {
sourceCode = await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_5__/* .runPrettier */ .eY)({
sourceCode,
filePath: buildContext.packageJsonFilePath
});
}
await fs_promises__WEBPACK_IMPORTED_MODULE_2__.writeFile(buildContext.packageJsonFilePath, Buffer.from(sourceCode, "utf8"));
}
await (0,_tools_npmInstall__WEBPACK_IMPORTED_MODULE_6__/* .npmInstall */ .c)({
packageJsonDirPath: (0,path__WEBPACK_IMPORTED_MODULE_1__.dirname)(buildContext.packageJsonFilePath)
});
}
function getModuleLatestVersion(params) {
const { moduleName } = params;
const versions = (() => {
const cmdOutput = child_process__WEBPACK_IMPORTED_MODULE_7__.execSync(`npm show ${moduleName} versions --json`)
.toString("utf8")
.trim();
const versions = JSON.parse(cmdOutput);
// NOTE: Bug in some older npm versions
if (typeof versions === "string") {
return [versions];
}
return versions;
})();
const version = versions.reverse().filter(version => !version.includes("-"))[0];
(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .h)(version !== undefined);
return version;
}
const storybookPreviewTsFileContent = [
`import type { Preview } from "@storybook/react-vite";`,
``,
`const preview: Preview = {`,
` parameters: {`,
` controls: {`,
` matchers: {`,
` color: /(background|color)$/i,`,
` date: /Date$/i`,
` }`,
` },`,
` options: {`,
` storySort: (a, b)=> {`,
``,
` const orderedPagesPrefix = [`,
` "Introduction",`,
` "login/login.ftl",`,
` "login/register.ftl",`,
` "login/terms.ftl",`,
` "login/error.ftl",`,
` "login/code.ftl",`,
` "login/delete-account-confirm.ftl",`,
` "login/delete-credential.ftl",`,
` "login/frontchannel-logout.ftl",`,
` "login/idp-review-user-profile.ftl",`,
` "login/info.ftl",`,
` "login/login-config-totp.ftl",`,
` "login/login-idp-link-confirm.ftl",`,
` "login/login-idp-link-email.ftl",`,
` "login/login-oauth-grant.ftl",`,
` "login/login-otp.ftl",`,
` "login/login-page-expired.ftl",`,
` "login/login-password.ftl",`,
` "login/login-reset-otp.ftl",`,
` "login/login-reset-password.ftl",`,
` "login/login-update-password.ftl",`,
` "login/login-update-profile.ftl",`,
` "login/login-username.ftl",`,
` "login/login-verify-email.ftl",`,
` "login/login-x509-info.ftl",`,
` "login/logout-confirm.ftl",`,
` "login/saml-post-form.ftl",`,
` "login/select-authenticator.ftl",`,
` "login/update-email.ftl",`,
` "login/webauthn-authenticate.ftl",`,
` "login/webauthn-error.ftl",`,
` "login/webauthn-register.ftl",`,
` "login/login-oauth2-device-verify-user-code.ftl",`,
` "login/login-recovery-authn-code-config.ftl",`,
` "login/login-recovery-authn-code-input.ftl",`,
` "account/account.ftl",`,
` "account/password.ftl",`,
` "account/federatedIdentity.ftl",`,
` "account/log.ftl",`,
` "account/sessions.ftl",`,
` "account/totp.ftl"`,
` ];`,
``,
` function getHardCodedWeight(title) {`,
` for (let i = 0; i < orderedPagesPrefix.length; i++) {`,
` if (`,
` title`,
` .toLowerCase()`,
` .startsWith(orderedPagesPrefix[i].toLowerCase())`,
` ) {`,
` return orderedPagesPrefix.length - i;`,
` }`,
` }`,
``,
` return 0;`,
` }`,
``,
` return getHardCodedWeight(b.title) - getHardCodedWeight(a.title);`,
``,
` }`,
``,
` }`,
` }`,
`};`,
``,
`export default preview;`,
``
].join("\n");
//# sourceMappingURL=initialize-login-theme.js.map
/***/ }),
/***/ 77372:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"x": () => (/* binding */ computeHash),
"f": () => (/* binding */ getExtensionModuleMetas)
});
// EXTERNAL MODULE: ./node_modules/tsafe/esm/assert.mjs + 1 modules
var assert = __webpack_require__(29041);
// EXTERNAL MODULE: ./node_modules/tsafe/esm/id.mjs
var id = __webpack_require__(38469);
// EXTERNAL MODULE: ./node_modules/zod/lib/index.mjs
var lib = __webpack_require__(52300);
// EXTERNAL MODULE: external "path"
var external_path_ = __webpack_require__(71017);
// EXTERNAL MODULE: external "fs/promises"
var promises_ = __webpack_require__(73292);
// EXTERNAL MODULE: ./dist/bin/tools/fs.existsAsync.js
var fs_existsAsync = __webpack_require__(43765);
// EXTERNAL MODULE: ./dist/bin/tools/listInstalledModules.js
var listInstalledModules = __webpack_require__(75564);
;// CONCATENATED MODULE: ./dist/bin/tools/crawlAsync.js
/** List all files in a given directory return paths relative to the dir_path */
async function crawlAsync(params) {
const { dirPath, returnedPathsType, onFileFound } = params;
await crawlAsyncRec({
dirPath,
onFileFound: async ({ filePath }) => {
switch (returnedPathsType) {
case "absolute":
await onFileFound(filePath);
return;
case "relative to dirPath":
await onFileFound((0,external_path_.relative)(dirPath, filePath));
return;
}
(0,assert/* assert */.h)();
}
});
}
async function crawlAsyncRec(params) {
const { dirPath, onFileFound } = params;
await Promise.all((await promises_.readdir(dirPath)).map(async (basename) => {
const fileOrDirPath = (0,external_path_.join)(dirPath, basename);
const isDirectory = await promises_.lstat(fileOrDirPath)
.then(stat => stat.isDirectory());
if (isDirectory) {
await crawlAsyncRec({ dirPath: fileOrDirPath, onFileFound });
return;
}
await onFileFound({ filePath: fileOrDirPath });
}));
}
//# sourceMappingURL=crawlAsync.js.map
// EXTERNAL MODULE: ./dist/bin/tools/runPrettier.js
var runPrettier = __webpack_require__(48433);
// EXTERNAL MODULE: ./dist/bin/tools/readThisNpmPackageVersion.js
var readThisNpmPackageVersion = __webpack_require__(64795);
// EXTERNAL MODULE: ./dist/bin/sync-extensions/getExtensionModuleFileSourceCodeReadyToBeCopied.js
var getExtensionModuleFileSourceCodeReadyToBeCopied = __webpack_require__(2237);
// EXTERNAL MODULE: external "crypto"
var external_crypto_ = __webpack_require__(6113);
// EXTERNAL MODULE: ./dist/bin/shared/constants.js
var constants = __webpack_require__(173);
// EXTERNAL MODULE: ./node_modules/tsafe/esm/exclude.mjs
var exclude = __webpack_require__(83101);
;// CONCATENATED MODULE: ./node_modules/tsafe/esm/isAmong.mjs
/** https://docs.tsafe.dev/isamong */
function isAmong(names, value) {
for (const name of names) {
if (name === value) {
return true;
}
}
return false;
}
//# sourceMappingURL=isAmong.mjs.map
;// CONCATENATED MODULE: ./dist/bin/sync-extensions/extensionModuleMeta.js
const zExtensionModuleMeta = (() => {
const zTargetType = lib.z.object({
moduleName: lib.z.string(),
version: lib.z.string(),
files: lib.z.array(lib.z.object({
isPublic: lib.z.boolean(),
fileRelativePath: lib.z.string(),
hash: lib.z.string(),
copyableFilePath: lib.z.string()
})),
peerDependencies: lib.z.record(lib.z.string())
});
(0,assert/* assert */.h)();
return (0,id.id)(zTargetType);
})();
const zParsedCacheFile = (() => {
const zTargetType = lib.z.object({
keycloakifyVersion: lib.z.string(),
prettierConfigHash: lib.z.union([lib.z.string(), lib.z["null"]()]),
thisFilePath: lib.z.string(),
extensionModuleMetas: lib.z.array(zExtensionModuleMeta)
});
(0,assert/* assert */.h)();
return (0,id.id)(zTargetType);
})();
const CACHE_FILE_RELATIVE_PATH = (0,external_path_.join)("extension-modules", "cache.json");
(0,assert/* assert */.h)();
async function getExtensionModuleMetas(params) {
const { buildContext } = params;
const cacheFilePath = (0,external_path_.join)(buildContext.cacheDirPath, CACHE_FILE_RELATIVE_PATH);
const keycloakifyVersion = (0,readThisNpmPackageVersion/* readThisNpmPackageVersion */.K)();
const prettierConfigHash = await (async () => {
if (!(await (0,runPrettier/* getIsPrettierAvailable */.MT)())) {
return null;
}
const { configHash } = await (0,runPrettier/* getPrettier */.LG)();
return configHash;
})();
const installedExtensionModules = await (async () => {
let installedExtensionModules = await (0,listInstalledModules/* listInstalledModules */.P)({
packageJsonFilePath: buildContext.packageJsonFilePath,
filter: ({ moduleName }) => moduleName.includes("keycloakify") && moduleName !== "keycloakify"
});
installedExtensionModules = (await Promise.all(installedExtensionModules.map(async (entry) => {
if (!(await (0,fs_existsAsync/* existsAsync */.o)((0,external_path_.join)(entry.dirPath, constants/* KEYCLOAK_THEME */.PC)))) {
return undefined;
}
return entry;
}))).filter((0,exclude/* exclude */.D)(undefined));
maybe_exclude_login_ui: {
const LOGIN_UI_MODULE_NAME = "@keycloakify/login-ui";
if (!installedExtensionModules
.map(({ moduleName }) => moduleName)
.includes(LOGIN_UI_MODULE_NAME)) {
break maybe_exclude_login_ui;
}
const shouldExcludeLoginUi = await (async () => {
for (const entry of installedExtensionModules) {
if (entry.moduleName === LOGIN_UI_MODULE_NAME ||
entry.moduleName === "@keycloakify/login-ui-storybook") {
continue;
}
if (await (0,fs_existsAsync/* existsAsync */.o)((0,external_path_.join)(entry.dirPath, constants/* KEYCLOAK_THEME */.PC, "login", "pages", "login"))) {
return true;
}
}
return false;
})();
if (!shouldExcludeLoginUi) {
break maybe_exclude_login_ui;
}
installedExtensionModules = installedExtensionModules.filter(({ moduleName }) => moduleName !== LOGIN_UI_MODULE_NAME);
}
return installedExtensionModules;
})();
const cacheContent = await (async () => {
if (!(await (0,fs_existsAsync/* existsAsync */.o)(cacheFilePath))) {
return undefined;
}
return await promises_.readFile(cacheFilePath);
})();
const extensionModuleMetas_cacheUpToDate = await (async () => {
const parsedCacheFile = await (async () => {
if (cacheContent === undefined) {
return undefined;
}
const cacheContentStr = cacheContent.toString("utf8");
let parsedCacheFile;
try {
parsedCacheFile = JSON.parse(cacheContentStr);
}
catch (_a) {
return undefined;
}
try {
zParsedCacheFile.parse(parsedCacheFile);
}
catch (_b) {
return undefined;
}
(0,assert/* assert */.h)((0,assert.is)(parsedCacheFile));
return parsedCacheFile;
})();
if (parsedCacheFile === undefined) {
return [];
}
if (parsedCacheFile.keycloakifyVersion !== keycloakifyVersion) {
return [];
}
if (parsedCacheFile.prettierConfigHash !== prettierConfigHash) {
return [];
}
if (parsedCacheFile.thisFilePath !== cacheFilePath) {
return [];
}
const extensionModuleMetas_cacheUpToDate = parsedCacheFile.extensionModuleMetas.filter(extensionModuleMeta => {
const correspondingInstalledExtensionModule = installedExtensionModules.find(installedExtensionModule => installedExtensionModule.moduleName ===
extensionModuleMeta.moduleName);
if (correspondingInstalledExtensionModule === undefined) {
return false;
}
return (correspondingInstalledExtensionModule.version ===
extensionModuleMeta.version);
});
return extensionModuleMetas_cacheUpToDate;
})();
const extensionModuleMetas = await Promise.all([...installedExtensionModules]
.sort((a, b) => a.moduleName.localeCompare(b.moduleName))
.map(async ({ moduleName, version, peerDependencies, dirPath }) => {
use_cache: {
const extensionModuleMeta_cache = extensionModuleMetas_cacheUpToDate.find(extensionModuleMeta => extensionModuleMeta.moduleName === moduleName);
if (extensionModuleMeta_cache === undefined) {
break use_cache;
}
return extensionModuleMeta_cache;
}
const files = [];
await crawlAsync({
dirPath: (0,external_path_.join)(dirPath, constants/* KEYCLOAK_THEME */.PC),
returnedPathsType: "relative to dirPath",
onFileFound: async (fileRelativePath_fromReservedDir) => {
const isPublic = fileRelativePath_fromReservedDir.startsWith(`public${external_path_.sep}`);
const fileRelativePath = isPublic
? (0,external_path_.relative)("public", fileRelativePath_fromReservedDir)
: fileRelativePath_fromReservedDir;
const sourceCode = await (0,getExtensionModuleFileSourceCodeReadyToBeCopied/* getExtensionModuleFileSourceCodeReadyToBeCopied */.p)({
buildContext,
isPublic,
fileRelativePath,
isOwnershipAction: false,
extensionModuleDirPath: dirPath,
extensionModuleName: moduleName,
extensionModuleVersion: version
});
const hash = computeHash(sourceCode);
const copyableFilePath = (0,external_path_.join)((0,external_path_.dirname)(cacheFilePath), constants/* KEYCLOAK_THEME */.PC, fileRelativePath_fromReservedDir);
{
const dirPath = (0,external_path_.dirname)(copyableFilePath);
if (!(await (0,fs_existsAsync/* existsAsync */.o)(dirPath))) {
await promises_.mkdir(dirPath, { recursive: true });
}
}
await promises_.writeFile(copyableFilePath, sourceCode);
files.push({
isPublic,
fileRelativePath,
hash,
copyableFilePath
});
}
});
{
const getId = (file) => `${file.isPublic ? "public" : "src"} - ${file.fileRelativePath}`;
files.sort((a, b) => getId(a).localeCompare(getId(b)));
}
return (0,id.id)({
moduleName,
version,
files,
peerDependencies: Object.fromEntries(Object.entries(peerDependencies)
.filter(([moduleName]) => !isAmong(["react", "@types/react"], moduleName))
.sort(([moduleName_a], [moduleName_b]) => moduleName_a.localeCompare(moduleName_b)))
});
}));
update_cache: {
const parsedCacheFile = (0,id.id)({
keycloakifyVersion,
prettierConfigHash,
thisFilePath: cacheFilePath,
extensionModuleMetas
});
const cacheContent_new = Buffer.from(JSON.stringify(parsedCacheFile, null, 2), "utf8");
if (cacheContent !== undefined && cacheContent_new.equals(cacheContent)) {
break update_cache;
}
create_dir: {
const dirPath = (0,external_path_.dirname)(cacheFilePath);
if (await (0,fs_existsAsync/* existsAsync */.o)(dirPath)) {
break create_dir;
}
await promises_.mkdir(dirPath, { recursive: true });
}
await promises_.writeFile(cacheFilePath, cacheContent_new);
}
return extensionModuleMetas;
}
function computeHash(data) {
return external_crypto_.createHash("sha256").update(data).digest("hex");
}
//# sourceMappingURL=extensionModuleMeta.js.map
/***/ }),
/***/ 2237:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "p": () => (/* binding */ getExtensionModuleFileSourceCodeReadyToBeCopied)
/* harmony export */ });
/* harmony import */ var _tools_runPrettier__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(48433);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(73292);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(71017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(29041);
/* harmony import */ var _shared_constants__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(173);
(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .h)();
async function getExtensionModuleFileSourceCodeReadyToBeCopied(params) {
const { buildContext, extensionModuleDirPath, isPublic, fileRelativePath, isOwnershipAction, extensionModuleName, extensionModuleVersion } = params;
const { refSourceCode } = await (async () => {
let sourceCode = undefined;
const sourceCode_originalBuffer = await fs_promises__WEBPACK_IMPORTED_MODULE_1__.readFile((0,path__WEBPACK_IMPORTED_MODULE_2__.join)(extensionModuleDirPath, _shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .KEYCLOAK_THEME */ .PC, isPublic ? "public" : ".", fileRelativePath));
let hasBeenUpdated = false;
const refSourceCode = {
get current() {
if (sourceCode === undefined) {
sourceCode = sourceCode_originalBuffer.toString("utf8");
}
return sourceCode;
},
set current(value) {
hasBeenUpdated = true;
sourceCode = value;
},
getAsBuffer: () => {
if (!hasBeenUpdated) {
return sourceCode_originalBuffer;
}
return Buffer.from(refSourceCode.current, "utf8");
}
};
return { refSourceCode };
})();
add_eslint_disable: {
if (isOwnershipAction) {
break add_eslint_disable;
}
if (!fileRelativePath.endsWith(".ts") && !fileRelativePath.endsWith(".tsx")) {
break add_eslint_disable;
}
if (refSourceCode.current.includes("/* eslint-disable */")) {
break add_eslint_disable;
}
refSourceCode.current = ["/* eslint-disable */", "", refSourceCode.current].join("\n");
}
addCommentToSourceCode({
refSourceCode,
fileRelativePath,
commentLines: (() => {
const path = fileRelativePath.split(path__WEBPACK_IMPORTED_MODULE_2__.sep).join("/");
const isEarlyColorSchemeScript = isPublic &&
_shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .THEME_TYPES.find */ .Jh.find(themeType => (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(themeType, _shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .EARLY_COLOR_SCHEME_SCRIPT_BASENAME */ .PH) ===
fileRelativePath) !== undefined;
const common = !isEarlyColorSchemeScript
? []
: [
``,
`${_shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .EARLY_COLOR_SCHEME_SCRIPT_BASENAME */ .PH} is a special file that will be imported in the head automatically by Keycloakify.`,
`Note that this file is not loaded in Storybook or when using the Vite DEV server.`,
"To test it you can use `NO_DEV_SERVER=true npx keycloakify start-keycloak` (NO_DEV_SERVER is only relevant for Account SPA and Admin themes)"
];
return isOwnershipAction
? [
`This file has been claimed for ownership from ${extensionModuleName} version ${extensionModuleVersion}.`,
`To relinquish ownership and restore this file to its original content, run the following command:`,
``,
`$ npx keycloakify own --path "${path}" ${isPublic ? "--public " : ""}--revert`,
...common
]
: [
`WARNING: Before modifying this file, run the following command:`,
``,
`$ npx keycloakify own --path "${path}"${isPublic ? " --public" : ""}`,
``,
`This file is provided by ${extensionModuleName} version ${extensionModuleVersion}.`,
`It was copied into your repository by the postinstall script: \`keycloakify sync-extensions\`.`,
...common
];
})()
});
format: {
if (!(await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_0__/* .getIsPrettierAvailable */ .MT)())) {
break format;
}
const sourceCode_buffer_before = refSourceCode.getAsBuffer();
const sourceCode_buffer_after = await (0,_tools_runPrettier__WEBPACK_IMPORTED_MODULE_0__/* .runPrettier */ .eY)({
filePath: (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(isPublic
? (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(buildContext.publicDirPath, _shared_constants__WEBPACK_IMPORTED_MODULE_4__/* .KEYCLOAK_THEME */ .PC)
: buildContext.themeSrcDirPath, fileRelativePath),
sourceCode: sourceCode_buffer_before
});
if (sourceCode_buffer_before.compare(sourceCode_buffer_after) === 0) {
break format;
}
refSourceCode.current = sourceCode_buffer_after.toString("utf8");
}
return refSourceCode.getAsBuffer();
}
function addCommentToSourceCode(params) {
const { refSourceCode, fileRelativePath, commentLines } = params;
const updateRef = (comment) => {
refSourceCode.current = [comment, ``, refSourceCode.current].join("\n");
};
for (const ext of [".ts", ".tsx", ".css", ".less", ".sass", ".js", ".jsx"]) {
if (!fileRelativePath.endsWith(ext)) {
continue;
}
updateRef([`/**`, ...commentLines.map(line => ` * ${line}`), ` */`].join("\n"));
return;
}
if (fileRelativePath.endsWith(".properties")) {
updateRef(commentLines.map(line => `# ${line}`).join("\n"));
return;
}
if (fileRelativePath.endsWith(".ftl")) {
const comment = [`<#--`, ...commentLines.map(line => ` ${line}`), `-->`].join("\n");
if (refSourceCode.current.trim().startsWith("<#ftl")) {
const [first, ...rest] = refSourceCode.current.split(">");
const last = rest.join(">");
refSourceCode.current = [`${first}>`, comment, last].join("\n");
return;
}
updateRef(comment);
return;
}
if (fileRelativePath.endsWith(".html") || fileRelativePath.endsWith(".svg")) {
const comment = [
`<!--`,
...commentLines.map(line => ` ${line
.replace("--path", "-t")
.replace("--revert", "-r")
.replace("Before modifying", "Before modifying or replacing")}`),
`-->`
].join("\n");
if (fileRelativePath.endsWith(".html") &&
refSourceCode.current.trim().startsWith("<!")) {
const [first, ...rest] = refSourceCode.current.split(">");
const last = rest.join(">");
refSourceCode.current = [`${first}>`, comment, last].join("\n");
return;
}
if (fileRelativePath.endsWith(".svg") &&
refSourceCode.current.trim().startsWith("<?")) {
const [first, ...rest] = refSourceCode.current.split("?>");
const last = rest.join("?>");
refSourceCode.current = [`${first}?>`, comment, last].join("\n");
return;
}
updateRef(comment);
return;
}
}
//# sourceMappingURL=getExtensionModuleFileSourceCodeReadyToBeCopied.js.map
/***/ }),
/***/ 75564:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "J": () => (/* binding */ readPackageJsonDependencies),
/* harmony export */ "P": () => (/* binding */ listInstalledModules)
/* harmony export */ });
/* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(29041);
/* harmony import */ var tsafe_id__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(38469);
/* harmony import */ var zod__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(52300);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(71017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(73292);
/* harmony import */ var fs_promises__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs_promises__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _tools_getInstalledModuleDirPath__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(93721);
/* harmony import */ var tsafe_exclude__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(83101);
async function listInstalledModules(params) {
const { packageJsonFilePath, filter } = params;
const parsedPackageJson = await readPackageJsonDependencies({
packageJsonFilePath
});
const extensionModuleNames = [parsedPackageJson.dependencies, parsedPackageJson.devDependencies]
.filter((0,tsafe_exclude__WEBPACK_IMPORTED_MODULE_4__/* .exclude */ .D)(undefined))
.map(obj => Object.keys(obj))
.flat()
.filter(moduleName => filter({ moduleName }));
const result = await Promise.all(extensionModuleNames.map(async (moduleName) => {
const dirPath = await (0,_tools_getInstalledModuleDirPath__WEBPACK_IMPORTED_MODULE_3__/* .getInstalledModuleDirPath */ .p)({
moduleName,
packageJsonDirPath: (0,path__WEBPACK_IMPORTED_MODULE_1__.dirname)(packageJsonFilePath)
});
const { version, peerDependencies } = await readPackageJsonVersionAndPeerDependencies({
packageJsonFilePath: (0,path__WEBPACK_IMPORTED_MODULE_1__.join)(dirPath, "package.json")
});
return { moduleName, version, peerDependencies, dirPath };
}));
return result;
}
const { readPackageJsonDependencies } = (() => {
const zParsedPackageJson = (() => {
const zTargetType = zod__WEBPACK_IMPORTED_MODULE_5__.z.object({
dependencies: zod__WEBPACK_IMPORTED_MODULE_5__.z.record(zod__WEBPACK_IMPORTED_MODULE_5__.z.string()).optional(),
devDependencies: zod__WEBPACK_IMPORTED_MODULE_5__.z.record(zod__WEBPACK_IMPORTED_MODULE_5__.z.string()).optional()
});
(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .h)();
return (0,tsafe_id__WEBPACK_IMPORTED_MODULE_6__.id)(zTargetType);
})();
async function readPackageJsonDependencies(params) {
const { packageJsonFilePath } = params;
const parsedPackageJson = JSON.parse((await fs_promises__WEBPACK_IMPORTED_MODULE_2__.readFile(packageJsonFilePath)).toString("utf8"));
zParsedPackageJson.parse(parsedPackageJson);
(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .h)((0,tsafe_assert__WEBPACK_IMPORTED_MODULE_0__.is)(parsedPackageJson));
return parsedPackageJson;
}
return { readPackageJsonDependencies };
})();
const { readPackageJsonVersionAndPeerDependencies } = (() => {
const zParsedPackageJson = (() => {
const zTargetType = zod__WEBPACK_IMPORTED_MODULE_5__.z.object({
version: zod__WEBPACK_IMPORTED_MODULE_5__.z.string(),
peerDependencies: zod__WEBPACK_IMPORTED_MODULE_5__.z.record(zod__WEBPACK_IMPORTED_MODULE_5__.z.string()).optional()
});
(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .h)();
return (0,tsafe_id__WEBPACK_IMPORTED_MODULE_6__.id)(zTargetType);
})();
async function readPackageJsonVersionAndPeerDependencies(params) {
var _a;
const { packageJsonFilePath } = params;
const parsedPackageJson = JSON.parse((await fs_promises__WEBPACK_IMPORTED_MODULE_2__.readFile(packageJsonFilePath)).toString("utf8"));
zParsedPackageJson.parse(parsedPackageJson);
(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_0__/* .assert */ .h)((0,tsafe_assert__WEBPACK_IMPORTED_MODULE_0__.is)(parsedPackageJson));
return {
version: parsedPackageJson.version,
peerDependencies: (_a = parsedPackageJson.peerDependencies) !== null && _a !== void 0 ? _a : {}
};
}
return { readPackageJsonVersionAndPeerDependencies };
})();
//# sourceMappingURL=listInstalledModules.js.map
/***/ })
};
;