Skip to main content
Version: 1.x

CommandsRouter

CommandsRouter

Handles discovery and parsing of command and middleware files in the filesystem.

Signature
class CommandsRouter {
constructor(options: CommandsRouterOptions)
populate(data: ParsedCommandData) => void;
isValidPath() => boolean;
clear() => void;
scan() => Promise<ParsedCommandData>;
scanIncremental(changedPath: string, _changeType: RouterFileChangeType = 'change') => Promise<ParsedCommandData>;
getData() => {
commands: Collection<string, Command>;
middlewares: Collection<string, Middleware>;
treeNodes: Collection<string, CommandTreeNode>;
compiledRoutes: Collection<string, CompiledCommandRoute>;
diagnostics: CommandRouteDiagnostic[];
};
getTreeData() => {
treeNodes: Collection<string, CommandTreeNode>;
compiledRoutes: Collection<string, CompiledCommandRoute>;
diagnostics: CommandRouteDiagnostic[];
};
toJSON() => ParsedCommandData;
}

constructor

method
(options: CommandsRouterOptions) => CommandsRouter

Creates a new CommandsRouter instance.

populate

method
(data: ParsedCommandData) => void

Populates the router with existing command, middleware, and tree data.

isValidPath

method
() => boolean

Checks if the configured entrypoint path exists.

clear

method
() => void

Clears all loaded commands, middleware, and compiled tree data.

scan

method
() => Promise<ParsedCommandData>

Scans the filesystem for commands and middleware files.

scanIncremental

method
(changedPath: string, _changeType: RouterFileChangeType = 'change') => Promise<ParsedCommandData>

Incrementally updates only the top-level command subtree affected by a file change. Falls back to a full scan when the changed path cannot be safely scoped.

getData

method
() => { commands: Collection<string, Command>; middlewares: Collection<string, Middleware>; treeNodes: Collection<string, CommandTreeNode>; compiledRoutes: Collection<string, CompiledCommandRoute>; diagnostics: CommandRouteDiagnostic[]; }

Gets the raw command, middleware, and compiled tree collections.

getTreeData

method
() => { treeNodes: Collection<string, CommandTreeNode>; compiledRoutes: Collection<string, CompiledCommandRoute>; diagnostics: CommandRouteDiagnostic[]; }

Gets only the internal command tree and compiled route data.

toJSON

method

Converts the loaded data to a JSON-serializable format.