修复本地服务启动脚本

This commit is contained in:
zhangshun
2026-06-01 17:10:36 +08:00
parent 34d2b3c629
commit 2d9bd1d4d7

View File

@@ -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
}
if (-not $hasPython) {
Write-Host "[!] 未找到 Python尝试使用系统 Python..." -ForegroundColor Yellow
# 尝试常见的 Python 路径
$pythonPaths = @(
$pythonCommand = $null
$pythonCandidates = @(
"python",
"python3",
"py",
"python3",
"C:\Python39\python.exe",
"C:\Python38\python.exe",
"C:\Python37\python.exe"
)
)
foreach ($path in $pythonPaths) {
foreach ($candidate in $pythonCandidates) {
try {
& $path --version 2>&1 | Out-Null
$env:PATH = "$(Split-Path $path -ErrorAction SilentlyContinue);$env:PATH"
$hasPython = $true
Write-Host "[✓] 找到 Python: $path" -ForegroundColor Green
& $candidate --version 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
$pythonCommand = $candidate
Write-Host "[ok] Python found: $candidate" -ForegroundColor Green
break
}
} 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
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