File size: 2,214 Bytes
145407d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | $ErrorActionPreference = "Stop"
$root = $PSScriptRoot
if (-not $root) { $root = (Get-Location).Path }
$toolsDir = Join-Path $root "tools"
$certsDir = Join-Path $root "certs"
New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null
New-Item -ItemType Directory -Force -Path $certsDir | Out-Null
$mkcert = Get-Command mkcert -ErrorAction SilentlyContinue
$mkcertPath = $null
if ($mkcert) {
$mkcertPath = $mkcert.Source
} else {
$mkcertPath = Join-Path $toolsDir "mkcert.exe"
if (-not (Test-Path $mkcertPath)) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$rel = Invoke-RestMethod -Uri "https://api.github.com/repos/FiloSottile/mkcert/releases/latest"
$asset = $rel.assets | Where-Object { $_.name -eq "mkcert-v$($rel.tag_name.TrimStart('v'))-windows-amd64.exe" } | Select-Object -First 1
if (-not $asset) {
$asset = $rel.assets | Where-Object { $_.name -match "windows-amd64\.exe$" } | Select-Object -First 1
}
if (-not $asset) {
throw "无法从 GitHub release 自动定位 mkcert 的 windows-amd64.exe"
}
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $mkcertPath -UseBasicParsing
}
}
& $mkcertPath -install | Out-Host
$certFile = Join-Path $certsDir "localhost.pem"
$keyFile = Join-Path $certsDir "localhost-key.pem"
& $mkcertPath -key-file $keyFile -cert-file $certFile "localhost" "127.0.0.1" "::1" | Out-Host
$pythonCandidates = @(
(Join-Path $root ".venv\Scripts\python.exe"),
(Join-Path $root ".venv_cpu\Scripts\python.exe")
)
$pythonPath = $pythonCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $pythonPath) {
$py = Get-Command python -ErrorAction SilentlyContinue
if ($py) { $pythonPath = $py.Source }
}
if (-not $pythonPath) {
throw "找不到 python。请先创建 venv(.venv 或 .venv_cpu)或确保 python 在 PATH 里。"
}
$env:PPV5_USE_HTTPS = "1"
$env:PPV5_HOST = "127.0.0.1"
$env:PPV5_PORT = "9346"
$env:PPV5_TLS_CERT = $certFile
$env:PPV5_TLS_KEY = $keyFile
if (-not $env:PPV5_CORS_ALLOWED_ORIGINS) {
$env:PPV5_CORS_ALLOWED_ORIGINS = "https://typst-app-clone.pages.dev"
}
Set-Location $root
& $pythonPath (Join-Path $root "main_v6.py")
|