toeic-vocab-tw / scripts /release.ps1
LEE-WHITE's picture
Duplicate from kknono668/toeic-vocab-tw
8850458 verified
Param(
[string]$Version,
[string]$Message = "Release"
)
$ErrorActionPreference = 'Stop'
$root = Split-Path $PSScriptRoot -Parent
Set-Location $root
Write-Host "[1/4] 更新 metadata (version=$Version)" -ForegroundColor Cyan
& (Join-Path $PSScriptRoot 'update_metadata.ps1') -Version $Version
# 讀取更新後的總詞數與版本(兼容兩種結構)
$dataPath = Join-Path $root 'data' 'toeic_vocabulary.json'
$obj = Get-Content -Path $dataPath -Raw -Encoding UTF8 | ConvertFrom-Json
if ($obj -is [System.Array]) {
$total = @($obj).Count
$metaPath = Join-Path $root 'data' 'metadata.json'
$meta = if (Test-Path $metaPath) { Get-Content -Path $metaPath -Raw -Encoding UTF8 | ConvertFrom-Json } else { $null }
$v = if ($meta) { $meta.version } else { $Version }
} else {
$total = [int]$obj.metadata.total_words
$v = $obj.metadata.version
}
Write-Host "[2/4] 產生 Viewer 友善 JSON" -ForegroundColor Cyan
& (Join-Path $PSScriptRoot 'make_viewer_json.ps1')
Write-Host "[3/4] 更新 README 統計" -ForegroundColor Cyan
& (Join-Path $PSScriptRoot 'update_readme.ps1') -Version $v -TotalWords $total
Write-Host "[4/4] 提交並推送" -ForegroundColor Cyan
git add README.md data/toeic_vocabulary.json data/metadata.json data/toeic_vocabulary_view.json scripts/*.ps1 | Out-Null
$commitMsg = if ($Version) { "${Message} v${v}" } else { $Message }
git commit -m $commitMsg | Out-Null
git push -u origin main
Write-Host "完成發佈:$commitMsg" -ForegroundColor Green