UNPKG

@visulima/cerebro

Version:

A delightful toolkit for building cross-runtime CLIs for Node.js, Deno, and Bun.

54 lines (53 loc) 1.89 kB
import type { Plugin, PluginContext } from "./types/plugin.d.ts"; import type { Toolbox } from "./types/toolbox.d.ts"; type Logger = Console; /** * Manages plugin lifecycle and execution */ declare class PluginManager<T extends Logger = Logger> { private readonly logger; private readonly plugins; private initialized; private cachedDependencyOrder; constructor(logger: T); /** * Checks if any plugins are registered. * @returns True if at least one plugin is registered */ hasPlugins(): boolean; /** * Registers a plugin. * @param plugin The plugin to register * @throws {Error} If plugin name is already registered or dependencies are invalid */ register(plugin: Plugin<T>): void; /** * Initializes all registered plugins. * @param context The plugin context for initialization */ init(context: PluginContext<T>): Promise<void>; /** * Executes a specific lifecycle hook for all plugins. * @param hook The lifecycle hook name * @param toolbox The command toolbox (for command-specific hooks) * @param result The command result (for afterCommand hook) */ executeLifecycle(hook: "beforeCommand" | "afterCommand" | "execute", toolbox: Toolbox<T>, result?: unknown): Promise<void>; /** * Executes error handlers for all plugins. * @param error The error that occurred * @param toolbox The command toolbox */ executeErrorHandlers(error: Error, toolbox: Toolbox<T>): Promise<void>; /** * Gets all registered plugins in dependency order. * @returns Array of plugins sorted by dependencies */ getDependencyOrder(): Plugin<T>[]; /** * Validates that all plugin dependencies exist. * @throws {Error} If any dependencies are missing */ private validateDependencies; } export default PluginManager;