-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeploy.ps1
More file actions
66 lines (54 loc) · 2.23 KB
/
Copy pathDeploy.ps1
File metadata and controls
66 lines (54 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
param(
[string]$TargetDir = "C:\Program Files\Cold Turkey\web"
)
# Request Admin privileges if not running as Admin
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "This script requires Administrator privileges to replace Cold Turkey files."
Write-Host "Restarting with elevated privileges..."
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -TargetDir `"$TargetDir`"" -Verb RunAs
exit
}
$ScriptsDir = Join-Path -Path $PSScriptRoot -ChildPath "CtblPlusPlus.WebUI\web\Scripts"
Write-Host "Building project via Webpack..."
Push-Location -Path $ScriptsDir
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed! Deployment aborted."
Pop-Location
pause
exit
}
Pop-Location
$SourceDir = Join-Path -Path $PSScriptRoot -ChildPath "CtblPlusPlus.WebUI\web\Bundled"
if (-not (Test-Path -Path $SourceDir)) {
Write-Error "Source directory not found: $SourceDir"
pause
exit
}
if (-not (Test-Path -Path $TargetDir)) {
Write-Warning "Target directory not found: $TargetDir"
$TargetDir = Read-Host "Please enter the path to the Cold Turkey web directory (e.g. C:\Program Files\Cold Turkey\web)"
if (-not (Test-Path -Path $TargetDir)) {
Write-Error "Target directory still not found. Exiting."
pause
exit
}
}
Write-Host "Replacing Cold Turkey web files..."
Write-Host "Source: $SourceDir"
Write-Host "Target: $TargetDir"
Write-Host ""
# Backup the original target directory just in case
$BackupDir = "$TargetDir.bak_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
Write-Host "Backing up original files to: $BackupDir"
Copy-Item -Path $TargetDir -Destination $BackupDir -Recurse -Force
# Clear the target directory so deleted files don't stick around
Write-Host "Clearing target directory..."
Remove-Item -Path "$TargetDir\*" -Recurse -Force
# Copy new files over
Write-Host "Copying new files..."
Copy-Item -Path "$SourceDir\*" -Destination $TargetDir -Recurse -Force
Write-Host ""
Write-Host "Replacement complete! You may need to restart Cold Turkey for changes to take effect."
pause