Created
May 22, 2025 12:02
-
-
Save Avi-E-Koenig/94192e5c8f4859542cb0c5a12498d1b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if script is running as Administrator | |
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
if (-not $isAdmin) { | |
Write-Error "This script must be run as Administrator. Exiting..." | |
exit 1 | |
} | |
# Step 1: Backup and remove NODE_ENV from system environment | |
$originalNodeEnv = [System.Environment]::GetEnvironmentVariable("NODE_ENV", "Machine") | |
[System.Environment]::SetEnvironmentVariable("NODE_ENV", $null, "Machine") | |
Write-Host "NODE_ENV removed from system environment (backed up as '$originalNodeEnv')." | |
# Step 2: Navigate to project directory and run git pull, npm install, build | |
$projectPath = "C:\DEV\nextjs-poc" | |
Set-Location $projectPath | |
try { | |
Write-Host "Pulling latest changes from Git..." | |
git pull | |
if ($LASTEXITCODE -ne 0) { throw "git pull failed" } | |
Write-Host "Installing dependencies..." | |
npm install | |
if ($LASTEXITCODE -ne 0) { throw "npm install failed" } | |
Write-Host "Building the project..." | |
npm run build | |
if ($LASTEXITCODE -ne 0) { throw "npm run build failed" } | |
# Step 3: Reload PM2 for id 24 | |
Write-Host "Reloading PM2 for nextis-poc (id 24)..." | |
pm2 reload 24 | |
if ($LASTEXITCODE -ne 0) { throw "pm2 reload failed" } | |
Write-Host "Deployment completed successfully." | |
} | |
catch { | |
Write-Error "Deployment failed: $_" | |
} | |
finally { | |
# Step 4: Restore NODE_ENV | |
[System.Environment]::SetEnvironmentVariable("NODE_ENV", $originalNodeEnv, "Machine") | |
Write-Host "NODE_ENV restored to original value: $originalNodeEnv" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment