diff --git a/.gitignore b/.gitignore index 37873fb..8df0420 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,13 @@ .task bin/ +tools/ tests/ server/ proxy/ temp/ patch/ .history/ +*.old frontend/dist frontend/node_modules build/bin/ diff --git a/README.md b/README.md index cdb9166..084e372 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,14 @@ flowchart TD ### 🛠️ วิธีการรันและบิลด์ (Development & Build) -#### 1. ติดตั้ง Dependencies +#### ⚡ บิลด์และอัปเดตอัตโนมัติในคลิกเดียว (Zero-Dependency One-Click Auto-Update) +หากคุณหรือผู้ใช้งานไม่มี Go, Node.js, Git หรือ Wails ติดตั้งในเครื่อง สามารถดับเบิลคลิกไฟล์นี้ได้ทันที: +```cmd +update-and-build.bat +``` +> ระบบจะดาวน์โหลด Portable MinGit, Go 1.24, Node.js v22 และ Wails v3 CLI ไว้ในโฟลเดอร์ `tools/` อัตโนมัติ จากนั้นจะ `git pull` โค้ดล่าสุดจากสาขา `Dev` แล้วทำการคอมไพล์ออกมาเป็น `bin/G-Launcher.exe` พร้อมเปิดใช้งานทันที + +#### 1. ติดตั้ง Dependencies (สำหรับผู้ที่มี Toolchain ในเครื่องแล้ว) ```bash # ติดตั้งแพ็กเกจ Frontend cd frontend @@ -190,6 +197,7 @@ G-Launcher/ ├── proto/ # Protobuf definitions ├── scripts/ # Release & version calculation scripts (launcher-release.mjs) ├── AGENTS.md # Engineering guidelines & development rules +├── update-and-build.bat # Zero-dependency auto-updater & local builder ├── build.bat # Windows build & UPX compression script ├── main.go # Application entry point & service registration └── Taskfile.yml # Wails build tasks definition diff --git a/build.bat b/build.bat index a44dada..2ec9cd3 100644 --- a/build.bat +++ b/build.bat @@ -1,29 +1,44 @@ @echo off chcp 65001 >nul -title 🔧 Wails3 Build & Compress Script +title 🔧 G-Launcher Build Script +cd /d "%~dp0" echo ============================================ -echo 🔧 เริ่มต้น Build โปรเจกต์... +echo 🔧 เริ่มต้น Build โปรเจกต์ G-Launcher... echo ============================================ -start /wait wails3 build -echo. -echo ============================================ -echo 🔧 กำลังบีบอัดและลบข้อมูล debug... -echo ============================================ -for %%f in ("build\bin\*.exe") do ( - echo 🔹 ลดขนาดไฟล์ %%~nxf ... - upx --best --lzma "%%f" +where wails3 >nul 2>nul +if %errorlevel% neq 0 ( + echo [INFO] ตรวจไม่พบ Wails3 ในระบบ กำลังเรียกใช้ระบบ Bootstrap อัตโนมัติ... + powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\bootstrap.ps1" -NoLaunch + goto done +) + +call wails3 build +if %errorlevel% neq 0 ( + echo. + echo ❌ Wails3 build ไม่สำเร็จ กำลังสลับไปใช้ระบบ Bootstrap สำรอง... + powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\bootstrap.ps1" -NoLaunch + goto done ) echo. echo ============================================ -echo ✅ เสร็จสิ้นขั้นตอน Build และลดขนาดไฟล์! +echo 🔧 ตรวจสอบและบีบอัดไฟล์ EXE (UPX)... echo ============================================ -pause +where upx >nul 2>nul +if %errorlevel% equ 0 ( + for %%f in ("bin\*.exe" "build\bin\*.exe") do ( + if exist "%%f" ( + echo 🔹 บีบอัด %%~nxf ... + upx --best --lzma "%%f" + ) + ) +) +:done echo. echo ============================================ -echo 📦 เริ่ม Package... +echo ✅ เสร็จสิ้นขั้นตอน Build! echo ============================================ -start wails3 package +pause diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1 new file mode 100644 index 0000000..128f97d --- /dev/null +++ b/scripts/bootstrap.ps1 @@ -0,0 +1,201 @@ +# ============================================================================== +# 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 +} \ No newline at end of file diff --git a/update-and-build.bat b/update-and-build.bat new file mode 100644 index 0000000..da4d296 --- /dev/null +++ b/update-and-build.bat @@ -0,0 +1,21 @@ +@echo off +chcp 65001 >nul +title 🚀 G-Launcher Auto-Updater & Local Builder +cd /d "%~dp0" + +echo ========================================================== +echo 🚀 เริ่มต้นระบบอัปเดตและคอมไพล์ G-Launcher +echo ========================================================== +echo. + +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\bootstrap.ps1" %* +if errorlevel 1 ( + echo. + echo ❌ มีข้อผิดพลาดเกิดขึ้นระหว่างการทำงาน! + pause + exit /b 1 +) + +echo. +echo กดปุ่มใดก็ได้เพื่อปิดหน้าต่างนี้... +pause >nul