From b779d3c3712c36886e0aa999385066c381289e26 Mon Sep 17 00:00:00 2001 From: Cat++ <69035887+NotGhex@users.noreply.github.com> Date: Sun, 14 Jul 2024 11:35:32 +0800 Subject: [PATCH] Use relative path in logs --- packages/core/src/classes/structures/RecipleModule.ts | 8 +++++++- packages/reciple/src/utils/logger.ts | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/core/src/classes/structures/RecipleModule.ts b/packages/core/src/classes/structures/RecipleModule.ts index edf5cc63..82c15c00 100644 --- a/packages/core/src/classes/structures/RecipleModule.ts +++ b/packages/core/src/classes/structures/RecipleModule.ts @@ -7,6 +7,7 @@ import { RecipleError } from './RecipleError.js'; import { kleur } from 'fallout-utility/strings'; import { Utils } from './Utils.js'; import semver from 'semver'; +import path from 'node:path'; export interface RecipleModuleData { /** @@ -71,9 +72,10 @@ export class RecipleModule { readonly file?: string; public status: RecipleModuleStatus = RecipleModuleStatus.Unloaded; + private root?: string; get name(): string|undefined { return this.data.name; } - get displayName(): string { return this.name ?? this.file ?? this.id; } + get displayName(): string { return this.name ?? (this.file && this.root ? path.relative(this.root, this.file) : this.file) ?? this.id; } get versions(): string[] { return normalizeArray([this.data.versions ?? 'latest'] as RestOrArray); } get commands(): AnyCommandBuilder[] { return this.data.commands?.map(c => Utils.resolveCommandBuilder(c)) ?? []; } get supported(): boolean { return this.versions.some(v => v === "latest" || semver.satisfies(this.client.version, v)); } @@ -142,4 +144,8 @@ export class RecipleModule { status: this.status }; } + + public static getModuleRoot(module: RecipleModule): string|null { + return module.root ?? null; + } } diff --git a/packages/reciple/src/utils/logger.ts b/packages/reciple/src/utils/logger.ts index 1250e1a6..5c05ea7c 100644 --- a/packages/reciple/src/utils/logger.ts +++ b/packages/reciple/src/utils/logger.ts @@ -1,6 +1,7 @@ import { Logger, LoggerLevel, kleur, type PartialDeep } from 'fallout-utility'; import type { RecipleConfig } from '../classes/Config.js'; import { type RecipleClient } from '../index.js'; +import { RecipleModule } from '@reciple/core'; import { cli } from './cli.js'; import path from 'node:path'; @@ -81,7 +82,11 @@ export function addEventListenersToClient(client: RecipleClient): void { client.modules.on('resolveModuleFileError', (file, error) => client.logger?.err(`Failed to resolve module ${kleur.yellow(quoteString(file))}:`, error)); - client.modules.on('preStartModule', (m) => client.logger?.debug(`Starting module ${kleur.cyan(quoteString(m.displayName))}`)); + client.modules.on('preStartModule', (m) => { + if (!RecipleModule.getModuleRoot(m)) Reflect.set(m, 'root', cli.cwd); + client.logger?.debug(`Starting module ${kleur.cyan(quoteString(m.displayName))}`); + }); + client.modules.on('postStartModule', (m) => client.logger?.log(`Started module ${kleur.cyan(quoteString(m.displayName))}`)); client.modules.on('startModuleError', (m, err) => client.logger?.error(`Failed to start module ${kleur.yellow(quoteString(m.displayName))}:`, err));