From e8d8b449cee636bd759acd4d2c7f54f17ea9eba0 Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 11 Aug 2025 21:17:26 +0200 Subject: [PATCH] Refactor --- scripts/build.ts | 8 +------- src/enviroment.d.ts | 8 +------- src/utils/Illegitimate.ts | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index e0ed768..56d13dc 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -21,17 +21,11 @@ const files = [ eventFiles.map(f => `src/events/${f}`) ].flat() -const banner = [ - "const bun__build = true", - process.env.DOCKER === "1" ? "const bun__docker = true" : null -].filter(v => typeof v === "string").join("\n") - await Bun.build({ entrypoints: ["src/index.ts", ...files], outdir: "dist", target: "bun", splitting: true, - minify: true, sourcemap: process.env.NODE_ENV === "dev" ? "external" : undefined, naming: { entry: "[dir]/[name].[ext]", @@ -39,5 +33,5 @@ await Bun.build({ asset: "asset/[name]-[hash].[ext]" }, root: "src", - banner + banner: process.env.DOCKER === "1" ? "process.env.BUN__DOCKER = 'true'" : undefined }) diff --git a/src/enviroment.d.ts b/src/enviroment.d.ts index 8b47b85..047cc02 100644 --- a/src/enviroment.d.ts +++ b/src/enviroment.d.ts @@ -3,8 +3,7 @@ declare global { interface ProcessEnv { NODE_ENV?: "dev" | "prod" TYPESCRIPT?: "true" - BUILD?: "true" - DOCKER?: "1" + BUN__DOCKER?: "true" } } } @@ -16,9 +15,4 @@ declare global { } } -declare global { - const bun__build: boolean | undefined - const bun__docker: boolean | undefined -} - export {} diff --git a/src/utils/Illegitimate.ts b/src/utils/Illegitimate.ts index db10c82..9d26c31 100644 --- a/src/utils/Illegitimate.ts +++ b/src/utils/Illegitimate.ts @@ -1,4 +1,5 @@ import { RedisClient } from "bun" +import { LoadEventsOptions } from "~/typings" import { ExtendedClient as Client } from "~/utils/Client" import env from "./Env" import loadAllEvents from "./Events/loadevents" @@ -7,12 +8,9 @@ import { log } from "./Logger" const client = new Client() const redis = new RedisClient(env.prod.REDISURI) -const ft = bun__build !== true ? "ts" : "js" -const dir = bun__docker !== true ? bun__build !== true ? "src" : "dist" : "" - class Illegitimate { async start() { - await loadAllEvents(client, { ft, dir }) + await loadAllEvents(client, this.getOpts()) await client.start() await this.databases() this.loadMethods() @@ -28,6 +26,20 @@ class Illegitimate { }) } + private getOpts(): LoadEventsOptions { + if (process.env.BUN__DOCKER === "true") { + return { + ft: "js", + dir: "" + } + } else { + return { + ft: "ts", + dir: "src" + } + } + } + private loadMethods() { String.prototype.removeIndents = function(this: string) { return this.replace(/^ */gm, "")