This commit is contained in:
xiaojibeier
2026-07-13 16:45:11 +08:00
parent a4a9f2e36c
commit 0e21232b38
21 changed files with 4603 additions and 1 deletions
+56
View File
@@ -0,0 +1,56 @@
/**
* 生产 11 位构建号:YYYYMMDD(8)+ 当日第几次构建(3 位 001~999)
*/
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const root = path.resolve(__dirname, '..')
const statePath = path.join(root, 'build', 'build-sequence.json')
const outPath = path.join(root, 'src', 'config', 'buildId.json')
const now = new Date()
const y = now.getFullYear()
const m = String(now.getMonth() + 1).padStart(2, '0')
const d = String(now.getDate()).padStart(2, '0')
const ymd8 = `${y}${m}${d}`
const todayKey = `${y}-${m}-${d}`
let state = { date: todayKey, daySeq: 0 }
if (fs.existsSync(statePath)) {
try {
const prev = JSON.parse(fs.readFileSync(statePath, 'utf8'))
if (prev && typeof prev === 'object') {
state.date = prev.date || todayKey
state.daySeq = Number.isFinite(prev.daySeq) ? prev.daySeq : 0
}
} catch { /* 忽略损坏文件 */ }
}
if (state.date === todayKey) {
state.daySeq = (state.daySeq || 0) + 1
} else {
state.date = todayKey
state.daySeq = 1
}
if (state.daySeq > 999) {
console.warn('[bump-build-id] 当日构建已超过 999 次,已钳位为 999')
state.daySeq = 999
}
const buildId = `${ymd8}${String(state.daySeq).padStart(3, '0')}`
fs.mkdirSync(path.dirname(statePath), { recursive: true })
fs.writeFileSync(statePath, JSON.stringify(state, null, 2), 'utf8')
fs.mkdirSync(path.dirname(outPath), { recursive: true })
fs.writeFileSync(
outPath,
JSON.stringify(
{ buildId, generatedAt: new Date().toISOString() },
null,
2,
),
'utf8',
)
console.log(`[bump-build-id] buildId=${buildId}`)