File size: 1,632 Bytes
8850458
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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]) {
  # 新結構:頂層陣列,metadata 存在 data/metadata.json
  $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 {
  # 舊結構:含 metadata 與 vocabulary_by_importance
  $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)"
}