修正:changelog 產生器保留既有紀錄,避免部署後更新紀錄被清空
根本原因:Docker build 內沒有 .git,generate-changelog 讀不到 git log 時會把 changelog.json 覆蓋成空清單,導致正式站的更新紀錄分頁變成空白。 影響:正式版更新紀錄分頁的資料完整性;package.json 的 npm start 行為與縮排格式。 修法: - git 取不到資料(或 0 筆)且既有 changelog.json 非空時,直接沿用不覆蓋 - package.json 的 start 改為 npm run dev,縮排統一為 tab Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"start": "node server/server.mjs"
|
||||
"start": "npm run dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"concurrently": "^9.2.1",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// 從 git log 產生更新紀錄資料,輸出到 src/data/changelog.json
|
||||
// 正式版(build 後)沒有 git 也能直接讀 JSON 顯示;dev 與 build 前會自動重新產生。
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { mkdirSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
@@ -35,13 +35,33 @@ function readGitLog() {
|
||||
})
|
||||
}
|
||||
|
||||
// 讀取既有的 changelog.json(Docker build 內由 COPY . . 帶進來),取不到時回傳 null。
|
||||
function readExisting() {
|
||||
try {
|
||||
const data = JSON.parse(readFileSync(outFile, 'utf8'))
|
||||
return Array.isArray(data.entries) ? data.entries : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
let entries = []
|
||||
|
||||
try {
|
||||
entries = readGitLog()
|
||||
} catch (error) {
|
||||
console.warn('[generate-changelog] 讀取 git log 失敗,輸出空清單:', error.message)
|
||||
console.warn('[generate-changelog] 讀取 git log 失敗:', error.message)
|
||||
}
|
||||
|
||||
// git 取不到(或拿到 0 筆,常見於 Docker build 內沒有 .git)時,
|
||||
// 若已有非空的 changelog.json 就沿用,避免把好資料覆蓋成空清單。
|
||||
if (entries.length === 0) {
|
||||
const existing = readExisting()
|
||||
if (existing && existing.length > 0) {
|
||||
console.log(`[generate-changelog] git 無資料,保留既有 ${existing.length} 筆更新紀錄不覆蓋`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
|
||||
Reference in New Issue
Block a user