fix: wrong file handling for builds
This commit is contained in:
+22
-7
@@ -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<CommandCategoryInfo | undefined> {
|
||||
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<Command | null> {
|
||||
|
||||
Reference in New Issue
Block a user