Skip to content

Commit

Permalink
Use relative path in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
catplvsplus committed Jul 14, 2024
1 parent 6152208 commit b779d3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/core/src/classes/structures/RecipleModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -71,9 +72,10 @@ export class RecipleModule<Data extends RecipleModuleData = RecipleModuleData> {
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<string>); }
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)); }
Expand Down Expand Up @@ -142,4 +144,8 @@ export class RecipleModule<Data extends RecipleModuleData = RecipleModuleData> {
status: this.status
};
}

public static getModuleRoot(module: RecipleModule): string|null {
return module.root ?? null;
}
}
7 changes: 6 additions & 1 deletion packages/reciple/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit b779d3c

Please sign in to comment.