diff --git a/scripts/serve.ps1 b/scripts/serve.ps1 index 6729456..03cb809 100644 --- a/scripts/serve.ps1 +++ b/scripts/serve.ps1 @@ -1,67 +1,55 @@ -# serve.ps1 - 开发服务器启动脚本 -Write-Host "=== 启动开发服务器 ===" -ForegroundColor Cyan +# serve.ps1 - development server launcher +Write-Host "=== Start Dev Server ===" -ForegroundColor Cyan Write-Host "" -# 检查是否已构建 if (-not (Test-Path "public/wasm/smart_math.js")) { - Write-Host "[!] 未找到 WASM 文件,正在构建..." -ForegroundColor Yellow + Write-Host "[!] WASM output not found, building first..." -ForegroundColor Yellow & "$PSScriptRoot\build.ps1" - + if (-not (Test-Path "public/wasm/smart_math.js")) { - Write-Host "[✗] 构建失败,无法启动服务器" -ForegroundColor Red + Write-Host "[x] Build failed, cannot start server" -ForegroundColor Red exit 1 } } -# 检查 Python -try { - python --version 2>&1 | Out-Null - $hasPython = $true -} catch { - $hasPython = $false -} +$pythonCommand = $null +$pythonCandidates = @( + "python", + "py", + "python3", + "C:\Python39\python.exe", + "C:\Python38\python.exe", + "C:\Python37\python.exe" +) -if (-not $hasPython) { - Write-Host "[!] 未找到 Python,尝试使用系统 Python..." -ForegroundColor Yellow - - # 尝试常见的 Python 路径 - $pythonPaths = @( - "python", - "python3", - "py", - "C:\Python39\python.exe", - "C:\Python38\python.exe", - "C:\Python37\python.exe" - ) - - foreach ($path in $pythonPaths) { - try { - & $path --version 2>&1 | Out-Null - $env:PATH = "$(Split-Path $path -ErrorAction SilentlyContinue);$env:PATH" - $hasPython = $true - Write-Host "[✓] 找到 Python: $path" -ForegroundColor Green +foreach ($candidate in $pythonCandidates) { + try { + & $candidate --version 2>&1 | Out-Null + if ($LASTEXITCODE -eq 0) { + $pythonCommand = $candidate + Write-Host "[ok] Python found: $candidate" -ForegroundColor Green break - } catch { - continue } + } catch { + continue } } -if (-not $hasPython) { - Write-Host "[✗] 未找到 Python,请安装 Python 3.7+ 并添加到 PATH" -ForegroundColor Red +if (-not $pythonCommand) { + Write-Host "[x] Python 3.7+ not found in PATH" -ForegroundColor Red exit 1 } -# 启动服务器 -Write-Host "[ ] 启动开发服务器..." -ForegroundColor Cyan -Write-Host "" -Write-Host "🌐 服务器信息:" -ForegroundColor White -Write-Host "├─ 地址: http://localhost:8080" -ForegroundColor Cyan -Write-Host "├─ 目录: $(Resolve-Path "public")" -ForegroundColor Gray -Write-Host "├─ 主页: /smart_test.html" -ForegroundColor Gray -Write-Host "└─ 按 Ctrl+C 停止服务器" -ForegroundColor Yellow -Write-Host "" -Write-Host ("─" * 50) -ForegroundColor DarkGray +$publicDir = Resolve-Path "public" -Set-Location "public" -python -m http.server 8080 \ No newline at end of file +Write-Host "[ ] Starting dev server..." -ForegroundColor Cyan +Write-Host "" +Write-Host "Server info:" -ForegroundColor White +Write-Host " - URL: http://localhost:8080" -ForegroundColor Cyan +Write-Host " - Root: $publicDir" -ForegroundColor Gray +Write-Host " - Home: /smart_test.html" -ForegroundColor Gray +Write-Host " - Stop: Ctrl+C" -ForegroundColor Yellow +Write-Host "" + +Set-Location $publicDir +& $pythonCommand -m http.server 8080