# PowerShell Deployment Script using npm Write-Host "Starting PWA deployment with npm..." -ForegroundColor Green try { # Pull latest code Write-Host "Pulling latest code..." -ForegroundColor Yellow & "C:\Program Files\Git\bin\git.exe" pull origin main if ($LASTEXITCODE -ne 0) { throw "Git pull failed" } # Clean old build files Write-Host "Cleaning old build files..." -ForegroundColor Yellow if (Test-Path "dist") { Remove-Item -Recurse -Force "dist" } # Clean node_modules if exists if (Test-Path "node_modules") { Write-Host "Cleaning node_modules..." -ForegroundColor Yellow Remove-Item -Recurse -Force "node_modules" -ErrorAction SilentlyContinue } # Remove lock files if (Test-Path "package-lock.json") { Remove-Item "package-lock.json" -ErrorAction SilentlyContinue } if (Test-Path "yarn.lock") { Remove-Item "yarn.lock" -ErrorAction SilentlyContinue } # Install dependencies with npm Write-Host "Installing dependencies with npm..." -ForegroundColor Yellow npm install if ($LASTEXITCODE -ne 0) { throw "Dependency installation failed" } # Build production version Write-Host "Building production version..." -ForegroundColor Yellow npm run build if ($LASTEXITCODE -ne 0) { throw "Build failed" } # Check build results Write-Host "Checking build results..." -ForegroundColor Yellow if (-not (Test-Path "dist")) { throw "Build failed, dist directory does not exist" } # Deploy to server Write-Host "Deploying to server..." -ForegroundColor Yellow # Try different upload methods $uploadSuccess = $false # Try rsync first try { & "C:\Program Files\Git\bin\rsync.exe" --version | Out-Null Write-Host "Using rsync to upload..." -ForegroundColor Cyan & "C:\Program Files\Git\bin\rsync.exe" --exclude='node_modules/' -ravzh --delete -e "ssh -o StrictHostKeyChecking=no" ./dist/ junma-server:/var/www/junma-show/ if ($LASTEXITCODE -eq 0) { $uploadSuccess = $true } } catch { Write-Host "rsync not available, trying scp..." -ForegroundColor Yellow } # Try scp if rsync failed if (-not $uploadSuccess) { try { # Try different scp paths $scpPaths = @( "C:\Program Files\Git\usr\bin\scp.exe", "C:\Program Files\Git\bin\scp.exe", "scp" ) foreach ($scpPath in $scpPaths) { try { if ($scpPath -eq "scp") { & $scpPath -r -o StrictHostKeyChecking=no ./dist/* junma-server:/var/www/junma-show/ } else { if (Test-Path $scpPath) { & $scpPath -r -o StrictHostKeyChecking=no ./dist/* junma-server:/var/www/junma-show/ } else { continue } } if ($LASTEXITCODE -eq 0) { Write-Host "Upload successful with: $scpPath" -ForegroundColor Green $uploadSuccess = $true break } } catch { continue } } } catch { Write-Host "All upload methods failed" -ForegroundColor Red } } if (-not $uploadSuccess) { throw "File upload failed - no working upload method found" } if ($LASTEXITCODE -ne 0) { throw "File upload failed" } Write-Host "Deployment completed!" -ForegroundColor Green Write-Host "Application URL: https://your-domain.com" -ForegroundColor Cyan Write-Host "PWA features enabled" -ForegroundColor Cyan } catch { Write-Host "Deployment failed: $($_.Exception.Message)" -ForegroundColor Red exit 1 }