@adonisjs/ace
Version:
A CLI framework for Node.js
49 lines (48 loc) • 1.61 kB
TypeScript
import type { AbstractBaseCommand, CommandMetaData, LoadersContract } from '../types.ts';
/**
* Fs loader exposes the API to load commands from a directory. All files
* ending with ".js", ".cjs", ".mjs", ".ts" and ".mts" are considered
* as commands
*
* @example
* ```ts
* const loader = new FsLoader('./commands')
* const metadata = await loader.getMetaData()
* const command = await loader.getCommand(metadata[0])
* ```
*/
export declare class FsLoader<Command extends AbstractBaseCommand> implements LoadersContract<Command> {
#private;
/**
* Create a new filesystem loader
*
* @param comandsDirectory - Path to the directory containing command files
* @param filter - Optional filter function to exclude certain files
*/
constructor(comandsDirectory: string, filter?: (filePath: string) => boolean);
/**
* Returns the metadata of all commands in the directory
*
* @example
* ```ts
* const metadata = await loader.getMetaData()
* metadata.forEach(cmd => console.log(cmd.commandName))
* ```
*/
getMetaData(): Promise<CommandMetaData[]>;
/**
* Returns the command class constructor for a given command. Null
* is returned when unable to lookup the command
*
* @param metaData - The command metadata to find
*
* @example
* ```ts
* const command = await loader.getCommand(metadata)
* if (command) {
* const instance = new command(kernel, parsed, ui, prompt)
* }
* ```
*/
getCommand(metaData: CommandMetaData): Promise<Command | null>;
}