diff --git a/src/mod-manager.ts b/src/mod-manager.ts index 7601565..e8b5fd7 100644 --- a/src/mod-manager.ts +++ b/src/mod-manager.ts @@ -10,6 +10,7 @@ import {Logger, pino} from "pino" import {ListCommand} from "./commands/list_command.js"; import UninstallCommand from "./commands/uninstall_command.js"; import EssentialCommand from "./commands/essential_command.js"; +import {readFileSync, unlinkSync} from "fs"; export default class ModManager { @@ -57,6 +58,14 @@ export default class ModManager { setTimeout(() => process.exit(1), 1) }) + // If no errors are logged, cleanup the log file when the process exits + process.on("exit", () => { + // If file is only whitespace, i.e. blank + if (!readFileSync(this.LOG_FILE, "utf-8").trim().length) { + unlinkSync(this.LOG_FILE) + } + }) + return logger; } }