keycloakify 10.0.0-rc.73 → 10.0.0-rc.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/{363.index.js → 440.index.js} +24 -74
- package/bin/main.js +1 -1
- package/package.json +2 -3
- package/src/bin/keycloakify/generateFtl/generateFtl.ts +3 -20
- package/src/bin/keycloakify/generateResources/generateResourcesForMainTheme.ts +11 -16
- package/src/bin/keycloakify/replacers/replaceImportsInCssCode.ts +30 -62
- package/src/bin/keycloakify/replacers/replaceImportsInInlineCssCode.ts +0 -28
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
|
-
exports.id =
|
3
|
-
exports.ids = [
|
2
|
+
exports.id = 440;
|
3
|
+
exports.ids = [440];
|
4
4
|
exports.modules = {
|
5
5
|
|
6
6
|
/***/ 73817:
|
@@ -155,7 +155,7 @@ function generateMessageProperties(params) {
|
|
155
155
|
|
156
156
|
/***/ }),
|
157
157
|
|
158
|
-
/***/
|
158
|
+
/***/ 46440:
|
159
159
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
160
160
|
|
161
161
|
// ESM COMPAT FLAG
|
@@ -348,63 +348,28 @@ const { readAssetsDirSync } = (() => {
|
|
348
348
|
;// CONCATENATED MODULE: ./dist/bin/keycloakify/replacers/replaceImportsInJsCode/index.js
|
349
349
|
|
350
350
|
//# sourceMappingURL=index.js.map
|
351
|
-
// EXTERNAL MODULE: external "crypto"
|
352
|
-
var external_crypto_ = __webpack_require__(6113);
|
353
351
|
;// CONCATENATED MODULE: ./dist/bin/keycloakify/replacers/replaceImportsInCssCode.js
|
354
352
|
|
355
353
|
|
356
|
-
|
357
354
|
(0,assert.assert)();
|
358
355
|
function replaceImportsInCssCode(params) {
|
359
|
-
|
360
|
-
const
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
.
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
.join(`var(--${cssVariableName})`)));
|
373
|
-
return { fixedCssCode, cssGlobalsToDefine };
|
374
|
-
}
|
375
|
-
function generateCssCodeToDefineGlobals(params) {
|
376
|
-
const { cssGlobalsToDefine, buildContext } = params;
|
377
|
-
return {
|
378
|
-
cssCodeToPrependInHead: [
|
379
|
-
":root {",
|
380
|
-
...Object.keys(cssGlobalsToDefine)
|
381
|
-
.map(cssVariableName => {
|
382
|
-
var _a;
|
383
|
-
return [
|
384
|
-
`--${cssVariableName}:`,
|
385
|
-
cssGlobalsToDefine[cssVariableName].replace(new RegExp(`url\\(${((_a = buildContext.urlPathname) !== null && _a !== void 0 ? _a : "/").replace(/\//g, "\\/")}`, "g"), `url(\${url.resourcesPath}/${constants/* basenameOfTheKeycloakifyResourcesDir */.M}/`)
|
386
|
-
].join(" ");
|
387
|
-
})
|
388
|
-
.map(line => ` ${line};`),
|
389
|
-
"}"
|
390
|
-
].join("\n")
|
391
|
-
};
|
356
|
+
const { cssCode, fileRelativeDirPath, buildContext } = params;
|
357
|
+
const fixedCssCode = cssCode.replace(/url\(["']?(\/[^/][^)"']+)["']?\)/g, (match, assetFileAbsoluteUrlPathname) => {
|
358
|
+
if (buildContext.urlPathname !== undefined) {
|
359
|
+
if (!assetFileAbsoluteUrlPathname.startsWith(buildContext.urlPathname)) {
|
360
|
+
// NOTE: Should never happen
|
361
|
+
return match;
|
362
|
+
}
|
363
|
+
assetFileAbsoluteUrlPathname = assetFileAbsoluteUrlPathname.replace(buildContext.urlPathname, "/");
|
364
|
+
}
|
365
|
+
const assetFileRelativeUrlPathname = external_path_.posix.relative(fileRelativeDirPath.replace(/\\/g, "/"), assetFileAbsoluteUrlPathname.replace(/^\//, ""));
|
366
|
+
return `url(${assetFileRelativeUrlPathname})`;
|
367
|
+
});
|
368
|
+
return { fixedCssCode };
|
392
369
|
}
|
393
370
|
//# sourceMappingURL=replaceImportsInCssCode.js.map
|
394
371
|
// EXTERNAL MODULE: ./node_modules/cheerio/lib/esm/index.js + 76 modules
|
395
372
|
var esm = __webpack_require__(87182);
|
396
|
-
;// CONCATENATED MODULE: ./dist/bin/keycloakify/replacers/replaceImportsInInlineCssCode.js
|
397
|
-
|
398
|
-
|
399
|
-
(0,assert.assert)();
|
400
|
-
function replaceImportsInInlineCssCode(params) {
|
401
|
-
const { cssCode, buildContext } = params;
|
402
|
-
const fixedCssCode = cssCode.replace(buildContext.urlPathname === undefined
|
403
|
-
? /url\(["']?\/([^/][^)"']+)["']?\)/g
|
404
|
-
: new RegExp(`url\\(["']?${buildContext.urlPathname}([^)"']+)["']?\\)`, "g"), (...[, group]) => `url(\${url.resourcesPath}/${constants/* basenameOfTheKeycloakifyResourcesDir */.M}/${group})`);
|
405
|
-
return { fixedCssCode };
|
406
|
-
}
|
407
|
-
//# sourceMappingURL=replaceImportsInInlineCssCode.js.map
|
408
373
|
// EXTERNAL MODULE: ./dist/bin/tools/getThisCodebaseRootDirPath.js
|
409
374
|
var getThisCodebaseRootDirPath = __webpack_require__(58822);
|
410
375
|
;// CONCATENATED MODULE: ./dist/bin/keycloakify/generateFtl/generateFtl.js
|
@@ -416,11 +381,10 @@ var getThisCodebaseRootDirPath = __webpack_require__(58822);
|
|
416
381
|
|
417
382
|
|
418
383
|
|
419
|
-
|
420
384
|
(0,assert.assert)();
|
421
385
|
function generateFtlFilesCodeFactory(params) {
|
422
386
|
var _a;
|
423
|
-
const { themeName,
|
387
|
+
const { themeName, indexHtmlCode, buildContext, keycloakifyVersion, themeType, fieldNames } = params;
|
424
388
|
const $ = esm/* default.load */.ZP.load(indexHtmlCode);
|
425
389
|
fix_imports_statements: {
|
426
390
|
$("script:not([src])").each((...[, element]) => {
|
@@ -435,8 +399,9 @@ function generateFtlFilesCodeFactory(params) {
|
|
435
399
|
$("style").each((...[, element]) => {
|
436
400
|
const cssCode = $(element).html();
|
437
401
|
(0,assert.assert)(cssCode !== null);
|
438
|
-
const { fixedCssCode } =
|
402
|
+
const { fixedCssCode } = replaceImportsInCssCode({
|
439
403
|
cssCode,
|
404
|
+
fileRelativeDirPath: ".",
|
440
405
|
buildContext
|
441
406
|
});
|
442
407
|
$(element).text(fixedCssCode);
|
@@ -452,18 +417,6 @@ function generateFtlFilesCodeFactory(params) {
|
|
452
417
|
}
|
453
418
|
$(element).attr(attrName, href.replace(new RegExp(`^${((_a = buildContext.urlPathname) !== null && _a !== void 0 ? _a : "/").replace(/\//g, "\\/")}`), `\${url.resourcesPath}/${constants/* basenameOfTheKeycloakifyResourcesDir */.M}/`));
|
454
419
|
}));
|
455
|
-
if (Object.keys(cssGlobalsToDefine).length !== 0) {
|
456
|
-
$("head").prepend([
|
457
|
-
"",
|
458
|
-
"<style>",
|
459
|
-
generateCssCodeToDefineGlobals({
|
460
|
-
cssGlobalsToDefine,
|
461
|
-
buildContext
|
462
|
-
}).cssCodeToPrependInHead,
|
463
|
-
"</style>",
|
464
|
-
""
|
465
|
-
].join("\n"));
|
466
|
-
}
|
467
420
|
}
|
468
421
|
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
|
469
422
|
const kcContextDeclarationTemplateFtl = external_fs_.readFileSync((0,external_path_.join)((0,getThisCodebaseRootDirPath/* getThisCodebaseRootDirPath */.e)(), "src", "bin", "keycloakify", "generateFtl", "kcContextDeclarationTemplate.ftl"))
|
@@ -734,7 +687,6 @@ async function generateResourcesForMainTheme(params) {
|
|
734
687
|
const { themeType } = params;
|
735
688
|
return (0,external_path_.join)(resourcesDirPath, "theme", themeName, themeType);
|
736
689
|
};
|
737
|
-
const cssGlobalsToDefine = {};
|
738
690
|
for (const themeType of ["login", "account"]) {
|
739
691
|
if (!buildContext.recordIsImplementedByThemeType[themeType]) {
|
740
692
|
continue;
|
@@ -771,13 +723,12 @@ async function generateResourcesForMainTheme(params) {
|
|
771
723
|
(0,transformCodebase/* transformCodebase */.N)({
|
772
724
|
srcDirPath: buildContext.projectBuildDirPath,
|
773
725
|
destDirPath,
|
774
|
-
transformSourceCode: ({ filePath, sourceCode }) => {
|
726
|
+
transformSourceCode: ({ filePath, fileRelativePath, sourceCode }) => {
|
775
727
|
if (filePath.endsWith(".css")) {
|
776
|
-
const {
|
777
|
-
cssCode: sourceCode.toString("utf8")
|
778
|
-
|
779
|
-
|
780
|
-
cssGlobalsToDefine[key] = value;
|
728
|
+
const { fixedCssCode } = replaceImportsInCssCode({
|
729
|
+
cssCode: sourceCode.toString("utf8"),
|
730
|
+
fileRelativeDirPath: (0,external_path_.dirname)(fileRelativePath),
|
731
|
+
buildContext
|
781
732
|
});
|
782
733
|
return {
|
783
734
|
modifiedSourceCode: Buffer.from(fixedCssCode, "utf8")
|
@@ -800,7 +751,6 @@ async function generateResourcesForMainTheme(params) {
|
|
800
751
|
themeName,
|
801
752
|
indexHtmlCode: external_fs_.readFileSync((0,external_path_.join)(buildContext.projectBuildDirPath, "index.html"))
|
802
753
|
.toString("utf8"),
|
803
|
-
cssGlobalsToDefine,
|
804
754
|
buildContext,
|
805
755
|
keycloakifyVersion: (0,readThisNpmPackageVersion/* readThisNpmPackageVersion */.K)(),
|
806
756
|
themeType,
|
package/bin/main.js
CHANGED
@@ -9213,7 +9213,7 @@ program
|
|
9213
9213
|
.task({
|
9214
9214
|
skip,
|
9215
9215
|
handler: async (cliCommandOptions) => {
|
9216
|
-
const { command } = await Promise.all(/* import() */[__nccwpck_require__.e(456), __nccwpck_require__.e(430), __nccwpck_require__.e(525), __nccwpck_require__.e(490), __nccwpck_require__.e(751), __nccwpck_require__.e(837), __nccwpck_require__.e(
|
9216
|
+
const { command } = await Promise.all(/* import() */[__nccwpck_require__.e(456), __nccwpck_require__.e(430), __nccwpck_require__.e(525), __nccwpck_require__.e(490), __nccwpck_require__.e(751), __nccwpck_require__.e(837), __nccwpck_require__.e(440)]).then(__nccwpck_require__.bind(__nccwpck_require__, 46440));
|
9217
9217
|
await command({ cliCommandOptions });
|
9218
9218
|
}
|
9219
9219
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "keycloakify",
|
3
|
-
"version": "10.0.0-rc.
|
3
|
+
"version": "10.0.0-rc.74",
|
4
4
|
"description": "Create Keycloak themes using React",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -478,7 +478,6 @@
|
|
478
478
|
"src/bin/keycloakify/index.ts",
|
479
479
|
"src/bin/keycloakify/keycloakify.ts",
|
480
480
|
"src/bin/keycloakify/replacers/replaceImportsInCssCode.ts",
|
481
|
-
"src/bin/keycloakify/replacers/replaceImportsInInlineCssCode.ts",
|
482
481
|
"src/bin/keycloakify/replacers/replaceImportsInJsCode/index.ts",
|
483
482
|
"src/bin/keycloakify/replacers/replaceImportsInJsCode/replaceImportsInJsCode.ts",
|
484
483
|
"src/bin/keycloakify/replacers/replaceImportsInJsCode/vite.ts",
|
@@ -771,9 +770,9 @@
|
|
771
770
|
"bin/193.index.js",
|
772
771
|
"bin/246.index.js",
|
773
772
|
"bin/36.index.js",
|
774
|
-
"bin/363.index.js",
|
775
773
|
"bin/420.index.js",
|
776
774
|
"bin/430.index.js",
|
775
|
+
"bin/440.index.js",
|
777
776
|
"bin/453.index.js",
|
778
777
|
"bin/456.index.js",
|
779
778
|
"bin/490.index.js",
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import cheerio from "cheerio";
|
2
2
|
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
3
|
-
import {
|
4
|
-
import { replaceImportsInInlineCssCode } from "../replacers/replaceImportsInInlineCssCode";
|
3
|
+
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
5
4
|
import * as fs from "fs";
|
6
5
|
import { join as pathJoin } from "path";
|
7
6
|
import type { BuildContext } from "../../shared/buildContext";
|
@@ -28,7 +27,6 @@ assert<BuildContext extends BuildContextLike ? true : false>();
|
|
28
27
|
export function generateFtlFilesCodeFactory(params: {
|
29
28
|
themeName: string;
|
30
29
|
indexHtmlCode: string;
|
31
|
-
cssGlobalsToDefine: Record<string, string>;
|
32
30
|
buildContext: BuildContextLike;
|
33
31
|
keycloakifyVersion: string;
|
34
32
|
themeType: ThemeType;
|
@@ -36,7 +34,6 @@ export function generateFtlFilesCodeFactory(params: {
|
|
36
34
|
}) {
|
37
35
|
const {
|
38
36
|
themeName,
|
39
|
-
cssGlobalsToDefine,
|
40
37
|
indexHtmlCode,
|
41
38
|
buildContext,
|
42
39
|
keycloakifyVersion,
|
@@ -65,8 +62,9 @@ export function generateFtlFilesCodeFactory(params: {
|
|
65
62
|
|
66
63
|
assert(cssCode !== null);
|
67
64
|
|
68
|
-
const { fixedCssCode } =
|
65
|
+
const { fixedCssCode } = replaceImportsInCssCode({
|
69
66
|
cssCode,
|
67
|
+
fileRelativeDirPath: ".",
|
70
68
|
buildContext
|
71
69
|
});
|
72
70
|
|
@@ -97,21 +95,6 @@ export function generateFtlFilesCodeFactory(params: {
|
|
97
95
|
);
|
98
96
|
})
|
99
97
|
);
|
100
|
-
|
101
|
-
if (Object.keys(cssGlobalsToDefine).length !== 0) {
|
102
|
-
$("head").prepend(
|
103
|
-
[
|
104
|
-
"",
|
105
|
-
"<style>",
|
106
|
-
generateCssCodeToDefineGlobals({
|
107
|
-
cssGlobalsToDefine,
|
108
|
-
buildContext
|
109
|
-
}).cssCodeToPrependInHead,
|
110
|
-
"</style>",
|
111
|
-
""
|
112
|
-
].join("\n")
|
113
|
-
);
|
114
|
-
}
|
115
98
|
}
|
116
99
|
|
117
100
|
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import { transformCodebase } from "../../tools/transformCodebase";
|
2
2
|
import * as fs from "fs";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
join as pathJoin,
|
5
|
+
resolve as pathResolve,
|
6
|
+
relative as pathRelative,
|
7
|
+
dirname as pathDirname
|
8
|
+
} from "path";
|
4
9
|
import { replaceImportsInJsCode } from "../replacers/replaceImportsInJsCode";
|
5
10
|
import { replaceImportsInCssCode } from "../replacers/replaceImportsInCssCode";
|
6
11
|
import {
|
@@ -64,8 +69,6 @@ export async function generateResourcesForMainTheme(params: {
|
|
64
69
|
return pathJoin(resourcesDirPath, "theme", themeName, themeType);
|
65
70
|
};
|
66
71
|
|
67
|
-
const cssGlobalsToDefine: Record<string, string> = {};
|
68
|
-
|
69
72
|
for (const themeType of ["login", "account"] as const) {
|
70
73
|
if (!buildContext.recordIsImplementedByThemeType[themeType]) {
|
71
74
|
continue;
|
@@ -127,21 +130,14 @@ export async function generateResourcesForMainTheme(params: {
|
|
127
130
|
transformCodebase({
|
128
131
|
srcDirPath: buildContext.projectBuildDirPath,
|
129
132
|
destDirPath,
|
130
|
-
transformSourceCode: ({ filePath, sourceCode }) => {
|
133
|
+
transformSourceCode: ({ filePath, fileRelativePath, sourceCode }) => {
|
131
134
|
if (filePath.endsWith(".css")) {
|
132
|
-
const {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
cssCode: sourceCode.toString("utf8")
|
135
|
+
const { fixedCssCode } = replaceImportsInCssCode({
|
136
|
+
cssCode: sourceCode.toString("utf8"),
|
137
|
+
fileRelativeDirPath: pathDirname(fileRelativePath),
|
138
|
+
buildContext
|
137
139
|
});
|
138
140
|
|
139
|
-
Object.entries(cssGlobalsToDefineForThisFile).forEach(
|
140
|
-
([key, value]) => {
|
141
|
-
cssGlobalsToDefine[key] = value;
|
142
|
-
}
|
143
|
-
);
|
144
|
-
|
145
141
|
return {
|
146
142
|
modifiedSourceCode: Buffer.from(fixedCssCode, "utf8")
|
147
143
|
};
|
@@ -168,7 +164,6 @@ export async function generateResourcesForMainTheme(params: {
|
|
168
164
|
indexHtmlCode: fs
|
169
165
|
.readFileSync(pathJoin(buildContext.projectBuildDirPath, "index.html"))
|
170
166
|
.toString("utf8"),
|
171
|
-
cssGlobalsToDefine,
|
172
167
|
buildContext,
|
173
168
|
keycloakifyVersion: readThisNpmPackageVersion(),
|
174
169
|
themeType,
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import * as crypto from "crypto";
|
2
1
|
import type { BuildContext } from "../../shared/buildContext";
|
3
2
|
import { assert } from "tsafe/assert";
|
4
|
-
import {
|
3
|
+
import { posix } from "path";
|
5
4
|
|
6
5
|
export type BuildContextLike = {
|
7
6
|
urlPathname: string | undefined;
|
@@ -9,68 +8,37 @@ export type BuildContextLike = {
|
|
9
8
|
|
10
9
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
11
10
|
|
12
|
-
export function replaceImportsInCssCode(params: {
|
13
|
-
|
14
|
-
|
15
|
-
} {
|
16
|
-
const { cssCode } = params;
|
17
|
-
|
18
|
-
const cssGlobalsToDefine: Record<string, string> = {};
|
19
|
-
|
20
|
-
new Set(cssCode.match(/url\(["']?\/[^/][^)"']+["']?\)[^;}]*?/g) ?? []).forEach(
|
21
|
-
match =>
|
22
|
-
(cssGlobalsToDefine[
|
23
|
-
"url" +
|
24
|
-
crypto
|
25
|
-
.createHash("sha256")
|
26
|
-
.update(match)
|
27
|
-
.digest("hex")
|
28
|
-
.substring(0, 15)
|
29
|
-
] = match)
|
30
|
-
);
|
31
|
-
|
32
|
-
let fixedCssCode = cssCode;
|
33
|
-
|
34
|
-
Object.keys(cssGlobalsToDefine).forEach(
|
35
|
-
cssVariableName =>
|
36
|
-
//NOTE: split/join pattern ~ replace all
|
37
|
-
(fixedCssCode = fixedCssCode
|
38
|
-
.split(cssGlobalsToDefine[cssVariableName])
|
39
|
-
.join(`var(--${cssVariableName})`))
|
40
|
-
);
|
41
|
-
|
42
|
-
return { fixedCssCode, cssGlobalsToDefine };
|
43
|
-
}
|
44
|
-
|
45
|
-
export function generateCssCodeToDefineGlobals(params: {
|
46
|
-
cssGlobalsToDefine: Record<string, string>;
|
11
|
+
export function replaceImportsInCssCode(params: {
|
12
|
+
cssCode: string;
|
13
|
+
fileRelativeDirPath: string;
|
47
14
|
buildContext: BuildContextLike;
|
48
15
|
}): {
|
49
|
-
|
16
|
+
fixedCssCode: string;
|
50
17
|
} {
|
51
|
-
const {
|
18
|
+
const { cssCode, fileRelativeDirPath, buildContext } = params;
|
19
|
+
|
20
|
+
const fixedCssCode = cssCode.replace(
|
21
|
+
/url\(["']?(\/[^/][^)"']+)["']?\)/g,
|
22
|
+
(match, assetFileAbsoluteUrlPathname) => {
|
23
|
+
if (buildContext.urlPathname !== undefined) {
|
24
|
+
if (!assetFileAbsoluteUrlPathname.startsWith(buildContext.urlPathname)) {
|
25
|
+
// NOTE: Should never happen
|
26
|
+
return match;
|
27
|
+
}
|
28
|
+
assetFileAbsoluteUrlPathname = assetFileAbsoluteUrlPathname.replace(
|
29
|
+
buildContext.urlPathname,
|
30
|
+
"/"
|
31
|
+
);
|
32
|
+
}
|
33
|
+
|
34
|
+
const assetFileRelativeUrlPathname = posix.relative(
|
35
|
+
fileRelativeDirPath.replace(/\\/g, "/"),
|
36
|
+
assetFileAbsoluteUrlPathname.replace(/^\//, "")
|
37
|
+
);
|
38
|
+
|
39
|
+
return `url(${assetFileRelativeUrlPathname})`;
|
40
|
+
}
|
41
|
+
);
|
52
42
|
|
53
|
-
return {
|
54
|
-
cssCodeToPrependInHead: [
|
55
|
-
":root {",
|
56
|
-
...Object.keys(cssGlobalsToDefine)
|
57
|
-
.map(cssVariableName =>
|
58
|
-
[
|
59
|
-
`--${cssVariableName}:`,
|
60
|
-
cssGlobalsToDefine[cssVariableName].replace(
|
61
|
-
new RegExp(
|
62
|
-
`url\\(${(buildContext.urlPathname ?? "/").replace(
|
63
|
-
/\//g,
|
64
|
-
"\\/"
|
65
|
-
)}`,
|
66
|
-
"g"
|
67
|
-
),
|
68
|
-
`url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/`
|
69
|
-
)
|
70
|
-
].join(" ")
|
71
|
-
)
|
72
|
-
.map(line => ` ${line};`),
|
73
|
-
"}"
|
74
|
-
].join("\n")
|
75
|
-
};
|
43
|
+
return { fixedCssCode };
|
76
44
|
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import type { BuildContext } from "../../shared/buildContext";
|
2
|
-
import { assert } from "tsafe/assert";
|
3
|
-
import { basenameOfTheKeycloakifyResourcesDir } from "../../shared/constants";
|
4
|
-
|
5
|
-
export type BuildContextLike = {
|
6
|
-
urlPathname: string | undefined;
|
7
|
-
};
|
8
|
-
|
9
|
-
assert<BuildContext extends BuildContextLike ? true : false>();
|
10
|
-
|
11
|
-
export function replaceImportsInInlineCssCode(params: {
|
12
|
-
cssCode: string;
|
13
|
-
buildContext: BuildContextLike;
|
14
|
-
}): {
|
15
|
-
fixedCssCode: string;
|
16
|
-
} {
|
17
|
-
const { cssCode, buildContext } = params;
|
18
|
-
|
19
|
-
const fixedCssCode = cssCode.replace(
|
20
|
-
buildContext.urlPathname === undefined
|
21
|
-
? /url\(["']?\/([^/][^)"']+)["']?\)/g
|
22
|
-
: new RegExp(`url\\(["']?${buildContext.urlPathname}([^)"']+)["']?\\)`, "g"),
|
23
|
-
(...[, group]) =>
|
24
|
-
`url(\${url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}/${group})`
|
25
|
-
);
|
26
|
-
|
27
|
-
return { fixedCssCode };
|
28
|
-
}
|