# SneakerPicks: Staging-first deploy to VPS param( [switch]$SkipBuild ) $ErrorActionPreference = "Stop" $VPS = "root@72.62.45.83" $SSH_OPTS = "-o StrictHostKeyChecking=no" $DEPLOY_FILE = "sneakerpicks-deploy.tar.gz" $REMOTE_PATH = "/var/www/sneakerpicks/$DEPLOY_FILE" Push-Location "$PSScriptRoot\.." try { # Step 1: Build locally if (-not $SkipBuild) { Write-Host "Building locally..." -ForegroundColor Cyan pnpm run build if ($LASTEXITCODE -ne 0) { Write-Host "Build failed!" -ForegroundColor Red; exit 1 } } # Step 2: Package Write-Host "Packaging..." -ForegroundColor Cyan if (Test-Path $DEPLOY_FILE) { Remove-Item $DEPLOY_FILE } tar -czf $DEPLOY_FILE --exclude=node_modules --exclude=.git --exclude=.env --exclude="sneakerpicks-deploy.tar.gz" -C . . $size = [math]::Round((Get-Item $DEPLOY_FILE).Length / 1MB, 1) Write-Host " Package size: ${size}MB" # Step 3: Upload Write-Host "Uploading to VPS..." -ForegroundColor Cyan scp $SSH_OPTS.Split(" ") $DEPLOY_FILE "${VPS}:${REMOTE_PATH}" if ($LASTEXITCODE -ne 0) { Write-Host "Upload failed!" -ForegroundColor Red; exit 1 } # Step 4: Deploy via staging-first script Write-Host "Deploying via staging-first process..." -ForegroundColor Cyan ssh $SSH_OPTS.Split(" ") $VPS "bash /var/www/deploy-sneakerpicks.sh" if ($LASTEXITCODE -ne 0) { Write-Host "Deploy failed!" -ForegroundColor Red; exit 1 } Write-Host "`nDeploy complete!" -ForegroundColor Green # Cleanup local Remove-Item $DEPLOY_FILE -ErrorAction SilentlyContinue } finally { Pop-Location }