2021-03-03 02:31:02 +01:00
|
|
|
import { basename as pathBasename, join as pathJoin } from "path";
|
|
|
|
import { execSync } from "child_process";
|
2022-07-29 23:10:35 +02:00
|
|
|
import * as fs from "fs";
|
2021-10-19 16:12:43 -03:00
|
|
|
import { transformCodebase } from "./transformCodebase";
|
2021-10-06 17:22:52 +02:00
|
|
|
import { rm_rf, rm, rm_r } from "./rm";
|
2021-02-28 18:40:57 +01:00
|
|
|
|
2021-03-03 02:31:02 +01:00
|
|
|
/** assert url ends with .zip */
|
2021-10-12 00:26:29 +02:00
|
|
|
export function downloadAndUnzip(params: { url: string; destDirPath: string; pathOfDirToExtractInArchive?: string }) {
|
2021-10-06 17:22:52 +02:00
|
|
|
const { url, destDirPath, pathOfDirToExtractInArchive } = params;
|
2021-02-28 18:40:57 +01:00
|
|
|
|
2021-03-03 02:31:02 +01:00
|
|
|
const tmpDirPath = pathJoin(destDirPath, "..", "tmp_xxKdOxnEdx");
|
2021-10-19 16:12:43 -03:00
|
|
|
const zipFilePath = pathBasename(url);
|
2021-02-28 18:40:57 +01:00
|
|
|
|
2021-07-21 22:42:00 +02:00
|
|
|
rm_rf(tmpDirPath);
|
2021-03-03 02:31:02 +01:00
|
|
|
|
2021-10-06 17:22:52 +02:00
|
|
|
fs.mkdirSync(tmpDirPath, { "recursive": true });
|
|
|
|
|
2021-10-19 16:12:43 -03:00
|
|
|
execSync(`curl -L ${url} -o ${zipFilePath}`, { "cwd": tmpDirPath });
|
2021-10-06 17:22:52 +02:00
|
|
|
|
2022-07-11 19:18:15 +02:00
|
|
|
execSync(`unzip -o ${zipFilePath}${pathOfDirToExtractInArchive === undefined ? "" : ` "${pathOfDirToExtractInArchive}/**/*"`}`, {
|
2021-10-12 00:26:29 +02:00
|
|
|
"cwd": tmpDirPath,
|
|
|
|
});
|
2021-03-03 02:31:02 +01:00
|
|
|
|
2021-07-21 22:42:00 +02:00
|
|
|
rm(pathBasename(url), { "cwd": tmpDirPath });
|
2021-03-03 02:31:02 +01:00
|
|
|
|
|
|
|
transformCodebase({
|
2021-10-12 00:26:29 +02:00
|
|
|
"srcDirPath": pathOfDirToExtractInArchive === undefined ? tmpDirPath : pathJoin(tmpDirPath, pathOfDirToExtractInArchive),
|
2021-10-06 17:22:52 +02:00
|
|
|
destDirPath,
|
2021-03-03 02:31:02 +01:00
|
|
|
});
|
|
|
|
|
2021-07-21 22:42:00 +02:00
|
|
|
rm_r(tmpDirPath);
|
2021-10-11 21:35:40 +02:00
|
|
|
}
|