2023-06-26 16:16:55 +01:00
|
|
|
// fileSmasher ~.~
|
|
|
|
// for when you're just too lazy to
|
|
|
|
// do it properly.
|
|
|
|
|
2023-07-28 10:36:50 +01:00
|
|
|
import { readdirSync, lstatSync, readFileSync, writeFileSync } from "fs";
|
2023-06-26 16:16:55 +01:00
|
|
|
|
|
|
|
let tsFileData:Array<string> = new Array<string>();
|
2023-06-26 16:21:16 +01:00
|
|
|
const tsFirstFileData:Array<string> = new Array<string>();
|
|
|
|
const tsLastFileData:Array<string> = new Array<string>();
|
|
|
|
const tsEverythingElse:Array<string> = new Array<string>();
|
2023-06-26 16:16:55 +01:00
|
|
|
|
|
|
|
function readDir(nam:string) {
|
|
|
|
const files = readdirSync(nam);
|
|
|
|
for (const file of files) {
|
|
|
|
if (nam == "./" && (file.startsWith(".") || file == "tooling" || file == "build" || file == "node_modules" || file == "combined.ts")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a very dumb way of checking for folders
|
|
|
|
// protip: don't do this.
|
2023-07-28 10:36:50 +01:00
|
|
|
if (lstatSync(`${nam}/${file}`).isDirectory()) {
|
2023-06-26 16:16:55 +01:00
|
|
|
readDir(`${nam}/${file}`);
|
|
|
|
} else if (file.endsWith(".ts")) {
|
|
|
|
if (file == "index.ts") {
|
|
|
|
tsLastFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
|
|
|
|
} else if (nam.includes("enum")) {
|
|
|
|
tsFirstFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
|
|
|
|
} else {
|
|
|
|
tsEverythingElse.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readDir("./");
|
|
|
|
|
|
|
|
tsFileData = tsFileData.concat(tsFirstFileData).concat(tsEverythingElse).concat(tsLastFileData);
|
|
|
|
|
|
|
|
const combinedFiles = tsFileData.join("\n");
|
|
|
|
|
|
|
|
const splitLines = combinedFiles.split("\n");
|
|
|
|
const resultLines:Array<string> = new Array<string>();
|
|
|
|
|
|
|
|
// Insert allowed imports
|
|
|
|
resultLines.push(`import chalk from "chalk";
|
|
|
|
import { createWriteStream, mkdirSync, existsSync, readFileSync, readFile, writeFile, writeFileSync, readdirSync } from "fs";
|
|
|
|
import { deflate, inflate } from "zlib";
|
|
|
|
import { createWriter, createReader, IReader, Endian } from "bufferstuff";
|
|
|
|
import { Server, Socket } from "net";`);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//resultLines.push(line);
|
|
|
|
resultLines.push(line.replace("export class", "class").replace("export interface", "interface").replace("export enum", "enum").replace("export type", "type"));
|
|
|
|
}
|
|
|
|
|
|
|
|
writeFileSync("./combined.ts", resultLines.join("\n"));
|