| | Param( |
| | [string]$Version |
| | ) |
| |
|
| | $ErrorActionPreference = 'Stop' |
| |
|
| | $root = Split-Path $PSScriptRoot -Parent |
| | $jsonPath = Join-Path $root 'data' 'toeic_vocabulary.json' |
| | if (!(Test-Path $jsonPath)) { throw "找不到資料檔:$jsonPath" } |
| |
|
| | $data = Get-Content -Path $jsonPath -Raw -Encoding UTF8 | ConvertFrom-Json |
| |
|
| | if ($data -is [System.Array]) { |
| | |
| | $total = @($data).Count |
| | $metaPath = Join-Path $root 'data' 'metadata.json' |
| | if (Test-Path $metaPath) { |
| | $meta = Get-Content -Path $metaPath -Raw -Encoding UTF8 | ConvertFrom-Json |
| | } else { |
| | $meta = [ordered]@{} |
| | } |
| | $meta.total_words = $total |
| | $meta.last_updated = (Get-Date).ToString('o') |
| | if ($Version) { $meta.version = $Version } |
| | ($meta | ConvertTo-Json -Depth 100) | Set-Content -Path $metaPath -Encoding UTF8 |
| | Write-Host "已更新 metadata.json:total_words=$total; version=$($meta.version); last_updated=$($meta.last_updated)" |
| | } else { |
| | |
| | $total = 0 |
| | foreach ($prop in $data.vocabulary_by_importance.PSObject.Properties) { |
| | $items = $prop.Value |
| | if ($items -is [System.Collections.IEnumerable]) { |
| | $total += @($items).Count |
| | } |
| | } |
| | $data.metadata.total_words = $total |
| | $data.metadata.last_updated = (Get-Date).ToString('o') |
| | if ($Version) { $data.metadata.version = $Version } |
| | $jsonOut = $data | ConvertTo-Json -Depth 100 |
| | Set-Content -Path $jsonPath -Value $jsonOut -Encoding UTF8 |
| | Write-Host "已更新 metadata:total_words=$total; version=$($data.metadata.version); last_updated=$($data.metadata.last_updated)" |
| | } |
| |
|