param(
  [string]$BuildDir = "dist",
  [string]$ReleaseRoot = "release",
  [string]$DeployFolderName = "upload"
)

$ErrorActionPreference = "Stop"

$projectRoot = Resolve-Path "."
$buildPath = Join-Path $projectRoot $BuildDir
$releasePath = Join-Path $projectRoot $ReleaseRoot
$deployPath = Join-Path $releasePath $DeployFolderName
$zipPath = Join-Path $releasePath ("$DeployFolderName.zip")

if (-not (Test-Path $buildPath)) {
  throw "Build output '$BuildDir' not found. Run build first."
}

if (Test-Path $deployPath) {
  Remove-Item -LiteralPath $deployPath -Recurse -Force
}
if (Test-Path $zipPath) {
  Remove-Item -LiteralPath $zipPath -Force
}

New-Item -ItemType Directory -Force -Path $deployPath | Out-Null
Copy-Item -Path (Join-Path $buildPath "*") -Destination $deployPath -Recurse -Force
Compress-Archive -Path (Join-Path $deployPath "*") -DestinationPath $zipPath -CompressionLevel Optimal

Write-Host "Deploy folder created:" $deployPath
Write-Host "Zip archive created:" $zipPath
