build fixes

This commit is contained in:
Holly Stubbs 2023-09-10 20:37:46 +01:00
parent 3070f6a742
commit 4a6d698b47
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
6 changed files with 34 additions and 15 deletions

View file

@ -1,10 +1,8 @@
console.clear();
import { ConsoleHelper } from "./ConsoleHelper"; import { ConsoleHelper } from "./ConsoleHelper";
import { readFileSync, existsSync } from "fs"; import { readFileSync, existsSync } from "fs";
if (!existsSync("./config.json")) { if (!existsSync("./config.json")) {
ConsoleHelper.printError("You must have a config file in the root of Binato's folder structure."); ConsoleHelper.printError("Config file missing!");
ConsoleHelper.printError("Check the GitHub for an example file"); ConsoleHelper.printError("Check the GitHub for an example or create one with the example you have.");
process.exit(1); process.exit(1);
} }

View file

@ -1,5 +1,7 @@
import * as dyetty from "dyetty"; import * as dyetty from "dyetty";
console.clear();
enum LogType { enum LogType {
INFO, INFO,
WARN, WARN,

View file

@ -4,11 +4,12 @@ import Database from "../objects/Database";
import DataStreamArray from "../objects/DataStreamArray"; import DataStreamArray from "../objects/DataStreamArray";
import MultiplayerManager from "../MultiplayerManager"; import MultiplayerManager from "../MultiplayerManager";
import PrivateChatManager from "../PrivateChatManager"; import PrivateChatManager from "../PrivateChatManager";
import { readFileSync } from "fs"; import { existsSync, readFileSync } from "fs";
import UserArray from "../objects/UserArray"; import UserArray from "../objects/UserArray";
import User from "./User"; import User from "./User";
import LatLng from "./LatLng"; import LatLng from "./LatLng";
import Bot from "../Bot"; import Bot from "../Bot";
import { ConsoleHelper } from "../../ConsoleHelper";
export default class Shared { export default class Shared {
public readonly chatManager:ChatManager; public readonly chatManager:ChatManager;
@ -21,6 +22,11 @@ export default class Shared {
public readonly bot:Bot; public readonly bot:Bot;
public constructor() { 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.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.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(); this.streams = new DataStreamArray();

View file

@ -3,7 +3,7 @@ import { readdirSync, rmSync, renameSync } from "fs";
const libFiles = readdirSync("./build"); const libFiles = readdirSync("./build");
for (const file of libFiles) { for (const file of libFiles) {
if (!file.startsWith("index.min.js")) { if (!file.startsWith("Binato.min.js")) {
rmSync(`./build/${file}`, { recursive: true }); rmSync(`./build/${file}`, { recursive: true });
} }
} }

View file

@ -5,6 +5,8 @@
import { readdirSync, lstatSync, readFileSync, writeFileSync } from "fs"; import { readdirSync, lstatSync, readFileSync, writeFileSync } from "fs";
let tsFileData:Array<string> = new Array<string>(); let tsFileData:Array<string> = new Array<string>();
const tsEvenFirsterData:Array<string> = new Array<string>();
const tsVeryFirstData:Array<string> = new Array<string>();
const tsFirstFileData:Array<string> = new Array<string>(); const tsFirstFileData:Array<string> = new Array<string>();
const tsLastFileData:Array<string> = new Array<string>(); const tsLastFileData:Array<string> = new Array<string>();
const tsEverythingElse:Array<string> = new Array<string>(); const tsEverythingElse:Array<string> = new Array<string>();
@ -23,7 +25,11 @@ function readDir(nam:string) {
} else if (file.endsWith(".ts")) { } else if (file.endsWith(".ts")) {
if (file == "Binato.ts") { if (file == "Binato.ts") {
tsLastFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString()); 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()); tsFirstFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
} else { } else {
tsEverythingElse.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString()); tsEverythingElse.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
@ -34,7 +40,7 @@ function readDir(nam:string) {
readDir("./"); 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"); const combinedFiles = tsFileData.join("\n");

View file

@ -1,10 +1,17 @@
import { readFileSync, writeFileSync } from "fs"; import { readFileSync, writeFileSync } from "fs";
import { minify } from "terser"; import { minify } from "terser";
(async () => { 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(), { const mangled = await minify(readFileSync("./build/combined.js").toString(), {
mangle: true, mangle: true,
toplevel: true, toplevel: true,
}); });
writeFileSync("./build/index.min.js", `${mangled.code}`); writeFileSync("./build/Binato.min.js", `${mangled.code}`);
})(); })();
}