commit
9e826d16dd
@ -4,5 +4,5 @@ export * from "./keycloakify";
|
|||||||
import { main } from "./keycloakify";
|
import { main } from "./keycloakify";
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
main();
|
main().catch(e => console.error(e));
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,10 @@ export async function main() {
|
|||||||
case "keycloakify":
|
case "keycloakify":
|
||||||
logger.log("🫶 Let keycloakify do its thang");
|
logger.log("🫶 Let keycloakify do its thang");
|
||||||
await jar({
|
await jar({
|
||||||
"rootPath": keycloakThemeBuildingDirPath,
|
"rootPath": pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources"),
|
||||||
"version": buildOptions.version,
|
"version": buildOptions.version,
|
||||||
"groupId": buildOptions.groupId,
|
"groupId": buildOptions.groupId,
|
||||||
"artifactId": buildOptions.artifactId || `${buildOptions.themeName}-keycloak-theme`,
|
"artifactId": buildOptions.artifactId,
|
||||||
"targetPath": jarFilePath
|
"targetPath": jarFilePath
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Readable, Transform } from "stream";
|
import { Readable, Transform } from "stream";
|
||||||
import { pipeline } from "stream/promises";
|
import { dirname, relative, sep } from "path";
|
||||||
import { relative, sep } from "path";
|
|
||||||
import { createWriteStream } from "fs";
|
import { createWriteStream } from "fs";
|
||||||
|
|
||||||
import walk from "./walk";
|
import walk from "./walk";
|
||||||
import type { ZipSource } from "./zip";
|
import type { ZipSource } from "./zip";
|
||||||
import zip from "./zip";
|
import zip from "./zip";
|
||||||
|
import { mkdir } from "fs/promises";
|
||||||
|
|
||||||
/** Trim leading whitespace from every line */
|
/** Trim leading whitespace from every line */
|
||||||
const trimIndent = (s: string) => s.replace(/(\n)\s+/g, "$1");
|
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 = () =>
|
const pathToRecord = () =>
|
||||||
new Transform({
|
new Transform({
|
||||||
objectMode: true,
|
objectMode: true,
|
||||||
transform: function (path, _, cb) {
|
transform: function (fsPath, _, cb) {
|
||||||
const filename = relative(rootPath, path).split(sep).join("/");
|
const path = relative(rootPath, fsPath).split(sep).join("/");
|
||||||
this.push({ filename, path });
|
this.push({ path, fsPath });
|
||||||
cb();
|
cb();
|
||||||
},
|
},
|
||||||
final: function () {
|
final: function () {
|
||||||
@ -69,19 +69,21 @@ export default async function jar({ groupId, artifactId, version, rootPath, targ
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
await mkdir(dirname(targetPath), { recursive: true });
|
||||||
* Create an async pipeline, wait until everything is fully processed
|
|
||||||
*/
|
// Create an async pipeline, wait until everything is fully processed
|
||||||
await pipeline(
|
await new Promise<void>((resolve, reject) => {
|
||||||
// walk all files in `rootPath` recursively
|
// walk all files in `rootPath` recursively
|
||||||
Readable.from(walk(rootPath)),
|
Readable.from(walk(rootPath))
|
||||||
// transform every path into a ZipSource object
|
// transform every path into a ZipSource object
|
||||||
pathToRecord(),
|
.pipe(pathToRecord())
|
||||||
// let the zip lib convert all ZipSource objects into a byte stream
|
// let the zip lib convert all ZipSource objects into a byte stream
|
||||||
zip(),
|
.pipe(zip())
|
||||||
// write that byte stream to targetPath
|
// write that byte stream to targetPath
|
||||||
createWriteStream(targetPath, { encoding: "binary" })
|
.pipe(createWriteStream(targetPath, { encoding: "binary" }))
|
||||||
);
|
.on("finish", () => resolve())
|
||||||
|
.on("error", e => reject(e));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,7 +216,7 @@ export default function zip() {
|
|||||||
const writeRecord = async (source: ZipSource) => {
|
const writeRecord = async (source: ZipSource) => {
|
||||||
if ("fsPath" in source) await writeFromPath(source.path, source.fsPath);
|
if ("fsPath" in source) await writeFromPath(source.path, source.fsPath);
|
||||||
else if ("data" in source) await writeFromBuffer(source.path, source.data);
|
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));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user