Skip to content

Commit 9e8c63a

Browse files
committed
feat: Add uninstall command and enhance installer with publisher info\n\n- Add 'phat uninstall' command to remove PHP versions\n- Add publisher information (PPhatDEV) to MSI installer\n- Improve release workflow with checksums and better file detection\n- Update documentation with uninstall feature
1 parent 702b856 commit 9e8c63a

5 files changed

Lines changed: 149 additions & 18 deletions

File tree

.github/workflows/release.yml

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
exit $LASTEXITCODE
3737
}
3838
39-
- name: Debug - List built files
39+
- name: Verify Build Output
4040
shell: pwsh
4141
run: |
4242
Write-Host "=== Looking for output files ==="
@@ -51,8 +51,24 @@ jobs:
5151
Write-Host ""
5252
Write-Host "=== Directory contents ==="
5353
Get-ChildItem -Path "installer/bin/Release" -Recurse | ForEach-Object { Write-Host $_.FullName }
54+
exit 1
55+
}
56+
57+
- name: Generate Checksum
58+
shell: pwsh
59+
run: |
60+
$msiPath = Get-ChildItem -Path "installer/bin/Release" -Filter "*.msi" -Recurse | Select-Object -First 1
61+
if (-not $msiPath) {
62+
Write-Error "No MSI file found!"
63+
exit 1
5464
}
5565
66+
$hash = Get-FileHash -Path $msiPath.FullName -Algorithm SHA256
67+
$checksumFile = "$($msiPath.DirectoryName)\$($msiPath.BaseName).sha256"
68+
"$($hash.Hash) $($msiPath.Name)" | Out-File -FilePath $checksumFile -Encoding UTF8
69+
Write-Host "✅ Checksum generated: $($hash.Hash)"
70+
Write-Host "📝 Checksum file: $checksumFile"
71+
5672
- name: Code Sign MSI (Optional)
5773
shell: pwsh
5874
run: |
@@ -71,24 +87,45 @@ jobs:
7187
exit 1
7288
}
7389
90+
$checksumPath = Get-ChildItem -Path "installer/bin/Release" -Filter "*.sha256" -Recurse | Select-Object -First 1
91+
7492
$tagName = "${{ github.event.release.tag_name }}"
7593
Write-Host "Uploading $($msiPath.Name) to release $tagName..."
7694
77-
# Upload the asset using GitHub CLI
95+
# Upload MSI file
7896
gh release upload "$tagName" "$($msiPath.FullName)" --clobber
79-
80-
if ($LASTEXITCODE -eq 0) {
81-
Write-Host "✅ Successfully uploaded Phat.msi to release $tagName"
82-
} else {
83-
Write-Error "Failed to upload asset"
97+
if ($LASTEXITCODE -ne 0) {
98+
Write-Error "Failed to upload MSI file"
8499
exit 1
85100
}
101+
Write-Host "✅ Successfully uploaded $($msiPath.Name)"
86102
87-
- name: Verify Release
103+
# Upload checksum file
104+
if ($checksumPath) {
105+
gh release upload "$tagName" "$($checksumPath.FullName)" --clobber
106+
if ($LASTEXITCODE -ne 0) {
107+
Write-Error "Failed to upload checksum file"
108+
exit 1
109+
}
110+
Write-Host "✅ Successfully uploaded $($checksumPath.Name)"
111+
}
112+
113+
- name: Summary
88114
shell: pwsh
89115
env:
90116
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91117
run: |
92118
$tagName = "${{ github.event.release.tag_name }}"
119+
$tagVersion = $tagName.TrimStart('v')
120+
$version = $tagVersion -replace '-.*$', ''
121+
122+
Write-Host ""
123+
Write-Host "═══════════════════════════════════════════════════════"
93124
Write-Host "✅ Release workflow completed successfully"
94-
Write-Host "📦 MSI uploaded to $tagName release"
125+
Write-Host "═══════════════════════════════════════════════════════"
126+
Write-Host "📦 Package: Phat-v$version.msi"
127+
Write-Host "🏷️ Release: $tagName"
128+
Write-Host "🔐 SHA256 checksum included"
129+
Write-Host "📝 Publisher: PPhatDEV"
130+
Write-Host "═══════════════════════════════════════════════════════"
131+
Write-Host ""

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ A simple yet powerful CLI tool to manage multiple PHP versions in XAMPP on Windo
88

99
- 🔄 Switch between PHP versions instantly
1010
- 📦 Download and install new PHP versions automatically
11-
- 📋 List all installed PHP versions (local)
11+
- �️ Uninstall PHP versions safely
12+
- �📋 List all installed PHP versions (local)
1213
- 🌐 Fetch available stable PHP versions from PHP.net (global)
1314
- ⚡ Automatic Apache configuration updates
1415
- 🛡️ Safe backups before switching
@@ -136,6 +137,20 @@ After installing, switch to it:
136137
phat switch 8.3.6
137138
```
138139

140+
### Uninstall a PHP version
141+
142+
```bash
143+
phat uninstall 8.0.30
144+
```
145+
146+
Removes an installed PHP version from your system. This will:
147+
148+
1. Verify the version exists and is not currently active
149+
2. Ask for confirmation before deletion
150+
3. Permanently remove the PHP version directory
151+
152+
**Note:** You cannot uninstall the currently active PHP version. Switch to a different version first.
153+
139154
### Help
140155

141156
```bash

installer/Phat.wixproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<Project Sdk="WixToolset.Sdk/4.0.4">
22
<PropertyGroup>
33
<OutputType>Package</OutputType>
4-
<OutputName>Phat</OutputName>
54
<ProductVersion Condition="'$(ProductVersion)' == ''">1.0.0</ProductVersion>
5+
<OutputName>phat-v$(ProductVersion)</OutputName>
66
<DefineConstants>ProductVersion=$(ProductVersion)</DefineConstants>
77
<!-- Security and Trust Settings -->
88
<InstallerVersion>500</InstallerVersion>
99
<Cultures>en-us</Cultures>
1010
</PropertyGroup>
1111

12+
<Target Name="DisplayVersion" BeforeTargets="Build">
13+
<Message Text="========================================" Importance="high" />
14+
<Message Text="Building MSI with version: $(ProductVersion)" Importance="high" />
15+
<Message Text="Output: $(OutputName).msi" Importance="high" />
16+
<Message Text="========================================" Importance="high" />
17+
</Target>
18+
1219
</Project>

installer/Phat.wxs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@
1010
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
1111
<MediaTemplate EmbedCab="yes" />
1212

13+
<!-- Publisher Information -->
14+
<Property Id="ARPPRODUCTICON" Value="PhatIcon" />
15+
<Property Id="ARPPUBLISHER" Value="PPhatDEV" />
16+
<Property Id="ARPHELPLINK" Value="https://github.com/pphatdev/php-version-switcher" />
17+
<Property Id="ARPURLINFOABOUT" Value="https://github.com/pphatdev/php-version-switcher" />
18+
<Property Id="ARPCONTACT" Value="PPhatDEV" />
19+
1320
<StandardDirectory Id="ProgramFilesFolder">
1421
<Directory Id="INSTALLFOLDER" Name="Phat">
1522
<Component Id="PhatBatComponent" Guid="*">
1623
<File Id="PhatBat" Source="..\phat.bat" KeyPath="yes" />
1724
<Environment
1825
Id="PhatPath"
19-
Name="Path"
26+
Name="PATH"
2027
Value="[INSTALLFOLDER]"
2128
Action="set"
2229
Part="last"
23-
System="yes" />
30+
System="yes"
31+
Permanent="no" />
2432
</Component>
2533
<Component Id="PhatPs1Component" Guid="*">
2634
<File Id="PhatPs1" Source="..\phat.ps1" KeyPath="yes" />

phat.ps1

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ function Write-UsageLine ([string]$CommandText, [string]$Description) {
214214

215215
function Show-Help {
216216
Write-Host ""
217-
Write-Host " ____ __ __ " -ForegroundColor Cyan
218-
Write-Host " / __ \/ /_ ____ _/ /_" -ForegroundColor Cyan
219-
Write-Host " / /_/ / __ \/ __ `/ __/" -ForegroundColor Cyan
220-
Write-Host " / ____/ / / / /_/ / /_ " -ForegroundColor Cyan
221-
Write-Host " /_/ /_/ /_/\__,_/\__/ " -ForegroundColor Cyan
217+
Write-Host " ____ __ __ " -ForegroundColor Cyan
218+
Write-Host " / __ \/ /_ ____ _/ /_ " -ForegroundColor Cyan
219+
Write-Host " / /_/ / __ \/ __ `/ __/ " -ForegroundColor Cyan
220+
Write-Host " / ____/ / / / /_/ / /_ " -ForegroundColor Cyan
221+
Write-Host " /_/ /_/ /_/\__,_/\__/ " -ForegroundColor Cyan
222222
Write-Host ""
223223
Write-Host " Phat - My Personal XAMPP PHP Version Switcher " -ForegroundColor Gray
224224
Write-Host " Github: @pphatdev" -ForegroundColor Gray
@@ -232,12 +232,14 @@ function Show-Help {
232232
Write-UsageLine "phat switch [version]" " -> Switch to a PHP version"
233233
Write-UsageLine "phat use [version]" " -> Alias for switch"
234234
Write-UsageLine "phat install [version]" " -> Download and install a PHP version"
235+
Write-UsageLine "phat uninstall [version]" " -> Remove an installed PHP version"
235236
Write-UsageLine "phat help" " -> Show this help"
236237
Write-Host ""
237238
Write-Host " Examples:"
238239
Write-ExampleLine "phat list --php --global"
239240
Write-ExampleLine "phat switch 7.4.33"
240241
Write-ExampleLine "phat install 8.2.27"
242+
Write-ExampleLine "phat uninstall 7.4.33"
241243
Write-Host ""
242244
}
243245

@@ -530,6 +532,67 @@ function Invoke-Install ([string]$Version) {
530532
Write-Host ""
531533
}
532534

535+
function Invoke-Uninstall ([string]$Version) {
536+
if (-not $Version) {
537+
Write-Host " Error: Version required. Usage: phat uninstall [version]" -ForegroundColor Red
538+
Write-Host " Example: phat uninstall 8.2.27" -ForegroundColor Gray
539+
return
540+
}
541+
542+
$targetDir = Join-Path $XAMPP_ROOT "php$Version"
543+
$currentDir = Join-Path $XAMPP_ROOT "php"
544+
545+
# Validate target exists
546+
if (-not (Test-Path $targetDir)) {
547+
Write-Host " Error: php$Version is not installed in $XAMPP_ROOT" -ForegroundColor Red
548+
Write-Host " Available:" -ForegroundColor Gray
549+
Get-ChildItem -Path $XAMPP_ROOT -Directory -Filter "php*" |
550+
Where-Object { $_.Name -ne "php" -and $_.Name -ne "phpMyAdmin" } |
551+
ForEach-Object { Write-Host " $($_.Name -replace '^php', '')" }
552+
return
553+
}
554+
555+
# Check if trying to uninstall the active version
556+
$currentVer = Get-PhpVersion $currentDir
557+
$targetVer = Get-PhpVersion $targetDir
558+
559+
if ($currentVer -and $targetVer -and ($currentVer -eq $targetVer)) {
560+
Write-Host " Error: Cannot uninstall the currently active PHP version ($Version)" -ForegroundColor Red
561+
Write-Host " Please switch to another version first." -ForegroundColor Yellow
562+
return
563+
}
564+
565+
Write-Host ""
566+
Write-Host " Uninstalling PHP $Version..." -ForegroundColor Cyan
567+
Write-Host ""
568+
569+
# Confirmation prompt
570+
Write-Host " This will permanently delete: $targetDir" -ForegroundColor Yellow
571+
$confirmation = Read-Host " Type 'yes' to confirm"
572+
573+
if ($confirmation -ne 'yes') {
574+
Write-Host ""
575+
Write-Host " Uninstall cancelled." -ForegroundColor Gray
576+
Write-Host ""
577+
return
578+
}
579+
580+
# Remove the directory
581+
try {
582+
Write-Host ""
583+
Write-Host " Removing PHP $Version..." -ForegroundColor White
584+
Remove-Item -Path $targetDir -Recurse -Force -ErrorAction Stop
585+
Write-Host ""
586+
Write-Host " Done! PHP $Version has been uninstalled." -ForegroundColor Green
587+
Write-Host ""
588+
}
589+
catch {
590+
Write-Host ""
591+
Write-Host " Error: Failed to remove PHP $Version - $_" -ForegroundColor Red
592+
Write-Host ""
593+
}
594+
}
595+
533596
# ── Dispatch ───────────────────────────────────────────────────────────────────
534597

535598
if ($VersionFlag) {
@@ -543,6 +606,7 @@ switch ($Command) {
543606
"switch" { Invoke-Switch $Argument }
544607
"use" { Invoke-Switch $Argument }
545608
"install" { Invoke-Install $Argument }
609+
"uninstall" { Invoke-Uninstall $Argument }
546610
"help" { Show-Help }
547611

548612
default { Show-Help }

0 commit comments

Comments
 (0)