# WeChat iLink Gateway - one-click start (Windows) $ErrorActionPreference = "Stop" Set-Location $PSScriptRoot function Ensure-Bun { $bun = Get-Command bun -ErrorAction SilentlyContinue if ($bun) { return } Write-Host "[*] Bun not found, installing..." -ForegroundColor Yellow irm https://bun.sh/install.ps1 | iex $env:Path = "$env:USERPROFILE\.bun\bin;$env:Path" if (-not (Get-Command bun -ErrorAction SilentlyContinue)) { Write-Host "[!] Bun installed but not on PATH. Close this window and run start.bat again." -ForegroundColor Red exit 1 } } function Ensure-Env { if (-not (Test-Path ".env")) { Copy-Item ".env.example" ".env" Write-Host "[*] Created .env from .env.example" -ForegroundColor Yellow } $lines = Get-Content ".env" $apiKeyLine = $lines | Where-Object { $_ -match '^\s*API_KEY\s*=' } | Select-Object -First 1 $apiKey = "" if ($apiKeyLine -match '^\s*API_KEY\s*=\s*(.*)$') { $apiKey = $Matches[1].Trim().Trim('"').Trim("'") } if ([string]::IsNullOrWhiteSpace($apiKey) -or $apiKey.Length -le 12) { $generated = -join ((1..24) | ForEach-Object { "{0:x}" -f (Get-Random -Max 16) }) $newLines = foreach ($line in $lines) { if ($line -match '^\s*API_KEY\s*=') { "API_KEY=$generated" } else { $line } } Set-Content -Path ".env" -Value $newLines -Encoding utf8 Write-Host "[*] Generated API_KEY in .env: $generated" -ForegroundColor Cyan } } Ensure-Bun Ensure-Env if (-not (Test-Path "node_modules")) { Write-Host "[*] Installing dependencies (bun install)..." -ForegroundColor Yellow bun install } $port = "3456" $envLine = Get-Content ".env" | Where-Object { $_ -match '^\s*PORT\s*=' } | Select-Object -First 1 if ($envLine -match '^\s*PORT\s*=\s*(\d+)') { $port = $Matches[1] } Write-Host "" Write-Host "[+] Starting gateway..." -ForegroundColor Green Write-Host " Console: http://localhost:$port/console" Write-Host " Status: http://localhost:$port/status" Write-Host " Press Ctrl+C to stop" Write-Host "" bun run start