UNPKG

@megaorm/cli

Version:

This package allows you to communicate with MegaORM via commands directly from the command line interface (CLI).

53 lines (52 loc) 2.47 kB
/** * Custom error class for handling errors related to command operations. */ export declare class CommandHandlerError extends Error { } /** * This class provides functionality for adding, and removing command files * */ export declare class CommandHandler { /** * The absolute path to the assets directory. */ private assets; /** * Instantiates a new CommandHandler. */ constructor(); /** * Collects the absolute paths of command files from the specified directory. * * @param path The directory path from which to collect command files. * @param map A boolean indicating whether to include mapped files (e.g., `.js.map`) in the resulting paths. * @returns A promise that resolves with an array of absolute paths to valid command files. * @throws `CommandHandlerError` if there is an issue collecting the files or if an invalid command file is encountered. */ private collectPaths; /** * Creates a new command file in the specified path. * * This method creates a new file for the specified command name in the given directory path. * You can choose to create a TypeScript file or a JavaScript file based on the provided boolean flag. * * @param name The PascalCase command name. * @param path The directory path where the command file will be created. * @param ts A boolean indicating whether to create a TypeScript file (`true`) or a JavaScript file (`false`). * @returns A promise that resolves with a success message indicating the path of the created command file. * @throws `CommandHandlerError` if the command name is invalid, the path is empty, or if any errors occur during file operations. * @note The command name must be in PascalCase, e.g., FetchCommand, RollbackCommand. */ add(name: string, path: string, ts?: boolean): Promise<string>; /** * Removes the command file in the specified path. * * @param name The PascalCase command name to be removed. * @param path The directory path where the command files are located. * @returns A promise that resolves with a success message indicating how many command files were removed. * @throws `CommandHandlerError` if the command name is invalid, the path is empty. * @note The command name must be in PascalCase, e.g., FetchCommand, RollbackCommand. */ remove(name: string, path: string): Promise<string>; }