const fs = require("fs");
const path = require("path");

const changelogPath = path.resolve("CHANGELOG.md");
const commitMsgPath = path.resolve(".git", "COMMIT_EDITMSG");
const packageJson = require("../package.json");

const commitMsg = fs.readFileSync(commitMsgPath, "utf-8").trim();
const version = packageJson.version;
const date = new Date().toISOString().split("T")[0]; // YYYY-MM-DD

const newEntry = `## [${version}] – ${date}\n\n- ${commitMsg}\n\n---\n`;

const oldChangelog = fs.readFileSync(changelogPath, "utf-8");
fs.writeFileSync(changelogPath, newEntry + oldChangelog, "utf-8");

console.log("✅ CHANGELOG.md aktualisiert mit Commit-Message:", commitMsg);
