summary refs log tree commit diff
path: root/src/bundle
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-10-27 23:30:14 +0100
committerRory& <root@rory.gay>2025-07-27 15:49:37 +0200
commitbd81cde9770e3d7c93b7b42f866b355c8b8bcbef (patch)
tree91a144f1de340b1e680253acca246d2558cc0dc9 /src/bundle
parentImplement CRUD for automod (diff)
downloadserver-ts-bd81cde9770e3d7c93b7b42f866b355c8b8bcbef.tar.xz
WIP logo/terminal stuff
Diffstat (limited to 'src/bundle')
-rw-r--r--src/bundle/Server.ts2
-rw-r--r--src/bundle/start.ts35
-rw-r--r--src/bundle/stats.ts36
3 files changed, 49 insertions, 24 deletions
diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts

index d7ba9260..8ef72750 100644 --- a/src/bundle/Server.ts +++ b/src/bundle/Server.ts
@@ -91,7 +91,7 @@ async function main() { Sentry.errorHandler(app); - console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`); + console.log(`[Server] ${green(`Listening on port ${bold(port)}`)}`); } main().catch(console.error); diff --git a/src/bundle/start.ts b/src/bundle/start.ts
index fe177cbc..33465abc 100644 --- a/src/bundle/start.ts +++ b/src/bundle/start.ts
@@ -18,6 +18,7 @@ // process.env.MONGOMS_DEBUG = "true"; import moduleAlias from "module-alias"; + moduleAlias(__dirname + "../../../package.json"); import "reflect-metadata"; @@ -26,8 +27,10 @@ import os from "os"; import { red, bold, yellow, cyan } from "picocolors"; import { initStats } from "./stats"; import { config } from "dotenv"; + config(); import { execSync } from "child_process"; +import { centerString, Logo } from "@spacebar/util"; const cores = process.env.THREADS ? parseInt(process.env.THREADS) : 1; @@ -41,23 +44,19 @@ function getCommitOrFail() { if (cluster.isPrimary) { const commit = getCommitOrFail(); - + Logo.printLogo(); console.log( bold(` -███████╗██████╗ █████╗ ██████╗███████╗██████╗ █████╗ ██████╗ -██╔════╝██╔══██╗██╔══██╗██╔════╝██╔════╝██╔══██╗██╔══██╗██╔══██╗ -███████╗██████╔╝███████║██║ █████╗ ██████╔╝███████║██████╔╝ -╚════██║██╔═══╝ ██╔══██║██║ ██╔══╝ ██╔══██╗██╔══██║██╔══██╗ -███████║██║ ██║ ██║╚██████╗███████╗██████╔╝██║ ██║██║ ██║ -╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ - - spacebar-server | ${yellow( - `Pre-release (${ - commit !== null - ? commit.slice(0, 7) - : "Unknown (Git cannot be found)" - })`, - )} +${centerString( + `spacebar-server | ${yellow( + `Pre-release (${ + commit !== null + ? commit.slice(0, 7) + : "Unknown (Git cannot be found)" + })`, + )}`, + 64, +)} Commit Hash: ${ commit !== null @@ -74,7 +73,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).) initStats(); - console.log(`[Process] starting with ${cores} threads`); + console.log(`[Process] Starting with ${cores} threads`); if (cores === 1) { require("./Server"); @@ -87,7 +86,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).) const delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000; setTimeout(() => { cluster.fork(); - console.log(`[Process] worker ${cyan(i)} started.`); + console.log(`[Process] Worker ${cyan(i)} started.`); }, delay); } @@ -102,7 +101,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).) cluster.on("exit", (worker) => { console.log( `[Worker] ${red( - `died with PID: ${worker.process.pid} , restarting ...`, + `PID ${worker.process.pid} died, restarting ...`, )}`, ); cluster.fork(); diff --git a/src/bundle/stats.ts b/src/bundle/stats.ts
index b690eb75..92e46027 100644 --- a/src/bundle/stats.ts +++ b/src/bundle/stats.ts
@@ -18,18 +18,44 @@ import os from "os"; import osu from "node-os-utils"; +import { readFileSync } from "node:fs"; import { red } from "picocolors"; export function initStats() { - console.log(`[Path] running in ${__dirname}`); + console.log(`[Path] Running in ${process.cwd()}`); + console.log(`[Path] Running from ${__dirname}`); try { - console.log(`[CPU] ${osu.cpu.model()} Cores x${osu.cpu.count()}`); + console.log(`[CPU] ${osu.cpu.model()} (x${osu.cpu.count()})`); } catch { - console.log("[CPU] Failed to get cpu model!"); + console.log("[CPU] Failed to get CPU model!"); } - console.log(`[System] ${os.platform()} ${os.arch()}`); - console.log(`[Process] running with PID: ${process.pid}`); + console.log(`[System] ${os.platform()} ${os.release()} ${os.arch()}`); + if (os.platform() == "linux") { + try { + const osReleaseLines = readFileSync( + "/etc/os-release", + "utf8", + ).split("\n"); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore + const osRelease: any = {}; + for (const line of osReleaseLines) { + if (!line) continue; + const [key, value] = line.match(/(.*?)="?([^"]*)"?/)!.slice(1); + osRelease[key] = value; + } + console.log( + `[System]\x1b[${osRelease.ANSI_COLOR}m ${osRelease.NAME ?? "Unknown"} ${osRelease.VERSION ?? "Unknown"} (${osRelease.BUILD_ID ?? "No build ID"})\x1b[0m`, + ); + } catch (e) { + console.log( + "[System] Unknown Linux distribution (missing /etc/os-release)", + ); + console.log(e); + } + } + console.log(`[Process] Running with PID: ${process.pid}`); if (process.getuid && process.getuid() === 0) { console.warn( red(