# آماده‌سازی پکیج دپلوی برای cPanel
$root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $root

Write-Host "Building frontend..." -ForegroundColor Cyan
npm run build
if ($LASTEXITCODE -ne 0) { exit 1 }

if (-not (Test-Path "backend\.env")) {
  Copy-Item "backend\.env.production.example" "backend\.env"
  Write-Host "Created backend\.env from example - EDIT JWT_SECRET before upload!" -ForegroundColor Yellow
}

$zipPath = Join-Path $root "deploy.zip"
if (Test-Path $zipPath) { Remove-Item $zipPath -Force }

$items = @(
  "app.js",
  "package.json",
  "DEPLOY-CPANEL.md",
  "backend\src",
  "backend\package.json",
  "backend\package-lock.json",
  "backend\.env",
  "backend\data",
  "backend\uploads",
  "frontend\dist"
)

Compress-Archive -Path $items -DestinationPath $zipPath -Force
Write-Host "Deploy package ready: $zipPath" -ForegroundColor Green
Write-Host "Upload deploy.zip to cPanel and extract." -ForegroundColor Green
