Skip to main content
Version: Next

CommandsRouter

CommandsRouter

CommandsRouter handles the discovery and routing of commands and middleware files in a directory structure. It supports nested commands and middleware inheritance.

new CommandsRouter(options)
ParameterTypeOptionalDescription
optionsCommandsRouterOptionsConfiguration options for the router

Properties

public entrypoint: any

Gets the configured entrypoint directory

public matchers: any

Gets the configured matchers for command and middleware files

Methods

public clear(): void

Clears the internal commands and middleware maps

public getData(): {

commands | : Map<string | ParsedCommand>; middleware | : Map<string | ParsedMiddleware>; } Returns the cached data of the commands and middleware

public isValidPath(): boolean

Checks if the entrypoint path is valid

public match(commandOrSegment): null | CommandMatchResult

Matches a command by name or path segments

ParameterTypeOptionalDescription
commandOrSegmentstringArray<string>

public reload(): Promise<CommandsTree>

Reloads the commands tree by re-scanning the entrypoint directory

public scan(): Promise<CommandsTree>

Scans the entrypoint directory for commands and middleware

public toJSON(): CommandsTree

Converts the internal maps to a serializable object