erp-platform/ui/scripts/write-version.js

45 lines
1 KiB
JavaScript
Raw Normal View History

2025-09-19 20:36:10 +00:00
import fs from "fs"
import { execSync } from "child_process"
function safeExec(cmd) {
try {
return execSync(cmd, { stdio: ["pipe", "pipe", "ignore"] }).toString().trim()
} catch {
return null
}
}
// Tüm tag isimlerini al
const rawTags = safeExec("git tag --list --sort=creatordate")
if (!rawTags) {
console.log("> No git tags found, skipping version.json")
process.exit(0)
}
const tags = rawTags
.split("\n")
.filter(Boolean)
.map((tag) => {
const date = safeExec(`git log -1 --format=%ad --date=short ${tag}`)
const messageRaw = safeExec(`git tag -l --format="%(contents)" ${tag}`)
const changeLog = messageRaw
? messageRaw.split("\n").map((s) => s.trim()).filter(Boolean)
: []
return {
version: tag.replace(/^v/, ""), // v1.0.5 → 1.0.5
buildDate: date,
changeLog
}
})
const commit = safeExec("git rev-parse --short HEAD")
const versionInfo = {
commit,
releases: tags.reverse()
}
fs.writeFileSync("public/version.json", JSON.stringify(versionInfo, null, 2))