download and extract actually just for downloading and extracting

This commit is contained in:
Joseph Garrone 2024-08-24 23:15:54 +02:00
parent c6cf564842
commit 1785916d32
4 changed files with 8 additions and 27 deletions

View File

@ -314,8 +314,7 @@ export async function generateResourcesForMainTheme(params: {
} }
const { extractedDirPath } = await downloadAndExtractArchive({ const { extractedDirPath } = await downloadAndExtractArchive({
urlOrPath: url: "https://repo1.maven.org/maven2/org/keycloak/keycloak-account-ui/25.0.1/keycloak-account-ui-25.0.1.jar",
"https://repo1.maven.org/maven2/org/keycloak/keycloak-account-ui/25.0.1/keycloak-account-ui-25.0.1.jar",
cacheDirPath: buildContext.cacheDirPath, cacheDirPath: buildContext.cacheDirPath,
fetchOptions: buildContext.fetchOptions, fetchOptions: buildContext.fetchOptions,
uniqueIdOfOnArchiveFile: "bring_in_account_v3_i18n_messages", uniqueIdOfOnArchiveFile: "bring_in_account_v3_i18n_messages",

View File

@ -21,7 +21,7 @@ export async function downloadKeycloakDefaultTheme(params: {
let kcNodeModulesKeepFilePaths_lastAccountV1: Set<string> | undefined = undefined; let kcNodeModulesKeepFilePaths_lastAccountV1: Set<string> | undefined = undefined;
const { extractedDirPath } = await downloadAndExtractArchive({ const { extractedDirPath } = await downloadAndExtractArchive({
urlOrPath: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`, url: `https://repo1.maven.org/maven2/org/keycloak/keycloak-themes/${keycloakVersion}/keycloak-themes-${keycloakVersion}.jar`,
cacheDirPath: buildContext.cacheDirPath, cacheDirPath: buildContext.cacheDirPath,
fetchOptions: buildContext.fetchOptions, fetchOptions: buildContext.fetchOptions,
uniqueIdOfOnArchiveFile: "downloadKeycloakDefaultTheme", uniqueIdOfOnArchiveFile: "downloadKeycloakDefaultTheme",

View File

@ -200,7 +200,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
const { archiveFilePath } = await downloadAndExtractArchive({ const { archiveFilePath } = await downloadAndExtractArchive({
cacheDirPath: buildContext.cacheDirPath, cacheDirPath: buildContext.cacheDirPath,
fetchOptions: buildContext.fetchOptions, fetchOptions: buildContext.fetchOptions,
urlOrPath: extensionJar.url, url: extensionJar.url,
uniqueIdOfOnArchiveFile: "no extraction", uniqueIdOfOnArchiveFile: "no extraction",
onArchiveFile: async () => {} onArchiveFile: async () => {}
}); });

View File

@ -1,15 +1,14 @@
import fetch, { type FetchOptions } from "make-fetch-happen"; import fetch, { type FetchOptions } from "make-fetch-happen";
import { mkdir, unlink, writeFile, readdir, readFile } from "fs/promises"; import { mkdir, unlink, writeFile, readdir, readFile } from "fs/promises";
import { dirname as pathDirname, join as pathJoin, basename as pathBasename } from "path"; import { dirname as pathDirname, join as pathJoin } from "path";
import { assert } from "tsafe/assert"; import { assert } from "tsafe/assert";
import { extractArchive } from "./extractArchive"; import { extractArchive } from "./extractArchive";
import { existsAsync } from "./fs.existsAsync"; import { existsAsync } from "./fs.existsAsync";
import * as crypto from "crypto"; import * as crypto from "crypto";
import { rm } from "./fs.rm"; import { rm } from "./fs.rm";
import * as fsPr from "fs/promises";
export async function downloadAndExtractArchive(params: { export async function downloadAndExtractArchive(params: {
urlOrPath: string; url: string;
uniqueIdOfOnArchiveFile: string; uniqueIdOfOnArchiveFile: string;
onArchiveFile: (params: { onArchiveFile: (params: {
fileRelativePath: string; fileRelativePath: string;
@ -22,33 +21,16 @@ export async function downloadAndExtractArchive(params: {
cacheDirPath: string; cacheDirPath: string;
fetchOptions: FetchOptions | undefined; fetchOptions: FetchOptions | undefined;
}): Promise<{ extractedDirPath: string; archiveFilePath: string }> { }): Promise<{ extractedDirPath: string; archiveFilePath: string }> {
const { const { url, uniqueIdOfOnArchiveFile, onArchiveFile, cacheDirPath, fetchOptions } =
urlOrPath, params;
uniqueIdOfOnArchiveFile,
onArchiveFile,
cacheDirPath,
fetchOptions
} = params;
const isUrl = /^https?:\/\//.test(urlOrPath); const archiveFileBasename = url.split("?")[0].split("/").reverse()[0];
const archiveFileBasename = isUrl
? urlOrPath.split("?")[0].split("/").reverse()[0]
: pathBasename(urlOrPath);
const archiveFilePath = pathJoin(cacheDirPath, archiveFileBasename); const archiveFilePath = pathJoin(cacheDirPath, archiveFileBasename);
download: { download: {
await mkdir(pathDirname(archiveFilePath), { recursive: true }); await mkdir(pathDirname(archiveFilePath), { recursive: true });
if (!isUrl) {
await fsPr.copyFile(urlOrPath, archiveFilePath);
break download;
}
const url = urlOrPath;
if (await existsAsync(archiveFilePath)) { if (await existsAsync(archiveFilePath)) {
const isDownloaded = await SuccessTracker.getIsDownloaded({ const isDownloaded = await SuccessTracker.getIsDownloaded({
cacheDirPath, cacheDirPath,