diff --git a/src/bin/keycloakify/index.ts b/src/bin/keycloakify/index.ts index 258b6e23..13d73c75 100644 --- a/src/bin/keycloakify/index.ts +++ b/src/bin/keycloakify/index.ts @@ -4,5 +4,5 @@ export * from "./keycloakify"; import { main } from "./keycloakify"; if (require.main === module) { - main(); + main().catch(e => console.error(e)); } diff --git a/src/bin/keycloakify/keycloakify.ts b/src/bin/keycloakify/keycloakify.ts index 119e9c2d..5bb8f74a 100644 --- a/src/bin/keycloakify/keycloakify.ts +++ b/src/bin/keycloakify/keycloakify.ts @@ -60,10 +60,10 @@ export async function main() { case "keycloakify": logger.log("🫶 Let keycloakify do its thang"); await jar({ - "rootPath": keycloakThemeBuildingDirPath, + "rootPath": pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources"), "version": buildOptions.version, "groupId": buildOptions.groupId, - "artifactId": buildOptions.artifactId || `${buildOptions.themeName}-keycloak-theme`, + "artifactId": buildOptions.artifactId, "targetPath": jarFilePath }); break; diff --git a/src/bin/tools/jar.ts b/src/bin/tools/jar.ts index 76fbba57..2dc60f0e 100644 --- a/src/bin/tools/jar.ts +++ b/src/bin/tools/jar.ts @@ -1,11 +1,11 @@ import { Readable, Transform } from "stream"; -import { pipeline } from "stream/promises"; -import { relative, sep } from "path"; +import { dirname, relative, sep } from "path"; import { createWriteStream } from "fs"; import walk from "./walk"; import type { ZipSource } from "./zip"; import zip from "./zip"; +import { mkdir } from "fs/promises"; /** Trim leading whitespace from every line */ const trimIndent = (s: string) => s.replace(/(\n)\s+/g, "$1"); @@ -57,9 +57,9 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ const pathToRecord = () => new Transform({ objectMode: true, - transform: function (path, _, cb) { - const filename = relative(rootPath, path).split(sep).join("/"); - this.push({ filename, path }); + transform: function (fsPath, _, cb) { + const path = relative(rootPath, fsPath).split(sep).join("/"); + this.push({ path, fsPath }); cb(); }, final: function () { @@ -69,19 +69,21 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ } }); - /** - * Create an async pipeline, wait until everything is fully processed - */ - await pipeline( + await mkdir(dirname(targetPath), { recursive: true }); + + // Create an async pipeline, wait until everything is fully processed + await new Promise((resolve, reject) => { // walk all files in `rootPath` recursively - Readable.from(walk(rootPath)), - // transform every path into a ZipSource object - pathToRecord(), - // let the zip lib convert all ZipSource objects into a byte stream - zip(), - // write that byte stream to targetPath - createWriteStream(targetPath, { encoding: "binary" }) - ); + Readable.from(walk(rootPath)) + // transform every path into a ZipSource object + .pipe(pathToRecord()) + // let the zip lib convert all ZipSource objects into a byte stream + .pipe(zip()) + // write that byte stream to targetPath + .pipe(createWriteStream(targetPath, { encoding: "binary" })) + .on("finish", () => resolve()) + .on("error", e => reject(e)); + }); } /** diff --git a/src/bin/tools/zip.ts b/src/bin/tools/zip.ts index 737ba4c2..5a2ad9be 100644 --- a/src/bin/tools/zip.ts +++ b/src/bin/tools/zip.ts @@ -216,7 +216,7 @@ export default function zip() { const writeRecord = async (source: ZipSource) => { if ("fsPath" in source) await writeFromPath(source.path, source.fsPath); else if ("data" in source) await writeFromBuffer(source.path, source.data); - else throw new Error("Illegal argument " + typeof source + " " + source); + else throw new Error("Illegal argument " + typeof source + " " + JSON.stringify(source)); }; /**