fix: wrong file handling for builds
This commit is contained in:
+22
-7
@@ -33,7 +33,7 @@ export interface Command {
|
|||||||
builder?: SlashCommandOptionsOnlyBuilder;
|
builder?: SlashCommandOptionsOnlyBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CommandCategoryInfo {
|
export interface CommandCategoryInfo {
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
@@ -144,12 +144,21 @@ export class CommandManager {
|
|||||||
catPath: string
|
catPath: string
|
||||||
): Promise<CommandCategoryInfo | undefined> {
|
): Promise<CommandCategoryInfo | undefined> {
|
||||||
try {
|
try {
|
||||||
const descriptorPath = path.join(catPath, 'category.json');
|
const extensions = ['js', 'mjs', 'cjs', 'ts'];
|
||||||
if (!fs.existsSync(descriptorPath))
|
|
||||||
throw new Error('Missing categoryinfo.json');
|
|
||||||
|
|
||||||
const content = await fs.promises.readFile(descriptorPath, 'utf-8');
|
for (const ext of extensions) {
|
||||||
return JSON.parse(content) as CommandCategoryInfo;
|
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) {
|
} catch (err) {
|
||||||
this.log.error('Error loading category info at %s: %s', catPath, err);
|
this.log.error('Error loading category info at %s: %s', catPath, err);
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -170,7 +179,13 @@ export class CommandManager {
|
|||||||
cmd parsing
|
cmd parsing
|
||||||
*/
|
*/
|
||||||
private isValidCommandFile(file: string): boolean {
|
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> {
|
private async attemptLoadCommand(filePath: string): Promise<Command | null> {
|
||||||
|
|||||||
Reference in New Issue
Block a user