import { Glob } from 'bun'; import { join } from 'node:path'; import type { ApplicationCommandStructure } from '@projectdysnomia/dysnomia'; import type { CommandHandler } from '../types'; export async function importCommands( pattern: string = '**/*.command.{js,ts,jsx,tsx}', baseDir: string = join(process.cwd(), 'src'), commandRegistry: Record> = {}, ): Promise>> { const glob = new Glob(pattern); for await (const file of glob.scan({ cwd: baseDir, absolute: true })) { const command = (await import(file)).default as CommandHandler; commandRegistry[command.definition.name] = command; } return commandRegistry; }