erp-platform/ui/scripts/generate-version.js
2025-09-23 11:32:04 +03:00

67 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// scripts/write-version.js
import fs from 'fs'
import { execSync } from 'child_process'
function safeExec(cmd) {
try {
return execSync(cmd, { stdio: ['pipe', 'pipe', 'ignore'], shell: true })
.toString()
.trim()
} catch {
return null
}
}
let releases = []
let commit = null
if (fs.existsSync('.git') || fs.existsSync('../.git')) {
// Git varsa: taglerden oku
const rawTags = safeExec('git tag --list --sort=creatordate')
if (rawTags) {
const tags = rawTags.split('\n').filter(Boolean)
releases = tags.map((tag) => {
const version = tag.replace(/^v/, '')
const date = safeExec(`git log -1 --format=%ad --date=short ${tag}`)
const commitId = safeExec(`git rev-list -n 1 ${tag}`)
const messageRaw = safeExec(`git tag -l --format="%(contents)" ${tag}`)
const changeLog = messageRaw
? messageRaw
.split('\n')
.map((s) => s.trim())
.filter(Boolean)
: ['No changelog for this tag']
return {
version,
buildDate: date,
commit: commitId,
changeLog,
}
})
}
commit = safeExec('git rev-parse --short HEAD')
} else {
// Git yoksa (ör. dev build)
const pkg = JSON.parse(fs.readFileSync('package.json'))
const version = pkg.version || '0.0.0'
commit = process.env.GIT_COMMIT || 'dev-local'
releases = [
{
version,
buildDate: new Date().toISOString().slice(0, 10),
commit,
changeLog: [
'Local development build',
'Git bilgisi mevcut değil, package.json versiyonu kullanıldı',
],
},
]
}
const versionInfo = { commit, releases: releases.reverse() }
fs.writeFileSync('public/version.json', JSON.stringify(versionInfo, null, 2))
//console.log('> version.json güncellendi:', versionInfo)