Initial commit: FunConnect project with server, relay, client and admin panel
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
181
scripts/build-client.ps1
Normal file
181
scripts/build-client.ps1
Normal file
@@ -0,0 +1,181 @@
|
||||
#
|
||||
# FunMC 客户端构建脚本 (Windows)
|
||||
# 用法: .\scripts\build-client.ps1 -Platform <平台> -ServerUrl <服务器URL>
|
||||
#
|
||||
# 示例:
|
||||
# .\scripts\build-client.ps1 -Platform all -ServerUrl "http://funmc.com:3000"
|
||||
# .\scripts\build-client.ps1 -Platform windows -ServerUrl "http://192.168.1.100:3000"
|
||||
#
|
||||
|
||||
param(
|
||||
[string]$Platform = "all",
|
||||
[string]$ServerUrl = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# 配置
|
||||
$Version = (Get-Content "client\Cargo.toml" | Select-String 'version = "' | Select-Object -First 1) -replace '.*"([^"]+)".*', '$1'
|
||||
$OutputDir = ".\dist"
|
||||
|
||||
# 颜色输出函数
|
||||
function Write-Info($Message) { Write-Host "[INFO] $Message" -ForegroundColor Cyan }
|
||||
function Write-Success($Message) { Write-Host "[✓] $Message" -ForegroundColor Green }
|
||||
function Write-Warning($Message) { Write-Host "[!] $Message" -ForegroundColor Yellow }
|
||||
function Write-Err($Message) { Write-Host "[✗] $Message" -ForegroundColor Red }
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
|
||||
Write-Host "║ FunMC 客户端构建脚本 v$Version ║" -ForegroundColor Cyan
|
||||
Write-Host "║ 魔幻方开发 ║" -ForegroundColor Cyan
|
||||
Write-Host "╚═══════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# 检查依赖
|
||||
function Test-Dependencies {
|
||||
Write-Info "检查构建依赖..."
|
||||
|
||||
if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {
|
||||
Write-Err "错误: 未找到 Rust/Cargo"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
|
||||
Write-Err "错误: 未找到 Node.js"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
|
||||
Write-Err "错误: 未找到 npm"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Success "依赖检查通过"
|
||||
}
|
||||
|
||||
# 写入服务器配置
|
||||
function Write-Config {
|
||||
if ($ServerUrl) {
|
||||
Write-Info "写入服务器配置: $ServerUrl"
|
||||
|
||||
$config = @{
|
||||
server_url = $ServerUrl
|
||||
version = $Version
|
||||
} | ConvertTo-Json
|
||||
|
||||
$config | Out-File -FilePath "client\ui\src\config.json" -Encoding UTF8
|
||||
|
||||
Write-Success "配置写入完成"
|
||||
}
|
||||
}
|
||||
|
||||
# 构建前端
|
||||
function Build-Frontend {
|
||||
Write-Info "构建前端..."
|
||||
|
||||
Push-Location "client\ui"
|
||||
npm install
|
||||
npm run build
|
||||
Pop-Location
|
||||
|
||||
Write-Success "前端构建完成"
|
||||
}
|
||||
|
||||
# 构建 Windows
|
||||
function Build-Windows {
|
||||
Write-Info "构建 Windows (x64)..."
|
||||
|
||||
Push-Location "client"
|
||||
cargo tauri build
|
||||
Pop-Location
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
|
||||
|
||||
$msiBundles = Get-ChildItem "client\target\release\bundle\msi\*.msi" -ErrorAction SilentlyContinue
|
||||
if ($msiBundles) {
|
||||
Copy-Item $msiBundles[0].FullName "$OutputDir\FunMC-$Version-windows-x64.msi"
|
||||
}
|
||||
|
||||
$nsiBundles = Get-ChildItem "client\target\release\bundle\nsis\*.exe" -ErrorAction SilentlyContinue
|
||||
if ($nsiBundles) {
|
||||
Copy-Item $nsiBundles[0].FullName "$OutputDir\FunMC-$Version-windows-x64.exe"
|
||||
}
|
||||
|
||||
Write-Success "Windows 构建完成"
|
||||
}
|
||||
|
||||
# 构建 Android
|
||||
function Build-Android {
|
||||
Write-Info "构建 Android..."
|
||||
|
||||
if (-not $env:ANDROID_HOME) {
|
||||
Write-Warning "未设置 ANDROID_HOME,跳过 Android 构建"
|
||||
return
|
||||
}
|
||||
|
||||
Push-Location "client"
|
||||
cargo tauri android build --apk
|
||||
Pop-Location
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
|
||||
|
||||
$apkBundles = Get-ChildItem "client\gen\android\app\build\outputs\apk\universal\release\*.apk" -ErrorAction SilentlyContinue
|
||||
if ($apkBundles) {
|
||||
Copy-Item $apkBundles[0].FullName "$OutputDir\FunMC-$Version-android.apk"
|
||||
}
|
||||
|
||||
Write-Success "Android 构建完成"
|
||||
}
|
||||
|
||||
# 显示构建结果
|
||||
function Show-Results {
|
||||
Write-Host ""
|
||||
Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
|
||||
Write-Host "║ 构建完成! ║" -ForegroundColor Cyan
|
||||
Write-Host "╚═══════════════════════════════════════════════════════════╝" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "输出目录: $OutputDir" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
if (Test-Path $OutputDir) {
|
||||
Write-Host "构建产物:"
|
||||
Get-ChildItem $OutputDir | Format-Table Name, Length -AutoSize
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "部署说明:" -ForegroundColor Yellow
|
||||
Write-Host "1. 将 $OutputDir 目录下的文件复制到服务器的 downloads 目录"
|
||||
Write-Host "2. 用户访问 http://your-server:3000/download 即可下载"
|
||||
Write-Host ""
|
||||
Write-Host "魔幻方开发" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# 主流程
|
||||
try {
|
||||
Test-Dependencies
|
||||
Write-Config
|
||||
Build-Frontend
|
||||
|
||||
switch ($Platform) {
|
||||
"windows" {
|
||||
Build-Windows
|
||||
}
|
||||
"android" {
|
||||
Build-Android
|
||||
}
|
||||
"all" {
|
||||
Build-Windows
|
||||
Build-Android
|
||||
}
|
||||
default {
|
||||
Write-Err "未知平台: $Platform"
|
||||
Write-Host "支持的平台: windows, android, all"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Show-Results
|
||||
} catch {
|
||||
Write-Err "构建过程中出错: $_"
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user