修复本地服务启动脚本
This commit is contained in:
@@ -1,67 +1,55 @@
|
|||||||
# serve.ps1 - 开发服务器启动脚本
|
# serve.ps1 - development server launcher
|
||||||
Write-Host "=== 启动开发服务器 ===" -ForegroundColor Cyan
|
Write-Host "=== Start Dev Server ===" -ForegroundColor Cyan
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
# 检查是否已构建
|
|
||||||
if (-not (Test-Path "public/wasm/smart_math.js")) {
|
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"
|
& "$PSScriptRoot\build.ps1"
|
||||||
|
|
||||||
if (-not (Test-Path "public/wasm/smart_math.js")) {
|
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
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 检查 Python
|
$pythonCommand = $null
|
||||||
try {
|
$pythonCandidates = @(
|
||||||
python --version 2>&1 | Out-Null
|
|
||||||
$hasPython = $true
|
|
||||||
} catch {
|
|
||||||
$hasPython = $false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not $hasPython) {
|
|
||||||
Write-Host "[!] 未找到 Python,尝试使用系统 Python..." -ForegroundColor Yellow
|
|
||||||
|
|
||||||
# 尝试常见的 Python 路径
|
|
||||||
$pythonPaths = @(
|
|
||||||
"python",
|
"python",
|
||||||
"python3",
|
|
||||||
"py",
|
"py",
|
||||||
|
"python3",
|
||||||
"C:\Python39\python.exe",
|
"C:\Python39\python.exe",
|
||||||
"C:\Python38\python.exe",
|
"C:\Python38\python.exe",
|
||||||
"C:\Python37\python.exe"
|
"C:\Python37\python.exe"
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach ($path in $pythonPaths) {
|
foreach ($candidate in $pythonCandidates) {
|
||||||
try {
|
try {
|
||||||
& $path --version 2>&1 | Out-Null
|
& $candidate --version 2>&1 | Out-Null
|
||||||
$env:PATH = "$(Split-Path $path -ErrorAction SilentlyContinue);$env:PATH"
|
if ($LASTEXITCODE -eq 0) {
|
||||||
$hasPython = $true
|
$pythonCommand = $candidate
|
||||||
Write-Host "[✓] 找到 Python: $path" -ForegroundColor Green
|
Write-Host "[ok] Python found: $candidate" -ForegroundColor Green
|
||||||
break
|
break
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $hasPython) {
|
if (-not $pythonCommand) {
|
||||||
Write-Host "[✗] 未找到 Python,请安装 Python 3.7+ 并添加到 PATH" -ForegroundColor Red
|
Write-Host "[x] Python 3.7+ not found in PATH" -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# 启动服务器
|
$publicDir = Resolve-Path "public"
|
||||||
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
|
|
||||||
|
|
||||||
Set-Location "public"
|
Write-Host "[ ] Starting dev server..." -ForegroundColor Cyan
|
||||||
python -m http.server 8080
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user