Merge remote-tracking branch 'upstream/main'
This commit is contained in:
@ -31,8 +31,6 @@
|
|||||||
</p>
|
</p>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
> 🗣️🔈 Sorry the latest release is broken, fixing ASAP
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<i>Ultimately this build tool generates a Keycloak theme <a href="https://www.keycloakify.dev">Learn more</a></i>
|
<i>Ultimately this build tool generates a Keycloak theme <a href="https://www.keycloakify.dev">Learn more</a></i>
|
||||||
<img src="https://user-images.githubusercontent.com/6702424/110260457-a1c3d380-7fac-11eb-853a-80459b65626b.png">
|
<img src="https://user-images.githubusercontent.com/6702424/110260457-a1c3d380-7fac-11eb-853a-80459b65626b.png">
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"version": "7.6.4",
|
"version": "7.6.6",
|
||||||
"description": "Create Keycloak themes using React",
|
"description": "Create Keycloak themes using React",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -13,7 +13,7 @@ export type BuildOptions = BuildOptions.Standalone | BuildOptions.ExternalAssets
|
|||||||
export namespace BuildOptions {
|
export namespace BuildOptions {
|
||||||
export type Common = {
|
export type Common = {
|
||||||
isSilent: boolean;
|
isSilent: boolean;
|
||||||
version: string;
|
themeVersion: string;
|
||||||
themeName: string;
|
themeName: string;
|
||||||
extraLoginPages: string[] | undefined;
|
extraLoginPages: string[] | undefined;
|
||||||
extraAccountPages: string[] | undefined;
|
extraAccountPages: string[] | undefined;
|
||||||
@ -149,7 +149,7 @@ export function readBuildOptions(params: { projectDirPath: string; isExternalAss
|
|||||||
.join(".") ?? fallbackGroupId) + ".keycloak"
|
.join(".") ?? fallbackGroupId) + ".keycloak"
|
||||||
);
|
);
|
||||||
})(),
|
})(),
|
||||||
"version": process.env.KEYCLOAKIFY_VERSION ?? version,
|
"themeVersion": process.env.KEYCLOAKIFY_THEME_VERSION ?? process.env.KEYCLOAKIFY_VERSION ?? version ?? "0.0.0",
|
||||||
"extraLoginPages": [...(extraPages ?? []), ...(extraLoginPages ?? [])],
|
"extraLoginPages": [...(extraPages ?? []), ...(extraLoginPages ?? [])],
|
||||||
extraAccountPages,
|
extraAccountPages,
|
||||||
extraThemeProperties,
|
extraThemeProperties,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<script>const _=
|
<script>const _=
|
||||||
|
<#assign pageId="PAGE_ID_xIgLsPgGId9D8e">
|
||||||
(()=>{
|
(()=>{
|
||||||
|
|
||||||
const out = ${ftl_object_to_js_code_declaring_an_object(.data_model, [])?no_esc};
|
const out = ${ftl_object_to_js_code_declaring_an_object(.data_model, [])?no_esc};
|
||||||
@ -118,8 +119,9 @@
|
|||||||
};
|
};
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
out["pageId"] = "PAGE_ID_xIgLsPgGId9D8e";
|
|
||||||
out["keycloakifyVersion"] = "KEYCLOAKIFY_VERSION_xEdKd3xEdr";
|
out["keycloakifyVersion"] = "KEYCLOAKIFY_VERSION_xEdKd3xEdr";
|
||||||
|
out["themeVersion"] = "KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx";
|
||||||
|
out["pageId"] = "${pageId}";
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ export type BuildOptionsLike = BuildOptionsLike.Standalone | BuildOptionsLike.Ex
|
|||||||
export namespace BuildOptionsLike {
|
export namespace BuildOptionsLike {
|
||||||
export type Common = {
|
export type Common = {
|
||||||
customUserAttributes: string[];
|
customUserAttributes: string[];
|
||||||
|
themeVersion: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Standalone = Common & {
|
export type Standalone = Common & {
|
||||||
@ -130,7 +131,8 @@ export function generateFtlFilesCodeFactory(params: {
|
|||||||
"CUSTOM_USER_ATTRIBUTES_eKsIY4ZsZ4xeM",
|
"CUSTOM_USER_ATTRIBUTES_eKsIY4ZsZ4xeM",
|
||||||
buildOptions.customUserAttributes.length === 0 ? "" : ", " + buildOptions.customUserAttributes.map(name => `"${name}"`).join(", ")
|
buildOptions.customUserAttributes.length === 0 ? "" : ", " + buildOptions.customUserAttributes.map(name => `"${name}"`).join(", ")
|
||||||
)
|
)
|
||||||
.replace("KEYCLOAKIFY_VERSION_xEdKd3xEdr", keycloakifyVersion),
|
.replace("KEYCLOAKIFY_VERSION_xEdKd3xEdr", keycloakifyVersion)
|
||||||
|
.replace("KEYCLOAKIFY_THEME_VERSION_sIgKd3xEdr3dx", buildOptions.themeVersion),
|
||||||
"<!-- xIdLqMeOedErIdLsPdNdI9dSlxI -->": [
|
"<!-- xIdLqMeOedErIdLsPdNdI9dSlxI -->": [
|
||||||
"<#if scripts??>",
|
"<#if scripts??>",
|
||||||
" <#list scripts as script>",
|
" <#list scripts as script>",
|
||||||
|
@ -9,7 +9,7 @@ export type BuildOptionsLike = {
|
|||||||
themeName: string;
|
themeName: string;
|
||||||
groupId: string;
|
groupId: string;
|
||||||
artifactId?: string;
|
artifactId?: string;
|
||||||
version: string;
|
themeVersion: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -26,7 +26,7 @@ export function generateJavaStackFiles(params: {
|
|||||||
jarFilePath: string;
|
jarFilePath: string;
|
||||||
} {
|
} {
|
||||||
const {
|
const {
|
||||||
buildOptions: { groupId, themeName, version, artifactId },
|
buildOptions: { groupId, themeName, themeVersion, artifactId },
|
||||||
keycloakThemeBuildingDirPath,
|
keycloakThemeBuildingDirPath,
|
||||||
doBundlesEmailTemplate
|
doBundlesEmailTemplate
|
||||||
} = params;
|
} = params;
|
||||||
@ -43,7 +43,7 @@ export function generateJavaStackFiles(params: {
|
|||||||
` <modelVersion>4.0.0</modelVersion>`,
|
` <modelVersion>4.0.0</modelVersion>`,
|
||||||
` <groupId>${groupId}</groupId>`,
|
` <groupId>${groupId}</groupId>`,
|
||||||
` <artifactId>${artifactId}</artifactId>`,
|
` <artifactId>${artifactId}</artifactId>`,
|
||||||
` <version>${version}</version>`,
|
` <version>${themeVersion}</version>`,
|
||||||
` <name>${artifactId}</name>`,
|
` <name>${artifactId}</name>`,
|
||||||
` <description />`,
|
` <description />`,
|
||||||
`</project>`
|
`</project>`
|
||||||
@ -83,6 +83,6 @@ export function generateJavaStackFiles(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"jarFilePath": pathJoin(keycloakThemeBuildingDirPath, "target", `${artifactId}-${version}.jar`)
|
"jarFilePath": pathJoin(keycloakThemeBuildingDirPath, "target", `${artifactId}-${themeVersion}.jar`)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ export namespace BuildOptionsLike {
|
|||||||
extraThemeProperties?: string[];
|
extraThemeProperties?: string[];
|
||||||
isSilent: boolean;
|
isSilent: boolean;
|
||||||
customUserAttributes: string[];
|
customUserAttributes: string[];
|
||||||
|
themeVersion: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Standalone = Common & {
|
export type Standalone = Common & {
|
||||||
|
@ -68,7 +68,7 @@ export async function main() {
|
|||||||
logger.log("🫶 Let keycloakify do its thang");
|
logger.log("🫶 Let keycloakify do its thang");
|
||||||
await jar({
|
await jar({
|
||||||
"rootPath": pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources"),
|
"rootPath": pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources"),
|
||||||
"version": buildOptions.version,
|
"version": buildOptions.themeVersion,
|
||||||
"groupId": buildOptions.groupId,
|
"groupId": buildOptions.groupId,
|
||||||
"artifactId": buildOptions.artifactId,
|
"artifactId": buildOptions.artifactId,
|
||||||
"targetPath": jarFilePath
|
"targetPath": jarFilePath
|
||||||
|
@ -8,7 +8,7 @@ export const bundlers = ["mvn", "keycloakify", "none"] as const;
|
|||||||
export type Bundler = (typeof bundlers)[number];
|
export type Bundler = (typeof bundlers)[number];
|
||||||
export type ParsedPackageJson = {
|
export type ParsedPackageJson = {
|
||||||
name: string;
|
name: string;
|
||||||
version: string;
|
version?: string;
|
||||||
homepage?: string;
|
homepage?: string;
|
||||||
keycloakify?: {
|
keycloakify?: {
|
||||||
/** @deprecated: use extraLoginPages instead */
|
/** @deprecated: use extraLoginPages instead */
|
||||||
@ -31,7 +31,7 @@ export type ParsedPackageJson = {
|
|||||||
|
|
||||||
export const zParsedPackageJson = z.object({
|
export const zParsedPackageJson = z.object({
|
||||||
"name": z.string(),
|
"name": z.string(),
|
||||||
"version": z.string(),
|
"version": z.string().optional(),
|
||||||
"homepage": z.string().optional(),
|
"homepage": z.string().optional(),
|
||||||
"keycloakify": z
|
"keycloakify": z
|
||||||
.object({
|
.object({
|
||||||
|
@ -48,7 +48,7 @@ export async function jarStream({ groupId, artifactId, version, asyncPathGenerat
|
|||||||
for await (const entry of asyncPathGeneratorFn()) {
|
for await (const entry of asyncPathGeneratorFn()) {
|
||||||
if ("buffer" in entry) {
|
if ("buffer" in entry) {
|
||||||
zipFile.addBuffer(entry.buffer, entry.zipPath);
|
zipFile.addBuffer(entry.buffer, entry.zipPath);
|
||||||
} else if ("fsPath" in entry && entry.fsPath.endsWith(sep)) {
|
} else if ("fsPath" in entry && !entry.fsPath.endsWith(sep)) {
|
||||||
zipFile.addFile(entry.fsPath, entry.zipPath);
|
zipFile.addFile(entry.fsPath, entry.zipPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { readdir } from "fs/promises";
|
import { readdir } from "fs/promises";
|
||||||
import { resolve } from "path";
|
import { resolve, sep } from "path";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously and recursively walk a directory tree, yielding every file and directory
|
* Asynchronously and recursively walk a directory tree, yielding every file and directory
|
||||||
* found
|
* found. Directory paths will _always_ end with a path separator.
|
||||||
*
|
*
|
||||||
* @param root the starting directory
|
* @param root the starting directory
|
||||||
* @returns AsyncGenerator
|
* @returns AsyncGenerator
|
||||||
@ -12,8 +12,8 @@ export default async function* walk(root: string): AsyncGenerator<string, void,
|
|||||||
for (const entry of await readdir(root, { withFileTypes: true })) {
|
for (const entry of await readdir(root, { withFileTypes: true })) {
|
||||||
const absolutePath = resolve(root, entry.name);
|
const absolutePath = resolve(root, entry.name);
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
yield absolutePath;
|
yield absolutePath.endsWith(sep) ? absolutePath : absolutePath + sep;
|
||||||
yield* walk(absolutePath);
|
yield* walk(absolutePath);
|
||||||
} else yield absolutePath;
|
} else yield absolutePath.endsWith(sep) ? absolutePath.substring(0, absolutePath.length - 1) : absolutePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { jarStream, type ZipEntryGenerator } from "keycloakify/bin/tools/jar";
|
import jar, { jarStream, type ZipEntryGenerator } from "keycloakify/bin/tools/jar";
|
||||||
import { fromBuffer, Entry, ZipFile } from "yauzl";
|
import { fromBuffer, Entry, ZipFile } from "yauzl";
|
||||||
import { it, describe, assert } from "vitest";
|
import { it, describe, assert, afterAll } from "vitest";
|
||||||
import { Readable } from "stream";
|
import { Readable } from "stream";
|
||||||
|
import { tmpdir } from "os";
|
||||||
|
import { mkdtemp, cp, mkdir, rm } from "fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
import { createReadStream } from "fs";
|
||||||
|
import walk from "keycloakify/bin/tools/walk";
|
||||||
|
|
||||||
type AsyncIterable<T> = {
|
type AsyncIterable<T> = {
|
||||||
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
||||||
@ -17,7 +22,7 @@ async function readToBuffer(stream: NodeJS.ReadableStream) {
|
|||||||
return Buffer.concat(await arrayFromAsync(stream as AsyncIterable<Buffer>));
|
return Buffer.concat(await arrayFromAsync(stream as AsyncIterable<Buffer>));
|
||||||
}
|
}
|
||||||
|
|
||||||
function unzip(buffer: Buffer) {
|
function unzipBuffer(buffer: Buffer) {
|
||||||
return new Promise<ZipFile>((resolve, reject) =>
|
return new Promise<ZipFile>((resolve, reject) =>
|
||||||
fromBuffer(buffer, { lazyEntries: true }, (err, zipFile) => {
|
fromBuffer(buffer, { lazyEntries: true }, (err, zipFile) => {
|
||||||
if (err !== null) {
|
if (err !== null) {
|
||||||
@ -57,15 +62,22 @@ function readAll(zipFile: ZipFile): Promise<Map<string, Buffer>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("jar", () => {
|
describe("jar", () => {
|
||||||
|
const coords = { artifactId: "someArtifactId", groupId: "someGroupId", version: "1.2.3" };
|
||||||
|
|
||||||
|
const tmpDirs: string[] = [];
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await Promise.all(tmpDirs.map(dir => rm(dir, { force: true, recursive: true })));
|
||||||
|
});
|
||||||
|
|
||||||
it("creates jar artifacts without error", async () => {
|
it("creates jar artifacts without error", async () => {
|
||||||
async function* mockFiles(): ZipEntryGenerator {
|
async function* mockFiles(): ZipEntryGenerator {
|
||||||
yield { zipPath: "foo", buffer: Buffer.from("foo") };
|
yield { zipPath: "foo", buffer: Buffer.from("foo") };
|
||||||
}
|
}
|
||||||
|
|
||||||
const opts = { artifactId: "someArtifactId", groupId: "someGroupId", version: "1.2.3", asyncPathGeneratorFn: mockFiles };
|
const zipped = await jarStream({ ...coords, asyncPathGeneratorFn: mockFiles });
|
||||||
const zipped = await jarStream(opts);
|
|
||||||
const buffered = await readToBuffer(zipped.outputStream);
|
const buffered = await readToBuffer(zipped.outputStream);
|
||||||
const unzipped = await unzip(buffered);
|
const unzipped = await unzipBuffer(buffered);
|
||||||
const entries = await readAll(unzipped);
|
const entries = await readAll(unzipped);
|
||||||
|
|
||||||
assert.equal(entries.size, 3);
|
assert.equal(entries.size, 3);
|
||||||
@ -83,4 +95,31 @@ describe("jar", () => {
|
|||||||
assert.isOk(pomProperties?.includes("someGroupId"));
|
assert.isOk(pomProperties?.includes("someGroupId"));
|
||||||
assert.isOk(pomProperties?.includes("someArtifactId"));
|
assert.isOk(pomProperties?.includes("someArtifactId"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("creates a jar from _real_ files without error", async () => {
|
||||||
|
const tmp = await mkdtemp(path.join(tmpdir(), "kc-jar-test-"));
|
||||||
|
tmpDirs.push(tmp);
|
||||||
|
const rootPath = path.join(tmp, "src");
|
||||||
|
const targetPath = path.join(tmp, "jar.jar");
|
||||||
|
await mkdir(rootPath);
|
||||||
|
|
||||||
|
await cp(path.dirname(__dirname), rootPath, { recursive: true });
|
||||||
|
|
||||||
|
await jar({ ...coords, rootPath, targetPath });
|
||||||
|
|
||||||
|
const buffered = await readToBuffer(createReadStream(targetPath));
|
||||||
|
const unzipped = await unzipBuffer(buffered);
|
||||||
|
const entries = await readAll(unzipped);
|
||||||
|
const zipPaths = Array.from(entries.keys());
|
||||||
|
|
||||||
|
assert.isOk(entries.has("META-INF/MANIFEST.MF"));
|
||||||
|
assert.isOk(entries.has("META-INF/maven/someGroupId/someArtifactId/pom.properties"));
|
||||||
|
|
||||||
|
for await (const fsPath of walk(rootPath)) {
|
||||||
|
if (!fsPath.endsWith(path.sep)) {
|
||||||
|
const rel = path.relative(rootPath, fsPath).replace(path.sep === "/" ? /\//g : /\\/g, "/");
|
||||||
|
assert.isOk(zipPaths.includes(rel), `missing ${rel} (${rel}, ${zipPaths.join(", ")})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user