import { Server } from 'socket.io' import { CommandRegistry } from '#application/console/commandRegistry' import { ConsolePrompt } from '#application/console/consolePrompt' import { LogReader } from '#application/console/logReader' import Logger, { LoggerType } from '#application/logger' import SocketManager from '#managers/socketManager' export class ConsoleManager { private readonly logger = Logger.type(LoggerType.COMMAND) private readonly registry: CommandRegistry private readonly prompt: ConsolePrompt private readonly logReader: LogReader private io: Server | null = null constructor() { this.registry = new CommandRegistry() this.prompt = new ConsolePrompt((command: string) => this.processCommand(command)) this.logReader = new LogReader(process.cwd()) } public async boot(): Promise { this.io = SocketManager.getIO() await this.registry.loadCommands() this.logReader.start() this.prompt.start() this.logger.info('Console manager loaded') } private async processCommand(commandLine: string): Promise { const [cmd, ...args] = commandLine.trim().split(' ') if (cmd === 'exit') { this.prompt.close() return } const CommandClass = this.registry.getCommand(cmd) if (!CommandClass) { console.error(`Unknown command: ${cmd}`) return } try { const commandInstance = new CommandClass(this.io as Server) await commandInstance.execute(args) } catch (error) { this.logger.error(`Error executing command ${cmd}: ${error instanceof Error ? error.message : String(error)}`) } } } export default new ConsoleManager()