param([string]$Upstream = (Join-Path $PSScriptRoot '../upstream/SpaceNinjaServer'))
$ErrorActionPreference = 'Stop'
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$destination = Join-Path $taskRoot 'Server/data'
New-Item -ItemType Directory -Path $destination -Force | Out-Null
$prefixes = @{api='/api'; arbiter='/api'; custom='/custom'; dynamic='/dynamic'; pay='/pay'; stats='/stats'; publicExport='/PublicExport'}
$routes = @()
foreach ($name in $prefixes.Keys | Sort-Object) {
$file = Join-Path $Upstream "src/routes/$name.ts"
$source = Get-Content -LiteralPath $file -Raw
foreach ($match in [regex]::Matches($source, '(\w+)Router\.(get|post)\("([^"\r\n]+)",\s*(\w+)')) {
$routes += [ordered]@{method=$match.Groups[2].Value.ToUpperInvariant(); path=$prefixes[$name]+$match.Groups[3].Value; controller=$match.Groups[4].Value; source="src/routes/$name.ts"}
}
}
$routes | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath (Join-Path $destination 'upstream-routes.json') -Encoding utf8
$schema = Get-Content -LiteralPath (Join-Path $Upstream 'src/models/inventoryModels/inventoryModel.ts') -Raw
$schema = $schema.Substring($schema.IndexOf('const inventorySchema ='))
$defaults = [ordered]@{}
foreach ($line in $schema -split '\r?\n') {
if ($line -match '^ (\w+): \{ type: Number, default: (\d+) \}') { $defaults[$Matches[1]] = [long]$Matches[2] }
elseif ($line -match '^ (\w+): \{ type: slotsBinSchema, default: \{ Slots: (\d+) \}') { $defaults[$Matches[1]] = @{Slots=[int]$Matches[2]; Extra=0} }
elseif ($line -match '^ (\w+): \[\w+\]') { $defaults[$Matches[1]] = @() }
elseif ($line -match '^ (\w+): \{ type: \[\w+\], default: \[\]') { $defaults[$Matches[1]] = @() }
elseif ($line -match '^ (\w+): \{ type: String, default: "([^"\r\n]*)"') { $defaults[$Matches[1]] = $Matches[2] }
}
$defaults | ConvertTo-Json -Depth 20 | Set-Content -LiteralPath (Join-Path $destination 'inventory-defaults.json') -Encoding utf8
Copy-Item -LiteralPath (Join-Path $Upstream 'static/fixed_responses') -Destination $destination -Recurse -Force
Copy-Item -LiteralPath (Join-Path $Upstream 'LICENSE') -Destination (Join-Path $taskRoot 'LICENSE')
$commit = git -C $Upstream rev-parse HEAD
if ($LASTEXITCODE -ne 0) { throw 'Could not read upstream commit' }
$exportService = Get-Content -LiteralPath (Join-Path $Upstream 'src/services/publicExportService.ts') -Raw
$other = [regex]::Match($exportService, 'ExportOther:\s*(\[[\s\S]*?\r?\n \])').Groups[1].Value
if (-not $other) { throw 'PublicExport constant table not found' }
$other = [regex]::Replace($other, '(?m)^(\s*)([A-Za-z][A-Za-z0-9]*):', '$1"$2":')
$other | ConvertFrom-Json | ConvertTo-Json -Depth 20 | Set-Content -LiteralPath (Join-Path $destination 'public-export-other.json') -Encoding utf8
@{repository='https://github.com/spaceninjaserver/SpaceNinjaServer'; commit=$commit; importedAt=[DateTime]::UtcNow.ToString('O'); routes=$routes.Count} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $destination 'upstream.json') -Encoding utf8
Write-Output "Imported $($routes.Count) route declarations and $($defaults.Count) inventory defaults from $commit"
param([string]$Upstream = (Join-Path $PSScriptRoot '../upstream/SpaceNinjaServer'))
$ErrorActionPreference = 'Stop'
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$destination = Join-Path $taskRoot 'Server/data'
New-Item -ItemType Directory -Path $destination -Force | Out-Null
$prefixes = @{api='/api'; arbiter='/api'; custom='/custom'; dynamic='/dynamic'; pay='/pay'; stats='/stats'; publicExport='/PublicExport'}
$routes = @()
foreach ($name in $prefixes.Keys | Sort-Object) {
$file = Join-Path $Upstream "src/routes/$name.ts"
$source = Get-Content -LiteralPath $file -Raw
foreach ($match in [regex]::Matches($source, '(\w+)Router\.(get|post)\("([^"\r\n]+)",\s*(\w+)')) {
$routes += [ordered]@{method=$match.Groups[2].Value.ToUpperInvariant(); path=$prefixes[$name]+$match.Groups[3].Value; controller=$match.Groups[4].Value; source="src/routes/$name.ts"}
}
}
$routes | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath (Join-Path $destination 'upstream-routes.json') -Encoding utf8
$schema = Get-Content -LiteralPath (Join-Path $Upstream 'src/models/inventoryModels/inventoryModel.ts') -Raw
$schema = $schema.Substring($schema.IndexOf('const inventorySchema ='))
$defaults = [ordered]@{}
foreach ($line in $schema -split '\r?\n') {
if ($line -match '^ (\w+): \{ type: Number, default: (\d+) \}') { $defaults[$Matches[1]] = [long]$Matches[2] }
elseif ($line -match '^ (\w+): \{ type: slotsBinSchema, default: \{ Slots: (\d+) \}') { $defaults[$Matches[1]] = @{Slots=[int]$Matches[2]; Extra=0} }
elseif ($line -match '^ (\w+): \[\w+\]') { $defaults[$Matches[1]] = @() }
elseif ($line -match '^ (\w+): \{ type: \[\w+\], default: \[\]') { $defaults[$Matches[1]] = @() }
elseif ($line -match '^ (\w+): \{ type: String, default: "([^"\r\n]*)"') { $defaults[$Matches[1]] = $Matches[2] }
}
$defaults | ConvertTo-Json -Depth 20 | Set-Content -LiteralPath (Join-Path $destination 'inventory-defaults.json') -Encoding utf8
Copy-Item -LiteralPath (Join-Path $Upstream 'static/fixed_responses') -Destination $destination -Recurse -Force
Copy-Item -LiteralPath (Join-Path $Upstream 'LICENSE') -Destination (Join-Path $taskRoot 'LICENSE')
$commit = git -C $Upstream rev-parse HEAD
if ($LASTEXITCODE -ne 0) { throw 'Could not read upstream commit' }
$exportService = Get-Content -LiteralPath (Join-Path $Upstream 'src/services/publicExportService.ts') -Raw
$other = [regex]::Match($exportService, 'ExportOther:\s*(\[[\s\S]*?\r?\n \])').Groups[1].Value
if (-not $other) { throw 'PublicExport constant table not found' }
$other = [regex]::Replace($other, '(?m)^(\s*)([A-Za-z][A-Za-z0-9]*):', '$1"$2":')
$other | ConvertFrom-Json | ConvertTo-Json -Depth 20 | Set-Content -LiteralPath (Join-Path $destination 'public-export-other.json') -Encoding utf8
@{repository='https://github.com/spaceninjaserver/SpaceNinjaServer'; commit=$commit; importedAt=[DateTime]::UtcNow.ToString('O'); routes=$routes.Count} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $destination 'upstream.json') -Encoding utf8
Write-Output "Imported $($routes.Count) route declarations and $($defaults.Count) inventory defaults from $commit"