import * as fs from "mz/fs" ; import * as path from "path" ; import { Command } from "./command" ; import { NameTransformer } from "./nameTransformer" ; /**
 * Searches for Command classes.
 */ export class CommandSearcher { /**
     * Directories to search within.
     */ private readonly directories : string [ ] ; /**
     * Transforms dashed-case names to camelCase.
     */ private readonly nameTransformer : NameTransformer ; param nameTransformer param directories public constructor ( directories , nameTransformer = new NameTransformer ( ) ) { this . nameTransformer = nameTransformer ; this . directories = directories ; } param name template TCommand returns public async search < TCommand extends Command > ( name ) { const camelCaseName = this . nameTransformer . toCamelCase ( name ) ; for ( const directory of this . directories ) { const joinedPath = path . join ( directory , `${ camelCaseName }.js` ) ; if ( await fs . exists ( joinedPath ) ) { return require ( joinedPath ) [ this . nameTransformer . toPascalCase ( name ) ] ; } } return undefined ; } }