parent
f5b87f4669
commit
8cd584cbd5
@ -12,7 +12,8 @@ export function downloadBuiltinKeycloakTheme(params: { keycloakVersion: string;
|
|||||||
downloadAndUnzip({
|
downloadAndUnzip({
|
||||||
"destDirPath": destDirPath,
|
"destDirPath": destDirPath,
|
||||||
"url": `https://github.com/keycloak/keycloak/archive/refs/tags/${keycloakVersion}.zip`,
|
"url": `https://github.com/keycloak/keycloak/archive/refs/tags/${keycloakVersion}.zip`,
|
||||||
"pathOfDirToExtractInArchive": `keycloak-${keycloakVersion}/themes/src/main/resources${ext}/theme`
|
"pathOfDirToExtractInArchive": `keycloak-${keycloakVersion}/themes/src/main/resources${ext}/theme`,
|
||||||
|
"cacheDirPath": pathJoin(keycloakThemeBuildingDirPath, ".cache")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,31 +2,74 @@ import { basename as pathBasename, join as pathJoin } from "path";
|
|||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { transformCodebase } from "./transformCodebase";
|
import { transformCodebase } from "./transformCodebase";
|
||||||
import { rm_rf, rm, rm_r } from "./rm";
|
import { rm, rm_rf } from "./rm";
|
||||||
|
import * as crypto from "crypto";
|
||||||
|
|
||||||
/** assert url ends with .zip */
|
/** assert url ends with .zip */
|
||||||
export function downloadAndUnzip(params: { url: string; destDirPath: string; pathOfDirToExtractInArchive?: string }) {
|
export function downloadAndUnzip(params: { url: string; destDirPath: string; pathOfDirToExtractInArchive?: string; cacheDirPath: string }) {
|
||||||
const { url, destDirPath, pathOfDirToExtractInArchive } = params;
|
const { url, destDirPath, pathOfDirToExtractInArchive, cacheDirPath } = params;
|
||||||
|
|
||||||
const tmpDirPath = pathJoin(destDirPath, "..", "tmp_xxKdOxnEdx");
|
const extractDirPath = pathJoin(
|
||||||
const zipFilePath = pathBasename(url);
|
cacheDirPath,
|
||||||
|
`_${crypto.createHash("sha256").update(JSON.stringify({ url, pathOfDirToExtractInArchive })).digest("hex").substring(0, 15)}`
|
||||||
|
);
|
||||||
|
|
||||||
rm_rf(tmpDirPath);
|
fs.mkdirSync(cacheDirPath, { "recursive": true });
|
||||||
|
|
||||||
fs.mkdirSync(tmpDirPath, { "recursive": true });
|
const { readIsSuccessByExtractDirPath, writeIsSuccessByExtractDirPath } = (() => {
|
||||||
|
const filePath = pathJoin(cacheDirPath, "isSuccessByExtractDirPath.json");
|
||||||
|
|
||||||
execSync(`curl -L ${url} -o ${zipFilePath}`, { "cwd": tmpDirPath });
|
type IsSuccessByExtractDirPath = Record<string, boolean | undefined>;
|
||||||
|
|
||||||
execSync(`unzip -o ${zipFilePath}${pathOfDirToExtractInArchive === undefined ? "" : ` "${pathOfDirToExtractInArchive}/**/*"`}`, {
|
function readIsSuccessByExtractDirPath(): IsSuccessByExtractDirPath {
|
||||||
"cwd": tmpDirPath
|
if (!fs.existsSync(filePath)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.parse(fs.readFileSync(filePath).toString("utf8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeIsSuccessByExtractDirPath(isSuccessByExtractDirPath: IsSuccessByExtractDirPath): void {
|
||||||
|
fs.writeFileSync(filePath, Buffer.from(JSON.stringify(isSuccessByExtractDirPath, null, 2), "utf8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { readIsSuccessByExtractDirPath, writeIsSuccessByExtractDirPath };
|
||||||
|
})();
|
||||||
|
|
||||||
|
downloadAndUnzip: {
|
||||||
|
const isSuccessByExtractDirPath = readIsSuccessByExtractDirPath();
|
||||||
|
|
||||||
|
if (isSuccessByExtractDirPath[extractDirPath]) {
|
||||||
|
break downloadAndUnzip;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeIsSuccessByExtractDirPath({
|
||||||
|
...isSuccessByExtractDirPath,
|
||||||
|
[extractDirPath]: false
|
||||||
});
|
});
|
||||||
|
|
||||||
rm(pathBasename(url), { "cwd": tmpDirPath });
|
rm_rf(extractDirPath);
|
||||||
|
|
||||||
|
fs.mkdirSync(extractDirPath);
|
||||||
|
|
||||||
|
const zipFileBasename = pathBasename(url);
|
||||||
|
|
||||||
|
execSync(`curl -L ${url} -o ${zipFileBasename}`, { "cwd": extractDirPath });
|
||||||
|
|
||||||
|
execSync(`unzip -o ${zipFileBasename}${pathOfDirToExtractInArchive === undefined ? "" : ` "${pathOfDirToExtractInArchive}/**/*"`}`, {
|
||||||
|
"cwd": extractDirPath
|
||||||
|
});
|
||||||
|
|
||||||
|
rm(zipFileBasename, { "cwd": extractDirPath });
|
||||||
|
|
||||||
|
writeIsSuccessByExtractDirPath({
|
||||||
|
...isSuccessByExtractDirPath,
|
||||||
|
[extractDirPath]: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
"srcDirPath": pathOfDirToExtractInArchive === undefined ? tmpDirPath : pathJoin(tmpDirPath, pathOfDirToExtractInArchive),
|
"srcDirPath": pathOfDirToExtractInArchive === undefined ? extractDirPath : pathJoin(extractDirPath, pathOfDirToExtractInArchive),
|
||||||
destDirPath
|
destDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
rm_r(tmpDirPath);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user