From 6ad0ba534077dd25e822daa58098f394dc60794d Mon Sep 17 00:00:00 2001 From: neru Date: Sat, 10 Jan 2026 11:13:02 -0300 Subject: [PATCH] fix: wrong file handling for builds --- src/commands.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 4e2f1dc..8d2846e 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -33,7 +33,7 @@ export interface Command { builder?: SlashCommandOptionsOnlyBuilder; } -interface CommandCategoryInfo { +export interface CommandCategoryInfo { name: string; description: string; } @@ -144,12 +144,21 @@ export class CommandManager { catPath: string ): Promise { try { - const descriptorPath = path.join(catPath, 'category.json'); - if (!fs.existsSync(descriptorPath)) - throw new Error('Missing categoryinfo.json'); + const extensions = ['js', 'mjs', 'cjs', 'ts']; - const content = await fs.promises.readFile(descriptorPath, 'utf-8'); - return JSON.parse(content) as CommandCategoryInfo; + for (const ext of extensions) { + const descriptorPath = path.join(catPath, `_category.${ext}`); + if (!fs.existsSync(descriptorPath)) continue; + + const module = await import(`file://${descriptorPath}`); + return ( + module.default?.default || + module.default || + (module as CommandCategoryInfo) + ); + } + + throw new Error('Missing categoryinfo.json'); } catch (err) { this.log.error('Error loading category info at %s: %s', catPath, err); return undefined; @@ -170,7 +179,13 @@ export class CommandManager { cmd parsing */ private isValidCommandFile(file: string): boolean { - return file.endsWith('.js') || file.endsWith('.ts'); + if (file.endsWith('.d.ts')) return false; + return ( + file.endsWith('.js') || + file.endsWith('.ts') || + file.endsWith('.mjs') || + file.endsWith('.cjs') + ); } private async attemptLoadCommand(filePath: string): Promise {