Skip to content

Commit f84a960

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

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
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

+13-10
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,21 @@ function Start-WebServer {
4040
Kill-WebServer
4141
Start-WebServer
4242

43-
Remove-Item -Force -Path .\request-examples\*.json
43+
try {
44+
Remove-Item -Force -Path .\request-examples\*.json
4445

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

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

52-
if ($LastExitCode -ne 0) {
53-
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed with exit code $LastExitCode."
53+
if ($LastExitCode -ne 0) {
54+
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed with exit code $LastExitCode."
55+
}
5456
}
5557
}
56-
57-
Kill-WebServer
58+
finally {
59+
Kill-WebServer
60+
}

0 commit comments

Comments
 (0)