diff --git a/Binato.ts b/Binato.ts index 395d8d8..81cd264 100644 --- a/Binato.ts +++ b/Binato.ts @@ -1,10 +1,8 @@ -console.clear(); - import { ConsoleHelper } from "./ConsoleHelper"; import { readFileSync, existsSync } from "fs"; if (!existsSync("./config.json")) { - ConsoleHelper.printError("You must have a config file in the root of Binato's folder structure."); - ConsoleHelper.printError("Check the GitHub for an example file"); + ConsoleHelper.printError("Config file missing!"); + ConsoleHelper.printError("Check the GitHub for an example or create one with the example you have."); process.exit(1); } diff --git a/ConsoleHelper.ts b/ConsoleHelper.ts index d364a00..34bce56 100644 --- a/ConsoleHelper.ts +++ b/ConsoleHelper.ts @@ -1,5 +1,7 @@ import * as dyetty from "dyetty"; +console.clear(); + enum LogType { INFO, WARN, diff --git a/server/objects/Shared.ts b/server/objects/Shared.ts index d918cde..eff7aba 100644 --- a/server/objects/Shared.ts +++ b/server/objects/Shared.ts @@ -4,11 +4,12 @@ import Database from "../objects/Database"; import DataStreamArray from "../objects/DataStreamArray"; import MultiplayerManager from "../MultiplayerManager"; import PrivateChatManager from "../PrivateChatManager"; -import { readFileSync } from "fs"; +import { existsSync, readFileSync } from "fs"; import UserArray from "../objects/UserArray"; import User from "./User"; import LatLng from "./LatLng"; import Bot from "../Bot"; +import { ConsoleHelper } from "../../ConsoleHelper"; export default class Shared { public readonly chatManager:ChatManager; @@ -21,6 +22,11 @@ export default class Shared { public readonly bot:Bot; public constructor() { + if (!existsSync("./config.json")) { + ConsoleHelper.printError("Config file missing!"); + ConsoleHelper.printError("Check the GitHub for an example or create one with the example you have."); + process.exit(1); + } this.config = JSON.parse(readFileSync("./config.json").toString()) as Config; this.database = new Database(this.config.database.address, this.config.database.port, this.config.database.username, this.config.database.password, this.config.database.name); this.streams = new DataStreamArray(); diff --git a/tooling/cleanup.ts b/tooling/cleanup.ts index cba0137..cebb778 100644 --- a/tooling/cleanup.ts +++ b/tooling/cleanup.ts @@ -3,7 +3,7 @@ import { readdirSync, rmSync, renameSync } from "fs"; const libFiles = readdirSync("./build"); for (const file of libFiles) { - if (!file.startsWith("index.min.js")) { + if (!file.startsWith("Binato.min.js")) { rmSync(`./build/${file}`, { recursive: true }); } } diff --git a/tooling/fileSmasher.ts b/tooling/fileSmasher.ts index b1ca63b..406681f 100644 --- a/tooling/fileSmasher.ts +++ b/tooling/fileSmasher.ts @@ -5,6 +5,8 @@ import { readdirSync, lstatSync, readFileSync, writeFileSync } from "fs"; let tsFileData:Array = new Array(); +const tsEvenFirsterData:Array = new Array(); +const tsVeryFirstData:Array = new Array(); const tsFirstFileData:Array = new Array(); const tsLastFileData:Array = new Array(); const tsEverythingElse:Array = new Array(); @@ -23,7 +25,11 @@ function readDir(nam:string) { } else if (file.endsWith(".ts")) { if (file == "Binato.ts") { tsLastFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString()); - } else if (nam.includes("enum") || nam.includes("packets") || file.includes("FunkyArray") || file.includes("SpectatorManager") || file.includes("Shared")) { + } else if (nam.includes("commands") || file.includes("ConsoleHelper")) { + tsEvenFirsterData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString()); + } else if (file.includes("FunkyArray") || file.includes("ChatManager") || file.includes("MultiplayerManager") || file === "Bot.ts") { + tsVeryFirstData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString()); + } else if (nam.includes("enum") || nam.includes("packets") || (nam.includes("objects") && !file.includes("FunkyArray") ) || file.includes("SpectatorManager")) { tsFirstFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString()); } else { tsEverythingElse.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString()); @@ -34,7 +40,7 @@ function readDir(nam:string) { readDir("./"); -tsFileData = tsFileData.concat(tsFirstFileData).concat(tsEverythingElse).concat(tsLastFileData); +tsFileData = tsFileData.concat(tsEvenFirsterData).concat(tsVeryFirstData).concat(tsFirstFileData).concat(tsEverythingElse).concat(tsLastFileData); const combinedFiles = tsFileData.join("\n"); diff --git a/tooling/mangle.ts b/tooling/mangle.ts index 73da792..a8dba8d 100644 --- a/tooling/mangle.ts +++ b/tooling/mangle.ts @@ -1,10 +1,17 @@ import { readFileSync, writeFileSync } from "fs"; import { minify } from "terser"; -(async () => { - const mangled = await minify(readFileSync("./build/combined.js").toString(), { - mangle: true, - toplevel: true, - }); - writeFileSync("./build/index.min.js", `${mangled.code}`); -})(); \ No newline at end of file +const DISABLE = false; + +if (DISABLE) { + writeFileSync("./build/Binato.min.js", readFileSync("./build/combined.js")); + console.warn("[WARNING] mangle.ts is disabled!"); +} else { + (async () => { + const mangled = await minify(readFileSync("./build/combined.js").toString(), { + mangle: true, + toplevel: true, + }); + writeFileSync("./build/Binato.min.js", `${mangled.code}`); + })(); +} \ No newline at end of file