Almoste there
This commit is contained in:
parent
00f15537a3
commit
ee3fd977c1
2
.gitignore
vendored
2
.gitignore
vendored
@ -42,4 +42,4 @@ jspm_packages
|
|||||||
|
|
||||||
/dist
|
/dist
|
||||||
|
|
||||||
/etc_tmp/
|
/sample_react_project/
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
"@types/node": "^10.0.0",
|
"@types/node": "^10.0.0",
|
||||||
"denoify": "^0.6.4",
|
"denoify": "^0.6.4",
|
||||||
"evt": "beta",
|
"evt": "beta",
|
||||||
"scripting-tools": "^0.19.13",
|
|
||||||
"typescript": "^4.1.5"
|
"typescript": "^4.1.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"scripting-tools": "^0.19.13",
|
||||||
"cheerio": "^1.0.0-rc.5",
|
"cheerio": "^1.0.0-rc.5",
|
||||||
"node-html-parser": "^2.1.0"
|
"node-html-parser": "^2.1.0"
|
||||||
}
|
}
|
||||||
|
95
src/bin/generateJavaStackFiles.ts
Normal file
95
src/bin/generateJavaStackFiles.ts
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
|
||||||
|
import * as url from "url";
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { join as pathJoin, dirname as pathDirname } from "path";
|
||||||
|
|
||||||
|
export type ParsedPackageJson = {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
homepage?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function generateJavaStackFiles(
|
||||||
|
params: {
|
||||||
|
parsedPackageJson: ParsedPackageJson;
|
||||||
|
keycloakThemeBuildingDirPath: string;
|
||||||
|
}
|
||||||
|
): void {
|
||||||
|
|
||||||
|
const { parsedPackageJson, keycloakThemeBuildingDirPath } = params;
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
const { pomFileCode } = (function generatePomFileCode(): { pomFileCode: string; } {
|
||||||
|
|
||||||
|
const { name, version, homepage } = parsedPackageJson;
|
||||||
|
|
||||||
|
const groupId = (() => {
|
||||||
|
|
||||||
|
const fallbackGroupId = `there.was.no.homepage.field.in.the.package.json.${name}.keycloak`;
|
||||||
|
|
||||||
|
return !homepage ?
|
||||||
|
fallbackGroupId :
|
||||||
|
url.parse(homepage).host?.split(".").reverse().join(".") ?? fallbackGroupId;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
const artefactId = `${name}-keycloak-theme`;
|
||||||
|
|
||||||
|
const pomFileCode = [
|
||||||
|
`<?xml version="1.0"?>`,
|
||||||
|
`<project xmlns="http://maven.apache.org/POM/4.0.0"`,
|
||||||
|
` xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`,
|
||||||
|
` xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">`,
|
||||||
|
` <modelVersion>4.0.0</modelVersion>`,
|
||||||
|
` <groupId>${groupId}</groupId>`,
|
||||||
|
` <artifactId>${artefactId}</artifactId>`,
|
||||||
|
` <version>${version}</version>`,
|
||||||
|
` <name>${artefactId}</name>`,
|
||||||
|
` <description />`,
|
||||||
|
`</project>`
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
return { pomFileCode };
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
keycloakThemeBuildingDirPath,
|
||||||
|
Buffer.from(pomFileCode, "utf8")
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
const themeManifestFilePath = pathJoin(
|
||||||
|
keycloakThemeBuildingDirPath, "src", "main",
|
||||||
|
"resources", "META-INF", "keycloak-themes.json"
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
fs.mkdirSync(pathDirname(themeManifestFilePath));
|
||||||
|
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
themeManifestFilePath,
|
||||||
|
Buffer.from(
|
||||||
|
JSON.stringify({
|
||||||
|
"themes": [
|
||||||
|
{
|
||||||
|
"name": "onyxia",
|
||||||
|
"types": ["login", "email", "account", "welcome"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, null, 2),
|
||||||
|
"utf8"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
22
src/bin/main.ts
Normal file
22
src/bin/main.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { generateKeycloakThemeResources } from "./generateKeycloakThemeResources";
|
||||||
|
import { generateJavaStackFiles } from "./generateJavaStackFiles";
|
||||||
|
import type { ParsedPackageJson } from "./generateJavaStackFiles";
|
||||||
|
import { join as pathJoin } from "path";
|
||||||
|
|
||||||
|
const reactProjectDirPath = process.cwd();
|
||||||
|
|
||||||
|
const parsedPackageJson: ParsedPackageJson = require(pathJoin(reactProjectDirPath, "package.json"));
|
||||||
|
|
||||||
|
const keycloakThemeBuildingDirPath = pathJoin(reactProjectDirPath, "build_keycloak");
|
||||||
|
|
||||||
|
generateKeycloakThemeResources({
|
||||||
|
keycloakThemeBuildingDirPath,
|
||||||
|
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
||||||
|
"themeName": parsedPackageJson.name
|
||||||
|
});
|
||||||
|
|
||||||
|
generateJavaStackFiles({
|
||||||
|
parsedPackageJson,
|
||||||
|
keycloakThemeBuildingDirPath
|
||||||
|
});
|
||||||
|
|
@ -1,24 +1,13 @@
|
|||||||
|
|
||||||
import * as st from "scripting-tools";
|
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { generateKeycloakThemeResources } from "../bin/generateKeycloakThemeResources";
|
import { generateKeycloakThemeResources } from "../bin/generateKeycloakThemeResources";
|
||||||
|
import { setupSampleReactProject } from "./setupSampleReactProject";
|
||||||
|
|
||||||
const cwd= pathJoin(__dirname, "..", "..", "etc_tmp");
|
const { sampleReactProjectDirPath } = setupSampleReactProject();
|
||||||
|
|
||||||
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({
|
generateKeycloakThemeResources({
|
||||||
"themeName": "onyxia-ui",
|
"themeName": "onyxia-ui",
|
||||||
"reactAppBuildDirPath": pathJoin(process.cwd(), "build"),
|
"reactAppBuildDirPath": pathJoin(sampleReactProjectDirPath, "build"),
|
||||||
"keycloakThemeBuildingDirPath": pathJoin(process.cwd(), "keycloak_build")
|
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
11
src/test/main.ts
Normal file
11
src/test/main.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
import { setupSampleReactProject } from "./setupSampleReactProject";
|
||||||
|
|
||||||
|
const { sampleReactProjectDirPath } = setupSampleReactProject();
|
||||||
|
|
||||||
|
process.chdir(sampleReactProjectDirPath);
|
||||||
|
|
||||||
|
console.log(`Running main in ${sampleReactProjectDirPath}`);
|
||||||
|
|
||||||
|
import("../bin/main");
|
||||||
|
|
20
src/test/setupSampleReactProject.ts
Normal file
20
src/test/setupSampleReactProject.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
import * as st from "scripting-tools";
|
||||||
|
import { join as pathJoin } from "path";
|
||||||
|
|
||||||
|
export function setupSampleReactProject() {
|
||||||
|
|
||||||
|
const sampleReactProjectDirPath = pathJoin(__dirname, "..", "..", "sample_react_project");
|
||||||
|
|
||||||
|
st.execSync(`rm -rf ${sampleReactProjectDirPath}`);
|
||||||
|
st.execSync(`mkdir ${sampleReactProjectDirPath}`);
|
||||||
|
|
||||||
|
[
|
||||||
|
"wget https://github.com/garronej/keycloak-react-theming/releases/download/v0.0.1/sample_build_dir_and_package_json.zip",
|
||||||
|
"unzip build.zip",
|
||||||
|
"rm build.zip"
|
||||||
|
].forEach(cmd => st.execSync(cmd, { "cwd": sampleReactProjectDirPath }));
|
||||||
|
|
||||||
|
return { sampleReactProjectDirPath };
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user