diff --git a/.gitignore b/.gitignore
index 29db0a26..8e858076 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,5 +42,4 @@ jspm_packages
/dist
-/build
-/keycloak_build
+/etc_tmp/
diff --git a/package-lock.json b/package-lock.json
index 399e5d15..250d9f99 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14,7 +14,8 @@
"devDependencies": {
"@types/node": "^10.0.0",
"denoify": "^0.6.4",
- "evt": "^1.8.11",
+ "evt": "beta",
+ "scripting-tools": "^0.19.13",
"typescript": "^4.1.5"
}
},
diff --git a/package.json b/package.json
index 3bff727d..556138ed 100755
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
"@types/node": "^10.0.0",
"denoify": "^0.6.4",
"evt": "beta",
+ "scripting-tools": "^0.19.13",
"typescript": "^4.1.5"
},
"dependencies": {
diff --git a/res/index.html b/res/index.html
deleted file mode 100644
index 2b282bb1..00000000
--- a/res/index.html
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
- React App
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/static/css/main.8c8b27cf.chunk.css b/res/static/css/main.8c8b27cf.chunk.css
deleted file mode 100644
index e69de29b..00000000
diff --git a/res/static/js/2.0f3a6c43.chunk.js b/res/static/js/2.0f3a6c43.chunk.js
deleted file mode 100644
index 3ccbd6b6..00000000
--- a/res/static/js/2.0f3a6c43.chunk.js
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
- function f() {
- return a.p + "static/js/" + ({}[e] || e) + "." + {
- 3: "0664cdc0"
- }[e] + ".chunk.js"
- }
-
- function f() {
- return a.p + "static/js/" + ({}[e] || e) + "." + {
- 3: "0664cdc0"
- }[e] + ".chunk.js"
- }
\ No newline at end of file
diff --git a/res/static/js/2.0f3a6c43.chunk_another.js b/res/static/js/2.0f3a6c43.chunk_another.js
deleted file mode 100644
index 3ccbd6b6..00000000
--- a/res/static/js/2.0f3a6c43.chunk_another.js
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
- function f() {
- return a.p + "static/js/" + ({}[e] || e) + "." + {
- 3: "0664cdc0"
- }[e] + ".chunk.js"
- }
-
- function f() {
- return a.p + "static/js/" + ({}[e] || e) + "." + {
- 3: "0664cdc0"
- }[e] + ".chunk.js"
- }
\ No newline at end of file
diff --git a/src/bin/generateKeycloakThemeResources.ts b/src/bin/generateKeycloakThemeResources.ts
new file mode 100644
index 00000000..d68d4757
--- /dev/null
+++ b/src/bin/generateKeycloakThemeResources.ts
@@ -0,0 +1,97 @@
+
+import { transformCodebase } from "../tools/transformCodebase";
+import * as fs from "fs";
+import { join as pathJoin } from "path";
+import {
+ replaceImportFromStaticInCssCode,
+ replaceImportFromStaticInJsCode
+} from "./replaceImportFromStatic";
+import { generateFtlFilesCodeFactory } from "./generateFtl";
+
+
+/*
+const reactAppBuildDirPath = pathJoin(process.cwd(), "build");
+
+assert(
+ fs.existsSync(reactAppBuildDirPath),
+ "Run 'react-script build' first (the build dir should be present)"
+);
+
+const keycloakDir = pathJoin(reactAppBuildDirPath, "..", "keycloak_build");
+
+
+*/
+
+const ftlValuesGlobalName = "keycloakFtlValues";
+
+export function generateKeycloakThemeResources(
+ params: {
+ themeName: string;
+ reactAppBuildDirPath: string;
+ keycloakThemeBuildingDirPath: string;
+ }
+) {
+
+ const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath } = params;
+
+ const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
+
+ let allCssGlobalsToDefine: Record = {};
+
+ transformCodebase({
+ "destDirPath": pathJoin(themeDirPath, "resources"),
+ "srcDirPath": reactAppBuildDirPath,
+ "transformSourceCodeString": ({ filePath, sourceCode }) => {
+
+ if (/\.css?$/i.test(filePath)) {
+
+ const { cssGlobalsToDefine, fixedCssCode } = replaceImportFromStaticInCssCode(
+ { "cssCode": sourceCode.toString("utf8") }
+ );
+
+ allCssGlobalsToDefine = {
+ ...allCssGlobalsToDefine,
+ ...cssGlobalsToDefine
+ };
+
+ return { "modifiedSourceCode": Buffer.from(fixedCssCode, "utf8") };
+
+ }
+
+ if (/\.js?$/i.test(filePath)) {
+
+ const { fixedJsCode } = replaceImportFromStaticInJsCode({
+ "jsCode": sourceCode.toString("utf8"),
+ ftlValuesGlobalName
+ });
+
+ return { "modifiedSourceCode": Buffer.from(fixedJsCode, "utf8") };
+
+ }
+
+ return { "modifiedSourceCode": sourceCode };
+
+ }
+ });
+
+ const { generateFtlFilesCode } = generateFtlFilesCodeFactory({
+ "cssGlobalsToDefine": allCssGlobalsToDefine,
+ ftlValuesGlobalName,
+ "indexHtmlCode": fs.readFileSync(
+ pathJoin(reactAppBuildDirPath, "index.html")
+ ).toString("utf8")
+ });
+
+ (["login.ftl", "register.ftl"] as const).forEach(pageBasename => {
+
+ const { ftlCode } = generateFtlFilesCode({ pageBasename });
+
+ fs.writeFileSync(
+ pathJoin(themeDirPath, pageBasename),
+ Buffer.from(ftlCode, "utf8")
+ )
+
+ });
+
+}
+
diff --git a/src/bin/main.ts b/src/bin/main.ts
deleted file mode 100644
index e322b497..00000000
--- a/src/bin/main.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-
-import { transformCodebase } from "../tools/transformCodebase";
-import * as fs from "fs";
-import { join as pathJoin } from "path";
-import { assert } from "evt/tools/typeSafety/assert";
-import {
- replaceImportFromStaticInCssCode,
- replaceImportFromStaticInJsCode
-} from "./replaceImportFromStatic";
-import { generateFtlFilesCodeFactory } from "./generateFtl";
-
-
-const reactAppBuildDirPath = pathJoin(process.cwd(), "build");
-
-assert(
- fs.existsSync(reactAppBuildDirPath),
- "Run 'react-script build' first (the build dir should be present)"
-);
-
-const keycloakDir = pathJoin(reactAppBuildDirPath, "..", "keycloak_build");
-
-let allCssGlobalsToDefine: Record = {};
-
-const ftlValuesGlobalName = "keycloakFtlValues";
-
-
-transformCodebase({
- "destDirPath": pathJoin(keycloakDir, "login", "resources"),
- "srcDirPath": reactAppBuildDirPath,
- "transformSourceCodeString": ({ filePath, sourceCode }) => {
-
- if (/\.css?$/i.test(filePath)) {
-
- const { cssGlobalsToDefine, fixedCssCode } = replaceImportFromStaticInCssCode(
- { "cssCode": sourceCode.toString("utf8") }
- );
-
- allCssGlobalsToDefine = {
- ...allCssGlobalsToDefine,
- ...cssGlobalsToDefine
- };
-
- return { "modifiedSourceCode": Buffer.from(fixedCssCode, "utf8") };
-
- }
-
- if (/\.js?$/i.test(filePath)) {
-
- const { fixedJsCode } = replaceImportFromStaticInJsCode({
- "jsCode": sourceCode.toString("utf8"),
- ftlValuesGlobalName
- });
-
- return { "modifiedSourceCode": Buffer.from(fixedJsCode, "utf8") };
-
- }
-
- return { "modifiedSourceCode": sourceCode };
-
- }
-});
-
-const { generateFtlFilesCode } = generateFtlFilesCodeFactory({
- "cssGlobalsToDefine": allCssGlobalsToDefine,
- ftlValuesGlobalName,
- "indexHtmlCode": fs.readFileSync(
- pathJoin(reactAppBuildDirPath, "index.html")
- ).toString("utf8")
-});
-
-(["login.ftl", "register.ftl"] as const).forEach(pageBasename => {
-
- const { ftlCode } = generateFtlFilesCode({ pageBasename });
-
- fs.writeFileSync(
- pathJoin(keycloakDir, "login", pageBasename),
- Buffer.from(ftlCode, "utf8")
- )
-
-});
diff --git a/src/test/generateKeycloakThemeResources.ts b/src/test/generateKeycloakThemeResources.ts
new file mode 100644
index 00000000..cb819daf
--- /dev/null
+++ b/src/test/generateKeycloakThemeResources.ts
@@ -0,0 +1,24 @@
+
+import * as st from "scripting-tools";
+import { join as pathJoin } from "path";
+import { generateKeycloakThemeResources } from "../bin/generateKeycloakThemeResources";
+
+const cwd= pathJoin(__dirname, "..", "..", "etc_tmp");
+
+st.execSync(`rm -rf ${cwd}`);
+st.execSync(`mkdir ${cwd}`);
+
+process.chdir(cwd);
+
+st.execSync("wget https://github.com/garronej/keycloak-react-theming/releases/download/v0.0.1/build.zip");
+
+st.execSync("unzip build.zip");
+
+st.execSync("rm build.zip");
+
+generateKeycloakThemeResources({
+ "themeName": "onyxia-ui",
+ "reactAppBuildDirPath": pathJoin(process.cwd(), "build"),
+ "keycloakThemeBuildingDirPath": pathJoin(process.cwd(), "keycloak_build")
+});
+