#!/usr/bin/env node import { readFileSync, writeFileSync } from "fs" import { join, dirname } from "path" import { fileURLToPath } from "url" const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) /** * Update change-notes in plugin.xml based on version from gradle.properties and CHANGELOG.md */ function updateChangeNotes() { try { // Read version from gradle.properties const gradlePropertiesPath = join(__dirname, "../gradle.properties") const gradlePropertiesContent = readFileSync(gradlePropertiesPath, "utf8") const gradleVersionMatch = gradlePropertiesContent.match(/^pluginVersion=(.+)$/m) if (!gradleVersionMatch) { throw new Error("pluginVersion not found in gradle.properties") } const version = gradleVersionMatch[1].trim() console.log(`Found plugin version: ${version}`) // Read CHANGELOG.md const changelogPath = join(__dirname, "../../../CHANGELOG.md") const changelogContent = readFileSync(changelogPath, "utf8") // Find the version section in changelog const versionPattern = new RegExp(`## \\[v${version.replace(/\./g, "\\.")}\\]([\\s\\S]*?)(?=## \\[v|$)`) const changelogVersionMatch = changelogContent.match(versionPattern) if (!changelogVersionMatch) { throw new Error(`Version ${version} not found in CHANGELOG.md`) } const changelogSection = changelogVersionMatch[1].trim() console.log(`Found changelog section for version ${version}`) // Convert markdown to HTML format suitable for plugin.xml const changeNotesHtml = convertMarkdownToHtml(changelogSection, version) // Read plugin.xml.template const pluginXmlTemplatePath = join(__dirname, "../src/main/resources/META-INF/plugin.xml.template") const pluginXmlTemplateContent = readFileSync(pluginXmlTemplatePath, "utf8") // Replace {{CHANGE_NOTES}} placeholder with generated HTML const updatedPluginXml = pluginXmlTemplateContent.replace(/\{\{CHANGE_NOTES\}\}/g, changeNotesHtml) // Write updated plugin.xml const pluginXmlPath = join(__dirname, "../src/main/resources/META-INF/plugin.xml") writeFileSync(pluginXmlPath, updatedPluginXml, "utf8") console.log(`✅ Successfully updated change-notes for version ${version} in plugin.xml`) } catch (error) { console.error("❌ Error updating change-notes:", error.message) process.exit(1) } } /** * Convert markdown changelog to HTML format suitable for plugin.xml */ function convertMarkdownToHtml(markdown, version) { let html = `