1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 19:40:07 +00:00

fix(windows): align source channel and prerelease binaries

Refs #538
This commit is contained in:
Tw93
2026-03-06 08:34:10 +08:00
parent 7c9b420a22
commit d0f627892d
17 changed files with 732 additions and 453 deletions

View File

@@ -15,7 +15,8 @@ $ErrorActionPreference = "Stop"
# Script location
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$windowsDir = Split-Path -Parent $scriptDir
$binPath = Join-Path $windowsDir "bin\analyze.exe"
$defaultBinPath = Join-Path $windowsDir "bin\analyze.exe"
. (Join-Path $windowsDir "lib\core\tui_binaries.ps1")
# Help
function Show-AnalyzeHelp {
@@ -47,29 +48,11 @@ if ($ShowHelp) {
return
}
# Check if binary exists
if (-not (Test-Path $binPath)) {
Write-Host "Building analyze tool..." -ForegroundColor Cyan
$cmdDir = Join-Path $windowsDir "cmd\analyze"
$binDir = Join-Path $windowsDir "bin"
if (-not (Test-Path $binDir)) {
New-Item -ItemType Directory -Path $binDir -Force | Out-Null
}
Push-Location $windowsDir
try {
$result = & go build -o "$binPath" "./cmd/analyze/" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to build analyze tool: $result" -ForegroundColor Red
Pop-Location
return
}
}
finally {
Pop-Location
}
$binPath = Ensure-TuiBinary -Name "analyze" -WindowsDir $windowsDir -DestinationPath $defaultBinPath -SourcePath "./cmd/analyze/"
if (-not $binPath) {
Write-Host "Analyze binary not found, no prerelease asset was available, and Go 1.24+ is not installed." -ForegroundColor Red
Write-Host "Install Go or wait for a Windows prerelease asset that includes analyze.exe." -ForegroundColor Yellow
exit 1
}
# Set path environment variable if provided

40
bin/remove.ps1 Normal file
View File

@@ -0,0 +1,40 @@
# Mole - Remove Command
# Removes Mole from the current installation directory.
#Requires -Version 5.1
param(
[Alias('h')]
[switch]$ShowHelp
)
$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$windowsDir = Split-Path -Parent $scriptDir
$installScript = Join-Path $windowsDir "install.ps1"
function Show-RemoveHelp {
$esc = [char]27
Write-Host ""
Write-Host "$esc[1;35mmo remove$esc[0m - Remove Mole from this system"
Write-Host ""
Write-Host "$esc[33mUsage:$esc[0m mo remove"
Write-Host ""
Write-Host "$esc[33mBehavior:$esc[0m"
Write-Host " - Removes the current Mole installation directory"
Write-Host " - Removes PATH entries created for this install"
Write-Host " - Prompts before deleting Mole config files"
Write-Host ""
}
if ($ShowHelp) {
Show-RemoveHelp
return
}
if (-not (Test-Path $installScript)) {
Write-Host "Installer not found at: $installScript" -ForegroundColor Red
exit 1
}
& $installScript -InstallDir $windowsDir -Uninstall

View File

@@ -12,7 +12,8 @@ $ErrorActionPreference = "Stop"
# Script location
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$windowsDir = Split-Path -Parent $scriptDir
$binPath = Join-Path $windowsDir "bin\status.exe"
$defaultBinPath = Join-Path $windowsDir "bin\status.exe"
. (Join-Path $windowsDir "lib\core\tui_binaries.ps1")
# Help
function Show-StatusHelp {
@@ -45,29 +46,11 @@ if ($ShowHelp) {
return
}
# Check if binary exists
if (-not (Test-Path $binPath)) {
Write-Host "Building status tool..." -ForegroundColor Cyan
$cmdDir = Join-Path $windowsDir "cmd\status"
$binDir = Join-Path $windowsDir "bin"
if (-not (Test-Path $binDir)) {
New-Item -ItemType Directory -Path $binDir -Force | Out-Null
}
Push-Location $windowsDir
try {
$result = & go build -o "$binPath" "./cmd/status/" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to build status tool: $result" -ForegroundColor Red
Pop-Location
return
}
}
finally {
Pop-Location
}
$binPath = Ensure-TuiBinary -Name "status" -WindowsDir $windowsDir -DestinationPath $defaultBinPath -SourcePath "./cmd/status/"
if (-not $binPath) {
Write-Host "Status binary not found, no prerelease asset was available, and Go 1.24+ is not installed." -ForegroundColor Red
Write-Host "Install Go or wait for a Windows prerelease asset that includes status.exe." -ForegroundColor Yellow
exit 1
}
# Run the binary

126
bin/update.ps1 Normal file
View File

@@ -0,0 +1,126 @@
# Mole - Update Command
# Updates a source-channel installation from the windows branch.
#Requires -Version 5.1
param(
[Alias('h')]
[switch]$ShowHelp
)
$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$windowsDir = Split-Path -Parent $scriptDir
$installScript = Join-Path $windowsDir "install.ps1"
$gitDir = Join-Path $windowsDir ".git"
function Show-UpdateHelp {
$esc = [char]27
Write-Host ""
Write-Host "$esc[1;35mmo update$esc[0m - Update the Windows source channel"
Write-Host ""
Write-Host "$esc[33mUsage:$esc[0m mo update"
Write-Host ""
Write-Host "$esc[33mBehavior:$esc[0m"
Write-Host " - Pulls the latest commit from origin/windows"
Write-Host " - Re-runs the local installer in-place"
Write-Host " - Rebuilds analyze/status if Go is available"
Write-Host ""
Write-Host "$esc[33mNotes:$esc[0m"
Write-Host " - Works only for git-based source installs"
Write-Host " - Legacy copied installs should be reinstalled with quick-install"
Write-Host ""
}
function Test-InstallDirOnUserPath {
param([string]$Path)
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if (-not $currentPath) {
return $false
}
return $currentPath -split ";" | Where-Object { $_ -eq $Path }
}
if ($ShowHelp) {
Show-UpdateHelp
return
}
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host "Git is not installed. Install Git to use 'mo update'." -ForegroundColor Red
exit 1
}
if (-not (Test-Path $installScript)) {
Write-Host "Installer not found at: $installScript" -ForegroundColor Red
exit 1
}
if (-not (Test-Path $gitDir)) {
Write-Host "This installation is not a git-based source install." -ForegroundColor Red
Write-Host "Reinstall with quick-install to enable 'mo update'." -ForegroundColor Yellow
exit 1
}
$dirtyOutput = & git -C $windowsDir status --porcelain --untracked-files=no 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to inspect git status: $dirtyOutput" -ForegroundColor Red
exit 1
}
if ($dirtyOutput) {
Write-Host "Local tracked changes detected in the installation directory." -ForegroundColor Red
Write-Host "Commit or discard them before running 'mo update'." -ForegroundColor Yellow
exit 1
}
$remote = (& git -C $windowsDir remote get-url origin 2>&1).Trim()
if ($LASTEXITCODE -ne 0 -or -not $remote) {
Write-Host "Git remote 'origin' is not configured for this install." -ForegroundColor Red
exit 1
}
$branch = (& git -C $windowsDir branch --show-current 2>&1).Trim()
if ($LASTEXITCODE -ne 0 -or -not $branch) {
$branch = "windows"
}
$before = (& git -C $windowsDir rev-parse --short HEAD 2>&1).Trim()
if ($LASTEXITCODE -ne 0 -or -not $before) {
Write-Host "Failed to read current revision." -ForegroundColor Red
exit 1
}
Write-Host "Updating source from $remote ($branch)..." -ForegroundColor Cyan
$pullOutput = & git -C $windowsDir pull --ff-only origin $branch 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to update source: $pullOutput" -ForegroundColor Red
exit 1
}
$after = (& git -C $windowsDir rev-parse --short HEAD 2>&1).Trim()
if ($LASTEXITCODE -ne 0 -or -not $after) {
Write-Host "Updated source, but failed to read the new revision." -ForegroundColor Red
exit 1
}
if ($after -eq $before) {
Write-Host "Already up to date at $after." -ForegroundColor Green
}
else {
Write-Host "Updated source: $before -> $after" -ForegroundColor Green
}
$installArgs = @(
"-InstallDir", $windowsDir
)
if (Test-InstallDirOnUserPath -Path $windowsDir) {
$installArgs += "-AddToPath"
}
Write-Host "Refreshing local installation..." -ForegroundColor Cyan
& $installScript @installArgs