201 lines
8.7 KiB
PowerShell
201 lines
8.7 KiB
PowerShell
# ==============================================================================
|
|
# G-Launcher Auto-Updater & Environment Bootstrap Script
|
|
# ==============================================================================
|
|
param(
|
|
[string]$Branch = "Dev",
|
|
[string]$RepoUrl = "https://gaytea.cod-algieba.ts.net/GaCy/G-Launcher.git",
|
|
[switch]$NoLaunch
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
$rootDir = Split-Path -Parent $PSScriptRoot
|
|
Set-Location $rootDir
|
|
$toolsDir = Join-Path $rootDir "tools"
|
|
if (!(Test-Path $toolsDir)) { New-Item -ItemType Directory -Path $toolsDir -Force | Out-Null }
|
|
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
Write-Host " G-Launcher: Auto-Update & Local Build System" -ForegroundColor Cyan
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
function Download-And-Extract {
|
|
param(
|
|
[string]$Url,
|
|
[string]$ZipName,
|
|
[string]$DestinationDir,
|
|
[string]$Description
|
|
)
|
|
Write-Host ">> Downloading $Description..." -ForegroundColor Yellow
|
|
$zipPath = Join-Path $toolsDir $ZipName
|
|
|
|
if (Get-Command curl.exe -ErrorAction SilentlyContinue) {
|
|
& curl.exe -L --fail --silent --show-error -o $zipPath $Url
|
|
} else {
|
|
(New-Object System.Net.WebClient).DownloadFile($Url, $zipPath)
|
|
}
|
|
|
|
Write-Host ">> Extracting $Description..." -ForegroundColor Yellow
|
|
if (!(Test-Path $DestinationDir)) { New-Item -ItemType Directory -Path $DestinationDir -Force | Out-Null }
|
|
|
|
Expand-Archive -LiteralPath $zipPath -DestinationPath $DestinationDir -Force
|
|
Remove-Item -Path $zipPath -Force -ErrorAction SilentlyContinue
|
|
Write-Host "[OK] $Description installed successfully!" -ForegroundColor Green
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 1. Verify Git (or portable MinGit)
|
|
# ------------------------------------------------------------------------------
|
|
Write-Host "[1/6] Checking Git..." -ForegroundColor White
|
|
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
|
|
if (-not $gitCmd) {
|
|
$minGitPath = Join-Path $toolsDir "mingit\cmd"
|
|
if (Test-Path (Join-Path $minGitPath "git.exe")) {
|
|
$env:PATH = "$minGitPath;" + $env:PATH
|
|
} else {
|
|
$minGitUrl = "https://github.com/git-for-windows/git/releases/download/v2.48.1.windows.1/MinGit-2.48.1-64-bit.zip"
|
|
Download-And-Extract -Url $minGitUrl -ZipName "mingit.zip" -DestinationDir (Join-Path $toolsDir "mingit") -Description "Portable Git (MinGit)"
|
|
$env:PATH = "$minGitPath;" + $env:PATH
|
|
}
|
|
}
|
|
$gitVersion = (& git --version)
|
|
Write-Host " -> Found: $gitVersion" -ForegroundColor Gray
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 2. Verify Go Compiler (or portable Go)
|
|
# ------------------------------------------------------------------------------
|
|
Write-Host "[2/6] Checking Go Compiler..." -ForegroundColor White
|
|
$goCmd = Get-Command go -ErrorAction SilentlyContinue
|
|
if (-not $goCmd) {
|
|
$goBinPath = Join-Path $toolsDir "go\bin"
|
|
if (Test-Path (Join-Path $goBinPath "go.exe")) {
|
|
$env:PATH = "$goBinPath;" + $env:PATH
|
|
$env:GOROOT = Join-Path $toolsDir "go"
|
|
} else {
|
|
$goUrl = "https://go.dev/dl/go1.24.0.windows-amd64.zip"
|
|
Download-And-Extract -Url $goUrl -ZipName "go.zip" -DestinationDir $toolsDir -Description "Portable Go 1.24"
|
|
$env:PATH = "$goBinPath;" + $env:PATH
|
|
$env:GOROOT = Join-Path $toolsDir "go"
|
|
}
|
|
}
|
|
$goVersion = (& go version)
|
|
Write-Host " -> Found: $goVersion" -ForegroundColor Gray
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 3. Verify Node.js & npm (or portable Node.js)
|
|
# ------------------------------------------------------------------------------
|
|
Write-Host "[3/6] Checking Node.js & npm..." -ForegroundColor White
|
|
$nodeCmd = Get-Command node -ErrorAction SilentlyContinue
|
|
if (-not $nodeCmd) {
|
|
$nodePath = Join-Path $toolsDir "node"
|
|
if (Test-Path (Join-Path $nodePath "node.exe")) {
|
|
$env:PATH = "$nodePath;" + $env:PATH
|
|
} else {
|
|
$nodeUrl = "https://nodejs.org/dist/v22.14.0/node-v22.14.0-win-x64.zip"
|
|
$tempNodeExtract = Join-Path $toolsDir "node_temp"
|
|
Download-And-Extract -Url $nodeUrl -ZipName "node.zip" -DestinationDir $tempNodeExtract -Description "Portable Node.js v22"
|
|
|
|
$extractedDir = Get-ChildItem -Path $tempNodeExtract | Where-Object { $_.PSIsContainer } | Select-Object -First 1
|
|
if ($extractedDir) {
|
|
Move-Item -Path $extractedDir.FullName -Destination $nodePath -Force
|
|
Remove-Item -Path $tempNodeExtract -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|
|
$env:PATH = "$nodePath;" + $env:PATH
|
|
}
|
|
}
|
|
$nodeVersion = (& node -v)
|
|
$npmVersion = (& npm -v)
|
|
Write-Host " -> Found: Node.js $nodeVersion (npm v$npmVersion)" -ForegroundColor Gray
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 4. Verify Wails v3 CLI
|
|
# ------------------------------------------------------------------------------
|
|
Write-Host "[4/6] Checking Wails v3 CLI..." -ForegroundColor White
|
|
$gopath = (& go env GOPATH).Trim()
|
|
$wailsBin = Join-Path $gopath "bin"
|
|
$env:PATH = "$wailsBin;" + $env:PATH
|
|
$wailsCmd = Get-Command wails3 -ErrorAction SilentlyContinue
|
|
if (-not $wailsCmd) {
|
|
Write-Host ">> Installing Wails v3 CLI..." -ForegroundColor Yellow
|
|
& go install github.com/wailsapp/wails/v3/cmd/wails3@v3.0.0-alpha.74
|
|
}
|
|
Write-Host " -> Wails v3 CLI is ready" -ForegroundColor Gray
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 5. Git Pull latest code
|
|
# ------------------------------------------------------------------------------
|
|
Write-Host "[5/6] Syncing latest code from branch '$Branch'..." -ForegroundColor White
|
|
$env:GIT_TERMINAL_PROMPT = "0"
|
|
if (Test-Path (Join-Path $rootDir ".git")) {
|
|
try {
|
|
& git fetch origin $Branch --progress
|
|
& git checkout $Branch
|
|
$pullOutput = & git pull origin $Branch
|
|
Write-Host " -> $pullOutput" -ForegroundColor Gray
|
|
} catch {
|
|
Write-Host "Warning: Could not pull latest changes (offline or local modifications). Proceeding with current local code." -ForegroundColor DarkYellow
|
|
}
|
|
} else {
|
|
Write-Host ">> Cloning repository from $RepoUrl..." -ForegroundColor Yellow
|
|
& git clone --branch $Branch $RepoUrl .
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 6. Build Project (Frontend + Go Backend)
|
|
# ------------------------------------------------------------------------------
|
|
Write-Host "[6/6] Compiling G-Launcher..." -ForegroundColor White
|
|
|
|
Write-Host " [6.1] Installing Frontend dependencies..." -ForegroundColor Gray
|
|
& npm --prefix frontend install --no-audit --no-fund
|
|
|
|
Write-Host " [6.2] Building React 19 Frontend..." -ForegroundColor Gray
|
|
& npm --prefix frontend run build
|
|
|
|
Write-Host " [6.3] Running go mod tidy..." -ForegroundColor Gray
|
|
& go mod tidy
|
|
|
|
$binDir = Join-Path $rootDir "bin"
|
|
if (!(Test-Path $binDir)) { New-Item -ItemType Directory -Path $binDir -Force | Out-Null }
|
|
$outputExe = Join-Path $binDir "G-Launcher.exe"
|
|
$sysoPath = Join-Path $rootDir "wails_windows_amd64.syso"
|
|
|
|
try {
|
|
Write-Host " [6.4] Generating Windows Manifest & Syso..." -ForegroundColor Gray
|
|
if (Get-Command wails3 -ErrorAction SilentlyContinue) {
|
|
& wails3 generate syso -arch amd64 -icon build/windows/icon.ico -manifest build/windows/wails.exe.manifest -info build/windows/info.json -out $sysoPath
|
|
}
|
|
} catch {
|
|
Write-Host "Warning: Syso generation skipped, building executable without embedded syso." -ForegroundColor DarkYellow
|
|
}
|
|
|
|
Write-Host " [6.5] Compiling Go backend binary..." -ForegroundColor Gray
|
|
& go build -tags production -trimpath -buildvcs=false -ldflags="-w -s -H windowsgui" -o $outputExe .
|
|
|
|
if (Test-Path $sysoPath) {
|
|
Remove-Item -Path $sysoPath -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
if ($LASTEXITCODE -ne 0 -or !(Test-Path $outputExe)) {
|
|
Write-Host ""
|
|
Write-Host "[ERROR] Compilation failed!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
$upxCmd = Get-Command upx -ErrorAction SilentlyContinue
|
|
if ($upxCmd) {
|
|
Write-Host " [6.6] Compressing binary with UPX..." -ForegroundColor Gray
|
|
& upx --best --lzma $outputExe
|
|
}
|
|
|
|
$exeSize = (Get-Item $outputExe).Length / 1MB
|
|
Write-Host ""
|
|
Write-Host "==========================================================" -ForegroundColor Green
|
|
Write-Host ("Build Successful! Output: bin/G-Launcher.exe ({0:N2} MB)" -f $exeSize) -ForegroundColor Green
|
|
Write-Host "==========================================================" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
if (-not $NoLaunch) {
|
|
Write-Host "Launching G-Launcher..." -ForegroundColor Cyan
|
|
Start-Process -FilePath $outputExe
|
|
} |