1- # Requires -Version 7.3
1+ # Requires -Version 7.4
22
33# This script builds the documentation website, starts a web server and opens the site in your browser. Intended for local development.
44
55param (
66 # 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
1010)
1111
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 '
1717
1818function EnsureHttpServerIsInstalled {
1919 if ((Get-Command " npm" - ErrorAction SilentlyContinue) -eq $null ) {
2020 throw " Unable to find npm in your PATH. please install Node.js first."
2121 }
2222
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+ # Workaround for error ENOENT returned from npm list, after installing Node.js on Windows.
29+ # See https://stackoverflow.com/questions/25093276/node-js-windows-error-enoent-stat-c-users-rt-appdata-roaming-npm
30+ if ($IsWindows ) {
31+ New-Item - ItemType Directory - Force - Path $env: APPDATA \npm > $null
32+ }
2533
26- if ($LastExitCode -eq 1 ) {
34+ npm list -- depth 1 -- global httpserver > $null
35+
36+ if ($LastExitCode -eq 1 ) {
37+ Write-Host " httpserver not found."
38+ $global :hasHttpServerInstalled = $false
39+ }
40+ }
41+
42+ if ($global :hasHttpServerInstalled -eq $false ) {
43+ Write-Host " Installing httpserver."
2744 npm install - g httpserver
2845 }
2946}
3047
3148EnsureHttpServerIsInstalled
32- VerifySuccessExitCode
3349
3450if (-Not $NoBuild -Or -Not (Test-Path - Path _site)) {
3551 Remove-Item _site\* - Recurse - ErrorAction Ignore
36-
37- dotnet build .. -- configuration Release
38- VerifySuccessExitCode
39-
52+ dotnet build .. -- configuration Release / p:RunAnalyzers= false
4053 Invoke-Expression ./ generate- examples.ps1
4154} else {
4255 Remove-Item _site\* - Recurse - ErrorAction Ignore
4356}
4457
4558dotnet tool restore
46- VerifySuccessExitCode
4759
4860$env: DOCFX_SOURCE_BRANCH_NAME = " dev"
49- dotnet docfx ./ docfx.json -- warningsAsErrors true
50- VerifySuccessExitCode
61+ dotnet docfx docfx.json -- warningsAsErrors true
5162
5263Copy-Item - Force home/* .html _site/
5364Copy-Item - Force home/* .ico _site/
@@ -63,7 +74,7 @@ if (-Not $NoOpen) {
6374}
6475
6576Write-Host " "
66- Write-Host " Web server started. Press Enter to close ."
77+ Write-Host " Web server started. Site is available at http://localhost:8080. Press Enter to stop web server ."
6778$key = [Console ]::ReadKey()
6879
6980Stop-Job - Id $webServerJob.Id
0 commit comments