|
1 | | -#Requires -Version 7.3 |
| 1 | +#Requires -Version 7.4 |
2 | 2 |
|
3 | 3 | # This script builds the documentation website, starts a web server and opens the site in your browser. Intended for local development. |
4 | 4 |
|
5 | 5 | param( |
6 | 6 | # Specify -NoBuild to skip code build and examples generation. This runs faster, so handy when only editing Markdown files. |
7 | | - [switch] $NoBuild=$False, |
8 | | - # Specify -NoOpen to skip opening the documentation website in a web browser. |
9 | | - [switch] $NoOpen=$False |
| 7 | + [switch] $NoBuild=$false, |
| 8 | + # Specify -NoOpen to skip opening the documentation website in a web browser (still starts the web server). |
| 9 | + [switch] $NoOpen=$false |
10 | 10 | ) |
11 | 11 |
|
12 | | -function VerifySuccessExitCode { |
13 | | - if ($LastExitCode -ne 0) { |
14 | | - throw "Command failed with exit code $LastExitCode." |
15 | | - } |
16 | | -} |
| 12 | +$ErrorActionPreference = "Stop" |
| 13 | +$PSNativeCommandUseErrorActionPreference = $true |
| 14 | + |
| 15 | +# Workaround for bug at https://github.com/PowerShell/PowerShell/issues/23875#issuecomment-2672336383 |
| 16 | +$PSDefaultParameterValues['Remove-Item:ProgressAction'] = 'SilentlyContinue' |
17 | 17 |
|
18 | 18 | function EnsureHttpServerIsInstalled { |
19 | 19 | if ((Get-Command "npm" -ErrorAction SilentlyContinue) -eq $null) { |
20 | 20 | throw "Unable to find npm in your PATH. please install Node.js first." |
21 | 21 | } |
22 | 22 |
|
23 | | - # If this command fails with ENOENT after installing Node.js on Windows, manually create the directory %APPDATA%\npm. |
24 | | - npm list --depth 1 --global httpserver >$null |
| 23 | + $global:hasHttpServerInstalled = $true |
| 24 | + |
| 25 | + & { |
| 26 | + $PSNativeCommandUseErrorActionPreference = $false |
| 27 | + |
| 28 | + # If this command fails with ENOENT after installing Node.js on Windows, manually create the directory %APPDATA%\npm. |
| 29 | + npm list --depth 1 --global httpserver >$null |
25 | 30 |
|
26 | | - if ($LastExitCode -eq 1) { |
| 31 | + if ($LastExitCode -eq 1) { |
| 32 | + Write-Host "httpserver not found." |
| 33 | + $global:hasHttpServerInstalled = $false |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + if ($global:hasHttpServerInstalled -eq $false) { |
| 38 | + Write-Host "Installing httpserver." |
27 | 39 | npm install -g httpserver |
28 | 40 | } |
29 | 41 | } |
30 | 42 |
|
31 | 43 | EnsureHttpServerIsInstalled |
32 | | -VerifySuccessExitCode |
33 | 44 |
|
34 | 45 | if (-Not $NoBuild -Or -Not (Test-Path -Path _site)) { |
35 | 46 | Remove-Item _site\* -Recurse -ErrorAction Ignore |
36 | | - |
37 | 47 | dotnet build .. --configuration Release |
38 | | - VerifySuccessExitCode |
39 | | - |
40 | 48 | Invoke-Expression ./generate-examples.ps1 |
41 | 49 | } else { |
42 | 50 | Remove-Item _site\* -Recurse -ErrorAction Ignore |
43 | 51 | } |
44 | 52 |
|
45 | 53 | dotnet tool restore |
46 | | -VerifySuccessExitCode |
47 | 54 |
|
48 | 55 | $env:DOCFX_SOURCE_BRANCH_NAME="dev" |
49 | | -dotnet docfx ./docfx.json --warningsAsErrors true |
50 | | -VerifySuccessExitCode |
| 56 | +dotnet docfx docfx.json --warningsAsErrors true |
51 | 57 |
|
52 | 58 | Copy-Item -Force home/*.html _site/ |
53 | 59 | Copy-Item -Force home/*.ico _site/ |
|
0 commit comments