Skip to content

Commit 714b09a

Browse files
committed
Interrupt on error when building docs locally. Added switch for faster inner loop.
1 parent be99234 commit 714b09a

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

docs/build-dev.ps1

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
1-
# This script assumes that you have already installed docfx and httpserver.
1+
#Requires -Version 7.0
2+
3+
# This script builds the documentation website, starts a web server and opens the site in your browser. Intended for local development.
4+
# It is assumed that you have already installed docfx and httpserver.
25
# If that's not the case, run the next commands:
36
# choco install docfx -y
47
# npm install -g httpserver
58

6-
Remove-Item _site -Recurse -ErrorAction Ignore
9+
param(
10+
# Specify -NoBuild to skip code build and examples generation. This runs faster, so handy when only editing Markdown files.
11+
[switch] $NoBuild=$False
12+
)
13+
14+
function VerifySuccessExitCode {
15+
if ($LastExitCode -ne 0) {
16+
throw "Command failed with exit code $LastExitCode."
17+
}
18+
}
19+
20+
if (-Not $NoBuild -Or -Not (Test-Path -Path _site)) {
21+
Remove-Item _site -Recurse -ErrorAction Ignore
722

8-
dotnet build .. --configuration Release
9-
Invoke-Expression ./generate-examples.ps1
23+
dotnet build .. --configuration Release
24+
VerifySuccessExitCode
25+
26+
Invoke-Expression ./generate-examples.ps1
27+
}
1028

1129
docfx ./docfx.json
12-
Copy-Item home/*.html _site/
13-
Copy-Item home/*.ico _site/
14-
Copy-Item -Recurse home/assets/* _site/styles/
30+
VerifySuccessExitCode
31+
32+
Copy-Item -Force home/*.html _site/
33+
Copy-Item -Force home/*.ico _site/
34+
Copy-Item -Force -Recurse home/assets/* _site/styles/
1535

1636
cd _site
1737
$webServerJob = httpserver &

docs/generate-examples.ps1

+19-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function Get-WebServer-ProcessId {
88
$processId = $(lsof -ti:14141)
99
}
1010
elseif ($IsWindows) {
11-
$processId = $(Get-NetTCPConnection -LocalPort 14141 -ErrorAction SilentlyContinue).OwningProcess
11+
$processId = $(Get-NetTCPConnection -LocalPort 14141 -ErrorAction SilentlyContinue).OwningProcess?[0]
1212
}
1313
else {
1414
throw [System.Exception] "Unsupported operating system."
@@ -22,7 +22,11 @@ function Kill-WebServer {
2222

2323
if ($processId -ne $null) {
2424
Write-Output "Stopping web server"
25-
Get-Process -Id $processId | Stop-Process
25+
Get-Process -Id $processId | Stop-Process -ErrorVariable stopErrorMessage
26+
27+
if ($stopErrorMessage) {
28+
throw "Failed to stop web server: $stopErrorMessage"
29+
}
2630
}
2731
}
2832

@@ -40,18 +44,21 @@ function Start-WebServer {
4044
Kill-WebServer
4145
Start-WebServer
4246

43-
Remove-Item -Force -Path .\request-examples\*.json
47+
try {
48+
Remove-Item -Force -Path .\request-examples\*.json
4449

45-
$scriptFiles = Get-ChildItem .\request-examples\*.ps1
46-
foreach ($scriptFile in $scriptFiles) {
47-
$jsonFileName = [System.IO.Path]::GetFileNameWithoutExtension($scriptFile.Name) + "_Response.json"
50+
$scriptFiles = Get-ChildItem .\request-examples\*.ps1
51+
foreach ($scriptFile in $scriptFiles) {
52+
$jsonFileName = [System.IO.Path]::GetFileNameWithoutExtension($scriptFile.Name) + "_Response.json"
4853

49-
Write-Output "Writing file: $jsonFileName"
50-
& $scriptFile.FullName > .\request-examples\$jsonFileName
54+
Write-Output "Writing file: $jsonFileName"
55+
& $scriptFile.FullName > .\request-examples\$jsonFileName
5156

52-
if ($LastExitCode -ne 0) {
53-
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed with exit code $LastExitCode."
57+
if ($LastExitCode -ne 0) {
58+
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed with exit code $LastExitCode."
59+
}
5460
}
5561
}
56-
57-
Kill-WebServer
62+
finally {
63+
Kill-WebServer
64+
}

0 commit comments

Comments
 (0)