Merge branch 'main' into mvn-begone

This commit is contained in:
Waldemar Reusch 2023-02-05 13:36:52 +01:00 committed by GitHub
commit 80618bbd9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 34 deletions

View File

@ -49,6 +49,12 @@
# Changelog highlights
## 6.11.0
- <del>You no longer need to have Maven installed to build the theme. Thanks to @lordvlad, [see PR](https://github.com/InseeFrLab/keycloakify/pull/239)</del>.
- Feature new build options: [`bundler`](https://docs.keycloakify.dev/build-options#keycloakify.bundler), [`groupId`](https://docs.keycloakify.dev/build-options#keycloakify.groupid), [`artifactId`](https://docs.keycloakify.dev/build-options#keycloakify.artifactid), [`version`](https://docs.keycloakify.dev/build-options#version).
Theses options can be user to customize the output name of the .jar. You can use environnement variables to overrides the values read in the package.json. Thanks to @lordvlad.
## 6.10.0
- Widows compat (thanks to @lordvlad, [see PR](https://github.com/InseeFrLab/keycloakify/pull/226)). WSL is no longer required 🎉

View File

@ -1,6 +1,6 @@
{
"name": "keycloakify",
"version": "6.10.1",
"version": "6.11.2",
"description": "Keycloak theme generator for Reacts app",
"repository": {
"type": "git",

View File

@ -3,9 +3,11 @@ import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
import { id } from "tsafe/id";
import { parse as urlParse } from "url";
import { typeGuard } from "tsafe/typeGuard";
import { symToStr } from "tsafe/symToStr";
const BUNDLERS = ["mvn", "keycloakify", "none"] as const;
type Bundler = typeof BUNDLERS[number];
const bundlers = ["mvn", "keycloakify", "none"] as const;
type Bundler = typeof bundlers[number];
type ParsedPackageJson = {
name: string;
version: string;
@ -31,7 +33,7 @@ const zParsedPackageJson = z.object({
"areAppAndKeycloakServerSharingSameDomain": z.boolean().optional(),
"artifactId": z.string().optional(),
"groupId": z.string().optional(),
"bundler": z.enum(BUNDLERS).optional()
"bundler": z.enum(bundlers).optional()
})
.optional()
});
@ -49,8 +51,8 @@ export namespace BuildOptions {
extraPages?: string[];
extraThemeProperties?: string[];
groupId: string;
artifactId?: string;
bundler?: Bundler;
artifactId: string;
bundler: Bundler;
};
export type Standalone = Common & {
@ -126,8 +128,20 @@ export function readBuildOptions(params: {
return {
themeName,
"bundler": (process.env.KEYCLOAKIFY_BUNDLER ?? bundler) as Bundler | undefined,
"artifactId": process.env.KEYCLOAKIFY_ARTIFACT_ID ?? artifactId,
"bundler": (() => {
const { KEYCLOAKIFY_BUNDLER } = process.env;
assert(
typeGuard<Bundler | undefined>(
KEYCLOAKIFY_BUNDLER,
[undefined, ...id<readonly string[]>(bundlers)].includes(KEYCLOAKIFY_BUNDLER)
),
`${symToStr({ KEYCLOAKIFY_BUNDLER })} should be one of ${bundlers.join(", ")}`
);
return KEYCLOAKIFY_BUNDLER ?? bundler ?? "mvn";
})(),
"artifactId": process.env.KEYCLOAKIFY_ARTIFACT_ID ?? artifactId ?? `${themeName}-keycloak-theme`,
"groupId": (() => {
const fallbackGroupId = `${themeName}.keycloak`;
@ -143,7 +157,7 @@ export function readBuildOptions(params: {
.join(".") ?? fallbackGroupId) + ".keycloak"
);
})(),
"version": process.env.KEYCLOAKFIY_VERSION ?? version,
"version": process.env.KEYCLOAKIFY_VERSION ?? version,
extraPages,
extraThemeProperties,
isSilent

View File

@ -30,8 +30,6 @@ export function generateJavaStackFiles(params: {
doBundlesEmailTemplate
} = params;
const finalArtifactId = artifactId ?? `${themeName}-keycloak-theme`;
{
const { pomFileCode } = (function generatePomFileCode(): {
pomFileCode: string;
@ -43,9 +41,9 @@ export function generateJavaStackFiles(params: {
` 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>${finalArtifactId}</artifactId>`,
` <artifactId>${artifactId}</artifactId>`,
` <version>${version}</version>`,
` <name>${finalArtifactId}</name>`,
` <name>${artifactId}</name>`,
` <description />`,
`</project>`
].join("\n");
@ -84,6 +82,6 @@ export function generateJavaStackFiles(params: {
}
return {
"jarFilePath": pathJoin(keycloakThemeBuildingDirPath, "target", `${finalArtifactId}-${version}.jar`)
"jarFilePath": pathJoin(keycloakThemeBuildingDirPath, "target", `${artifactId}-${version}.jar`)
};
}

View File

@ -8,6 +8,8 @@ import { readBuildOptions } from "./BuildOptions";
import { getLogger } from "../tools/logger";
import { getCliOptions } from "../tools/cliOptions";
import jar from "../tools/jar";
import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
const reactProjectDirPath = process.cwd();
@ -51,22 +53,26 @@ export async function main() {
buildOptions
});
if (buildOptions.bundler === "none") {
logger.log("😱 Skipping bundling step, there will be no jar");
} else if (buildOptions.bundler === "keycloakify") {
logger.log("🫶 Let keycloakify do its thang");
await jar({
"rootPath": pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources"),
"version": buildOptions.version,
"groupId": buildOptions.groupId,
"artifactId": buildOptions.artifactId || `${buildOptions.themeName}-keycloak-theme`,
"targetPath": jarFilePath
});
} else {
logger.log("🫙 Run maven to deliver a jar");
child_process.execSync("mvn package", {
"cwd": keycloakThemeBuildingDirPath
});
switch (buildOptions.bundler) {
case "none":
logger.log("😱 Skipping bundling step, there will be no jar");
break;
case "keycloakify":
logger.log("🫶 Let keycloakify do its thang");
await jar({
"rootPath": pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources"),
"version": buildOptions.version,
"groupId": buildOptions.groupId,
"artifactId": buildOptions.artifactId,
"targetPath": jarFilePath
});
break;
case "mvn":
logger.log("🫙 Run maven to deliver a jar");
child_process.execSync("mvn package", { "cwd": keycloakThemeBuildingDirPath });
break;
default:
assert<Equals<typeof buildOptions.bundler, never>>(false);
}
// We want, however, to test in a container running the latest Keycloak version

View File

@ -3,10 +3,10 @@ import { join as pathJoin } from "path";
import { constants } from "fs";
import { chmod, stat } from "fs/promises";
async () => {
var { bin } = await import(pathJoin(getProjectRoot(), "package.json"));
(async () => {
const { bin } = await import(pathJoin(getProjectRoot(), "package.json"));
var promises = Object.values<string>(bin).map(async scriptPath => {
const promises = Object.values<string>(bin).map(async scriptPath => {
const fullPath = pathJoin(getProjectRoot(), scriptPath);
const oldMode = (await stat(fullPath)).mode;
const newMode = oldMode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH;
@ -14,4 +14,4 @@ async () => {
});
await Promise.all(promises);
};
})();