includes translations

This commit is contained in:
Joseph Garrone
2021-02-28 18:40:57 +01:00
parent f70625bf3f
commit cd145b42d6
20 changed files with 8709 additions and 33 deletions

View File

@ -0,0 +1,61 @@
import * as fs from "fs";
import * as path from "path";
import { crawl } from "./crawl";
/** Apply a transformation function to every file of directory */
export function transformCodebase(
params: {
srcDirPath: string;
destDirPath: string;
transformSourceCodeString: (params: {
sourceCode: Buffer;
filePath: string;
}) => {
modifiedSourceCode: Buffer;
newFileName?: string;
} | undefined;
}
) {
const { srcDirPath, destDirPath, transformSourceCodeString } = params;
for (const file_relative_path of crawl(srcDirPath)) {
const filePath = path.join(srcDirPath, file_relative_path);
const transformSourceCodeStringResult = transformSourceCodeString({
"sourceCode": fs.readFileSync(filePath),
"filePath": path.join(srcDirPath, file_relative_path)
});
if (transformSourceCodeStringResult === undefined) {
continue;
}
fs.mkdirSync(
path.dirname(
path.join(
destDirPath,
file_relative_path
)
),
{ "recursive": true }
);
const { newFileName, modifiedSourceCode } = transformSourceCodeStringResult;
fs.writeFileSync(
path.join(
path.dirname(path.join(destDirPath, file_relative_path)),
newFileName ?? path.basename(file_relative_path)
),
modifiedSourceCode
);
}
}