|
| 1 | +$ErrorActionPreference = 'Stop' |
| 2 | + |
| 3 | +$hostAddress = if ($env:DOCS_HOST) { $env:DOCS_HOST } else { '127.0.0.1' } |
| 4 | +$port = if ($env:DOCS_PORT) { $env:DOCS_PORT } else { '8080' } |
| 5 | + |
| 6 | +dotnet tool restore |
| 7 | +Push-Location site |
| 8 | +try { |
| 9 | + if (Get-Command python3 -ErrorAction SilentlyContinue) { |
| 10 | + $pythonCommand = 'python3' |
| 11 | + $pythonArgs = @('-m', 'http.server', $port, '--bind', $hostAddress) |
| 12 | + } elseif (Get-Command python -ErrorAction SilentlyContinue) { |
| 13 | + $pythonCommand = 'python' |
| 14 | + $pythonArgs = @('-m', 'http.server', $port, '--bind', $hostAddress) |
| 15 | + } elseif (Get-Command py -ErrorAction SilentlyContinue) { |
| 16 | + $pythonCommand = 'py' |
| 17 | + $pythonArgs = @('-3', '-m', 'http.server', $port, '--bind', $hostAddress) |
| 18 | + } else { |
| 19 | + Write-Warning "Python runtime not found (python3/python/py). Falling back to 'lunet serve'." |
| 20 | + dotnet tool run lunet --stacktrace serve |
| 21 | + return |
| 22 | + } |
| 23 | + |
| 24 | + dotnet tool run lunet --stacktrace build --dev |
| 25 | + |
| 26 | + $watcher = Start-Process -FilePath 'dotnet' ` |
| 27 | + -ArgumentList @('tool', 'run', 'lunet', '--stacktrace', 'build', '--dev', '--watch') ` |
| 28 | + -NoNewWindow ` |
| 29 | + -PassThru |
| 30 | + |
| 31 | + try { |
| 32 | + Write-Host "Serving docs at http://${hostAddress}:$port" |
| 33 | + Write-Host 'Watching docs with Lunet (dev mode)...' |
| 34 | + |
| 35 | + Push-Location '.lunet/build/www' |
| 36 | + try { |
| 37 | + & $pythonCommand @pythonArgs |
| 38 | + } |
| 39 | + finally { |
| 40 | + Pop-Location |
| 41 | + } |
| 42 | + } |
| 43 | + finally { |
| 44 | + if ($watcher -and -not $watcher.HasExited) { |
| 45 | + Stop-Process -Id $watcher.Id -Force |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | +finally { |
| 50 | + Pop-Location |
| 51 | +} |
0 commit comments