# PowerShell Script to create deployment ZIP after successful build param( [string]$ProjectRoot = $PSScriptRoot + "\.." ) # Read package.json to get name and version $packageJsonPath = Join-Path $ProjectRoot "package.json" $packageJson = Get-Content $packageJsonPath | ConvertFrom-Json $projectName = $packageJson.name $version = $packageJson.version # Create ZIP filename $zipFileName = "${projectName}-${version}.zip" $zipPath = Join-Path $ProjectRoot $zipFileName # Remove existing ZIP if it exists if (Test-Path $zipPath) { Remove-Item $zipPath -Force Write-Host "[DELETE] Removed existing ZIP: $zipFileName" -ForegroundColor Yellow } # Define files and directories to include $itemsToInclude = @( ".next", "public", ".env.production", "server.js", "nssm.exe", "nssm.exe Installation.md", "package.json", "package-lock.json", "Start-Dev.ps1", "StartNodeApp.bat" ) # Check which items exist $existingItems = @() foreach ($item in $itemsToInclude) { $itemPath = Join-Path $ProjectRoot $item if (Test-Path $itemPath) { $existingItems += $item Write-Host "[FOUND] $item" -ForegroundColor Green } else { Write-Host "[MISSING] $item" -ForegroundColor Yellow } } if ($existingItems.Count -eq 0) { Write-Host "[ERROR] No items found to include in ZIP!" -ForegroundColor Red exit 1 } # Create temporary directory for ZIP contents $tempDir = Join-Path $ProjectRoot "temp-deployment" if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force } New-Item -ItemType Directory -Path $tempDir | Out-Null # Copy items to temporary directory foreach ($item in $existingItems) { $sourcePath = Join-Path $ProjectRoot $item $destPath = Join-Path $tempDir $item if (Test-Path $sourcePath -PathType Container) { # It's a directory Copy-Item $sourcePath $destPath -Recurse -Force Write-Host "[COPY DIR] $item" -ForegroundColor Cyan } else { # It's a file Copy-Item $sourcePath $destPath -Force Write-Host "[COPY FILE] $item" -ForegroundColor Cyan } } # Create ZIP file try { Write-Host "[CREATE] Creating ZIP: $zipFileName..." -ForegroundColor Blue # Use .NET compression to create ZIP Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::CreateFromDirectory($tempDir, $zipPath) # Get ZIP file size $zipSize = (Get-Item $zipPath).Length $zipSizeMB = [math]::Round($zipSize / 1MB, 2) Write-Host "[SUCCESS] Successfully created deployment ZIP!" -ForegroundColor Green Write-Host "[FILE] $zipFileName" -ForegroundColor White Write-Host "[SIZE] $zipSizeMB MB" -ForegroundColor White Write-Host "[LOCATION] $zipPath" -ForegroundColor White } catch { Write-Host "[ERROR] Failed to create ZIP: $($_.Exception.Message)" -ForegroundColor Red exit 1 } finally { # Clean up temporary directory if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force Write-Host "[CLEANUP] Cleaned up temporary files" -ForegroundColor Gray } } Write-Host "" Write-Host "[COMPLETE] Deployment ZIP ready for production deployment!" -ForegroundColor Green