fix build

This commit is contained in:
Joseph Garrone
2021-03-03 02:31:02 +01:00
parent 52ba14cd8f
commit 2a5a4c16ea
8 changed files with 70 additions and 65 deletions

View File

@ -1,8 +1,10 @@
import { basename as pathBasename } from "path";
import child_process from "child_process";
import { basename as pathBasename, join as pathJoin } from "path";
import { execSync } from "child_process";
import fs from "fs";
import { transformCodebase } from "../tools/transformCodebase";
/** assert url ends with .zip */
export function downloadAndUnzip(
params: {
url: string;
@ -12,11 +14,21 @@ export function downloadAndUnzip(
const { url, destDirPath } = params;
fs.mkdirSync(destDirPath, { "recursive": true });
const tmpDirPath = pathJoin(destDirPath, "..", "tmp_xxKdOxnEdx");
[
`wget ${url}`,
...["unzip", "rm"].map(prg => `${prg} ${pathBasename(url)}`),
].forEach(cmd => child_process.execSync(cmd, { "cwd": destDirPath }));
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}`);
}

View File

@ -3,34 +3,42 @@
import * as fs from "fs";
import * as path from "path";
import { crawl } from "./crawl";
import { id } from "evt/tools/typeSafety/id";
/** Apply a transformation function to every file of directory */
export function transformCodebase(
params: {
srcDirPath: string;
destDirPath: string;
transformSourceCodeString: (params: {
type TransformSourceCode =
(params: {
sourceCode: Buffer;
filePath: string;
}) => {
modifiedSourceCode: Buffer;
newFileName?: string;
} | undefined;
/** Apply a transformation function to every file of directory */
export function transformCodebase(
params: {
srcDirPath: string;
destDirPath: string;
transformSourceCode?: TransformSourceCode;
}
) {
const { srcDirPath, destDirPath, transformSourceCodeString } = params;
const {
srcDirPath,
destDirPath,
transformSourceCode = id<TransformSourceCode>(({ sourceCode }) => ({ "modifiedSourceCode": sourceCode }))
} = params;
for (const file_relative_path of crawl(srcDirPath)) {
const filePath = path.join(srcDirPath, file_relative_path);
const transformSourceCodeStringResult = transformSourceCodeString({
const transformSourceCodeResult = transformSourceCode({
"sourceCode": fs.readFileSync(filePath),
"filePath": path.join(srcDirPath, file_relative_path)
});
if (transformSourceCodeStringResult === undefined) {
if (transformSourceCodeResult === undefined) {
continue;
}
@ -44,7 +52,7 @@ export function transformCodebase(
{ "recursive": true }
);
const { newFileName, modifiedSourceCode } = transformSourceCodeStringResult;
const { newFileName, modifiedSourceCode } = transformSourceCodeResult;
fs.writeFileSync(
path.join(