1
0
forked from noxious/server
This commit is contained in:
Dennis Postma 2024-12-28 21:26:31 +01:00
parent 4f1b9cf024
commit 5c94584cb2
4 changed files with 12 additions and 15 deletions

View File

@ -1,5 +1,6 @@
import * as fs from 'fs'
import * as path from 'path'
import Logger, { LoggerType } from '#application/logger'
import { getAppPath } from '#application/storage'
import { Command } from '#application/types'
@ -18,11 +19,7 @@ export class CommandRegistry {
try {
const files = await fs.promises.readdir(directory, { withFileTypes: true })
await Promise.all(
files
.filter(file => this.isValidCommandFile(file))
.map(file => this.loadCommandFile(file))
)
await Promise.all(files.filter((file) => this.isValidCommandFile(file)).map((file) => this.loadCommandFile(file)))
} catch (error) {
this.logger.error(`Failed to read commands directory: ${error instanceof Error ? error.message : String(error)}`)
}
@ -56,4 +53,4 @@ export class CommandRegistry {
this.commands.set(name, CommandClass)
this.logger.info(`Registered command: ${name}`)
}
}
}

View File

@ -30,4 +30,4 @@ export class ConsolePrompt {
this.promptCommand()
})
}
}
}

View File

@ -1,5 +1,6 @@
import * as fs from 'fs'
import * as path from 'path'
import Logger, { LoggerType } from '#application/logger'
export class LogReader {
@ -17,7 +18,7 @@ export class LogReader {
}
public stop(): void {
this.watchers.forEach(watcher => watcher.close())
this.watchers.forEach((watcher) => watcher.close())
this.watchers = []
}
@ -33,8 +34,8 @@ export class LogReader {
// Watch existing files
try {
fs.readdirSync(this.logsDirectory)
.filter(file => file.endsWith('.log'))
.forEach(file => this.watchLogFile(file))
.filter((file) => file.endsWith('.log'))
.forEach((file) => this.watchLogFile(file))
} catch (error) {
this.logger.error(`Error reading logs directory: ${error}`)
}
@ -73,4 +74,4 @@ export class LogReader {
this.watchers.push(watcher)
}
}
}

View File

@ -1,4 +1,5 @@
import { Server } from 'socket.io'
import { CommandRegistry } from '#application/console/commandRegistry'
import { ConsolePrompt } from '#application/console/consolePrompt'
import { LogReader } from '#application/console/logReader'
@ -13,9 +14,7 @@ export class ConsoleManager {
constructor() {
this.registry = new CommandRegistry()
this.prompt = new ConsolePrompt(
(command: string) => this.processCommand(command)
)
this.prompt = new ConsolePrompt((command: string) => this.processCommand(command))
this.logReader = new LogReader(process.cwd())
}
@ -53,4 +52,4 @@ export class ConsoleManager {
}
}
export default new ConsoleManager()
export default new ConsoleManager()