diff --git a/src/commands.ts b/src/commands.ts index 8d2846e..573396a 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -168,7 +168,7 @@ export class CommandManager { private async loadCatCommands(catPath: string): Promise> { const promises = fs .readdirSync(catPath) - .filter((file) => this.isValidCommandFile(file)) + .filter((file) => isModule(file)) .map( async (file) => await this.attemptLoadCommand(path.join(catPath, file)) ); @@ -178,16 +178,6 @@ export class CommandManager { /* cmd parsing */ - private isValidCommandFile(file: string): boolean { - 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 { try { const module = await import(`file://${filePath}`); diff --git a/src/utils/misc.ts b/src/utils/misc.ts new file mode 100644 index 0000000..467c04c --- /dev/null +++ b/src/utils/misc.ts @@ -0,0 +1,9 @@ +const MOD_EXCLUDE: Array = ['.d.ts']; +const MOD_INCLUDE: Array = ['.ts', '.js', '.mjs', '.cjs']; +export function isModule(path: string): boolean { + for (const ext of MOD_EXCLUDE) if (path.endsWith(ext)) return false; + + for (const ext of MOD_INCLUDE) if (path.endsWith(ext)) return true; + + return false; +}