keycloak_theme/src/bin/tools/downloadAndUnzip.ts
2021-07-21 22:42:00 +02:00

35 lines
870 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { basename as pathBasename, join as pathJoin } from "path";
import { execSync } from "child_process";
import fs from "fs";
import { transformCodebase } from "../tools/transformCodebase";
import { rm_rf, rm, rm_r } from "./rm";
/** assert url ends with .zip */
export function downloadAndUnzip(
params: {
url: string;
destDirPath: string;
}
) {
const { url, destDirPath } = params;
const tmpDirPath = pathJoin(destDirPath, "..", "tmp_xxKdOxnEdx");
rm_rf(tmpDirPath);
fs.mkdirSync(tmpDirPath, { "recursive": true });
execSync(`wget ${url}`, { "cwd": tmpDirPath })
execSync(`unzip ${pathBasename(url)}`, { "cwd": tmpDirPath });
rm(pathBasename(url), { "cwd": tmpDirPath });
transformCodebase({
"srcDirPath": tmpDirPath,
"destDirPath": destDirPath,
});
rm_r(tmpDirPath);
}