2023-10-24 12:04:07 +01:00
|
|
|
// Copyright (c) Holly Stubbs (tgpholly) - Licensed under MIT
|
|
|
|
// Check LICENSE in repository root for more information.
|
|
|
|
|
2023-06-22 11:32:40 +01:00
|
|
|
// fileSmasher ~.~
|
|
|
|
// for when you're just too lazy to
|
|
|
|
// do it properly.
|
|
|
|
|
2023-07-28 10:01:47 +01:00
|
|
|
import { readdirSync, lstatSync, readFileSync, writeFileSync } from "fs";
|
2023-06-22 11:32:40 +01:00
|
|
|
|
2023-07-13 16:33:48 +01:00
|
|
|
const tsFileData:Array<string> = new Array<string>();
|
2023-06-22 11:32:40 +01:00
|
|
|
|
2023-07-28 10:28:32 +01:00
|
|
|
// Github Actions forced my hand
|
2023-07-28 09:54:32 +01:00
|
|
|
const toolinglessFolderPath = __dirname.replace("/tooling", "/");
|
|
|
|
|
2023-06-22 11:32:40 +01:00
|
|
|
function readDir(nam:string) {
|
|
|
|
const files = readdirSync(nam);
|
|
|
|
for (const file of files) {
|
2023-07-28 09:54:32 +01:00
|
|
|
if (nam == toolinglessFolderPath && (file.startsWith(".") || file == "tooling" || file == "lib" || file == "node_modules" || file == "combined.ts")) {
|
2023-06-22 11:32:40 +01:00
|
|
|
continue;
|
|
|
|
}
|
2023-07-28 09:59:34 +01:00
|
|
|
|
2023-07-28 10:03:08 +01:00
|
|
|
if (lstatSync(`${nam}/${file}`).isDirectory()) {
|
2023-06-22 11:32:40 +01:00
|
|
|
readDir(`${nam}/${file}`);
|
|
|
|
} else if (file.endsWith(".ts")) {
|
|
|
|
tsFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-28 09:54:32 +01:00
|
|
|
readDir(toolinglessFolderPath);
|
2023-06-22 11:32:40 +01:00
|
|
|
|
|
|
|
const combinedFiles = tsFileData.join("\n");
|
|
|
|
|
|
|
|
const splitLines = combinedFiles.split("\n");
|
|
|
|
const resultLines:Array<string> = new Array<string>();
|
|
|
|
|
|
|
|
const unExport = [
|
|
|
|
"class:ReaderBase",
|
|
|
|
"class:ReaderLE",
|
|
|
|
"class:ReaderBE",
|
|
|
|
"class:WriterBase",
|
|
|
|
"class:WriterLE",
|
|
|
|
"class:WriterBE",
|
|
|
|
];
|
|
|
|
|
|
|
|
function checkForMatchAndReplace(s:string) {
|
|
|
|
for (const tUExp of unExport) {
|
|
|
|
const spl = tUExp.split(":");
|
|
|
|
const type = spl[0];
|
|
|
|
if (s.startsWith(`export ${type} ${spl[1]}`)) {
|
|
|
|
return s.replace(`export ${type} ${spl[1]}`, `${type} ${spl[1]}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's process the file to make it usable
|
|
|
|
for (const line of splitLines) {
|
|
|
|
// Throw away imports as they aren't needed
|
|
|
|
// TODO: Add allow list for npm module imports
|
|
|
|
if (line.startsWith("import")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Fix up classes, interfaces and such.
|
2023-10-24 12:04:32 +01:00
|
|
|
if (process.argv[2] === "forweb") {
|
|
|
|
resultLines.push(line.replace("export class", "class").replace("export function", "function").replace("export enum", "enum").replace("export interface", "interface"));
|
|
|
|
} else {
|
|
|
|
resultLines.push(checkForMatchAndReplace(line));
|
|
|
|
}
|
2023-06-22 11:32:40 +01:00
|
|
|
}
|
|
|
|
|
2023-07-28 10:28:32 +01:00
|
|
|
writeFileSync("./combined.ts", resultLines.join("\n"));
|