keycloak_theme/src/bin/tools/downloadAndUnzip.ts

34 lines
873 B
TypeScript
Raw Normal View History

2021-02-28 18:40:57 +01:00
2021-03-03 02:31:02 +01:00
import { basename as pathBasename, join as pathJoin } from "path";
import { execSync } from "child_process";
2021-02-28 18:40:57 +01:00
import fs from "fs";
2021-03-03 02:31:02 +01:00
import { transformCodebase } from "../tools/transformCodebase";
2021-02-28 18:40:57 +01:00
2021-03-03 02:31:02 +01:00
/** assert url ends with .zip */
2021-02-28 18:40:57 +01:00
export function downloadAndUnzip(
params: {
url: string;
destDirPath: string;
}
) {
const { url, destDirPath } = params;
2021-03-03 02:31:02 +01:00
const tmpDirPath = pathJoin(destDirPath, "..", "tmp_xxKdOxnEdx");
2021-02-28 18:40:57 +01:00
2021-03-03 02:31:02 +01:00
execSync(`rm -rf ${tmpDirPath}`);
fs.mkdirSync(tmpDirPath, { "recursive": true });
execSync(`wget ${url}`, { "cwd": tmpDirPath })
execSync(`unzip ${pathBasename(url)}`, { "cwd": tmpDirPath });
execSync(`rm ${pathBasename(url)}`, { "cwd": tmpDirPath });
transformCodebase({
"srcDirPath": tmpDirPath,
"destDirPath": destDirPath,
});
execSync(`rm -r ${tmpDirPath}`);
2021-02-28 18:40:57 +01:00
}