diff --git a/README.md b/README.md index 99ba3eef..ec5508c8 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,26 @@ - Documentation

+ +# REQUIREMENT +## For building the theme: + +- `mvn` must be installed + +## For development, (testing the theme on a docker container ect ): + +- `rm` +- `mkdir` ) +- `wget` +- `unzip` + +Tested on MacOS + +# USAGE + +## Build the theme: +`npx build-keycloak-theme` + +## (Optional/Debug) Download more themes: + +`npx download-sample-keycloak-themes` diff --git a/package.json b/package.json index bfcc4fa2..7cfb9a30 100755 --- a/package.json +++ b/package.json @@ -10,12 +10,13 @@ "types": "dist/lib/index.d.ts", "scripts": { "build": "tsc && npm run grant-exec-perms", - "grant-exec-perms": "chmod +x dist/bin/build-keycloak-theme/index.js", - "test": "node dist/test/build-keycloak-theme.js", + "grant-exec-perms": "chmod +x dist/bin/{build-keycloak-theme/index,download-sample-keycloak-themes}.js", + "test": "node dist/test/build-keycloak-theme && node dist/test/download-sample-keycloak-themes", "enable_short_import_path": "npm run build && denoify_enable_short_npm_import_path" }, "bin": { - "build-keycloak-theme": "dist/bin/build-keycloak-theme" + "build-keycloak-theme": "dist/bin/build-keycloak-theme", + "download-sample-keycloak-themes": "dist/bin/download-sample-keycloak-themes" }, "author": "u/garronej", "license": "MIT", @@ -42,4 +43,4 @@ "dependencies": { "cheerio": "^1.0.0-rc.5" } -} +} \ No newline at end of file diff --git a/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts b/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts index 55da237c..d2b053b8 100644 --- a/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts +++ b/src/bin/build-keycloak-theme/generateKeycloakThemeResources.ts @@ -8,20 +8,6 @@ import { } 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( diff --git a/src/bin/build-keycloak-theme/index.ts b/src/bin/build-keycloak-theme/index.ts index 3fa01005..6d911aa1 100644 --- a/src/bin/build-keycloak-theme/index.ts +++ b/src/bin/build-keycloak-theme/index.ts @@ -3,31 +3,35 @@ import { generateJavaStackFiles } from "./generateJavaStackFiles"; import type { ParsedPackageJson } from "./generateJavaStackFiles"; import { join as pathJoin } from "path"; import * as child_process from "child_process"; -import { generateDebugFiles } from "./generateDebugFiles"; +import { generateDebugFiles } from "./generateDebugFiles"; const reactProjectDirPath = process.cwd(); const parsedPackageJson: ParsedPackageJson = require(pathJoin(reactProjectDirPath, "package.json")); -const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak"); +export const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak"); -generateKeycloakThemeResources({ - keycloakThemeBuildingDirPath, - "reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"), - "themeName": parsedPackageJson.name -}); +if (require.main === module) { -generateJavaStackFiles({ - parsedPackageJson, - keycloakThemeBuildingDirPath -}); + generateKeycloakThemeResources({ + keycloakThemeBuildingDirPath, + "reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"), + "themeName": parsedPackageJson.name + }); -child_process.execSync( - "mvn package", - { "cwd": keycloakThemeBuildingDirPath } -); + generateJavaStackFiles({ + parsedPackageJson, + keycloakThemeBuildingDirPath + }); -generateDebugFiles({ - keycloakThemeBuildingDirPath, - "packageJsonName": parsedPackageJson.name -}); + child_process.execSync( + "mvn package", + { "cwd": keycloakThemeBuildingDirPath } + ); + + generateDebugFiles({ + keycloakThemeBuildingDirPath, + "packageJsonName": parsedPackageJson.name + }); + +} diff --git a/src/bin/download-sample-keycloak-themes.ts b/src/bin/download-sample-keycloak-themes.ts new file mode 100644 index 00000000..e124ac1a --- /dev/null +++ b/src/bin/download-sample-keycloak-themes.ts @@ -0,0 +1,17 @@ + +import * as fs from "fs"; +import { join as pathJoin, basename as pathBasename } from "path"; +import { keycloakThemeBuildingDirPath } from "./build-keycloak-theme"; +import child_process from "child_process"; + +if (!fs.existsSync(keycloakThemeBuildingDirPath)) { + console.log("Error: The keycloak theme need to be build"); + process.exit(1); +} + +const url = "https://github.com/garronej/keycloak-react-theming/releases/download/v0.0.1/other_keycloak_thems.zip"; + +[ + `wget ${url}`, + ...["unzip", "rm"].map(prg => `${prg} ${pathBasename(url)}`), +].forEach(cmd => child_process.execSync(cmd, { "cwd": pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme") })); diff --git a/src/test/build-keycloak-theme.ts b/src/test/build-keycloak-theme.ts index 78981e7f..7f36ae67 100644 --- a/src/test/build-keycloak-theme.ts +++ b/src/test/build-keycloak-theme.ts @@ -1,11 +1,15 @@ import { setupSampleReactProject } from "./setupSampleReactProject"; +import * as st from "scripting-tools"; +import { join as pathJoin } from "path"; const { sampleReactProjectDirPath } = setupSampleReactProject(); -process.chdir(sampleReactProjectDirPath); - console.log(`Running main in ${sampleReactProjectDirPath}`); -import("../bin/build-keycloak-theme"); +st.execSync( + `node ${pathJoin(__dirname, "../bin/build-keycloak-theme")}`, + { "cwd": sampleReactProjectDirPath } +); + diff --git a/src/test/download-sample-keycloak-themes.ts b/src/test/download-sample-keycloak-themes.ts new file mode 100644 index 00000000..c5404e6d --- /dev/null +++ b/src/test/download-sample-keycloak-themes.ts @@ -0,0 +1,13 @@ + +import { sampleReactProjectDirPath } from "./setupSampleReactProject"; +import * as st from "scripting-tools"; +import { join as pathJoin } from "path"; + +console.log(`Running main in ${sampleReactProjectDirPath}`); + +st.execSync( + `node ${pathJoin(__dirname, "../bin/download-sample-keycloak-themes")}`, + { "cwd": sampleReactProjectDirPath } +); + + diff --git a/src/test/setupSampleReactProject.ts b/src/test/setupSampleReactProject.ts index e34a8d26..718157f4 100644 --- a/src/test/setupSampleReactProject.ts +++ b/src/test/setupSampleReactProject.ts @@ -2,9 +2,9 @@ import * as st from "scripting-tools"; import { join as pathJoin, basename as pathBasename } from "path"; -export function setupSampleReactProject() { +export const sampleReactProjectDirPath = pathJoin(__dirname, "..", "..", "sample_react_project"); - const sampleReactProjectDirPath = pathJoin(__dirname, "..", "..", "sample_react_project"); +export function setupSampleReactProject() { st.execSync(`rm -rf ${sampleReactProjectDirPath}`); st.execSync(`mkdir ${sampleReactProjectDirPath}`);