feat: add application entry point with config, database, and logger initialization

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
saopig1andClaude Opus 4.6 committed 2026-03-30 00:21:38 +08:00
1 parent 8727605036
commit 7c60bd69ef
1 file changed
+36
+36
View File
@@ -0,0 +1,36 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import { loadConfig, saveConfig } from "./data/config.js";
import { createDatabase } from "./data/database.js";
import { createLogger } from "./logger.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT_DIR = path.resolve(__dirname, "..");
const DATA_DIR = path.join(ROOT_DIR, "data");
const CONFIG_PATH = path.join(ROOT_DIR, "config.json");
const DB_PATH = path.join(DATA_DIR, "tsmusicbot.db");
const LOG_DIR = path.join(DATA_DIR, "logs");
async function main() {
const config = loadConfig(CONFIG_PATH);
saveConfig(CONFIG_PATH, config);
const logger = createLogger(LOG_DIR);
const db = createDatabase(DB_PATH);
logger.info({ webPort: config.webPort }, "TSMusicBot started");
const shutdown = () => {
logger.info("Shutting down...");
db.close();
process.exit(0);
};
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
}
main().catch((err) => {
console.error("Fatal error:", err);
process.exit(1);
});