1- #
21# UpdateNativeApiDocs.ps1 is a PowerShell script designed to download the
32# API docs from the specified RNW CI build in ADO and integrate them into
43# our docs folder, properly tagged with New/Old architecture tags
@@ -48,7 +47,7 @@ Function Create-WinRtApiDocWithBadge([string]$SourceDocPath, [string]$DestDocPat
4847 $Content = $Content.Trim ()
4948
5049 # Write final file
51- $Content | Out-File - Encoding utf8NoBOM $DestDocPath
50+ $Content | Out-File - Encoding utf8 $DestDocPath
5251}
5352
5453Function Get-DocKind ([string ]$DocPath ) {
@@ -130,7 +129,7 @@ Function Merge-WinRtApiDocs([string]$OldArchDocsPath, [string]$NewArchDocsPath,
130129 $OldContent = $OldContent -replace " ---(.*\r\n){1,}---\r\n\r\n" , " `r`n`r`n # Old Architecture`r`n`r`n "
131130 $OldContent = $OldContent -replace " \r\n#" , " `r`n ##"
132131
133- ($NewContent + $OldContent ) | Out-File - Encoding utf8NoBOM - NoNewline $MergedFilePath
132+ ($NewContent + $OldContent ) | Out-File - Encoding utf8 - NoNewline $MergedFilePath
134133 Create- WinRtApiDocWithBadge - SourceDocPath $MergedFilePath - DestDocPath (Join-Path $OutputDocsPath $_ ) - BadgeMd $NewAndOldArchBadgeMd
135134 }
136135 $Kind = Get-DocKind - DocPath (Join-Path $OutputDocsPath $_ )
@@ -140,12 +139,16 @@ Function Merge-WinRtApiDocs([string]$OldArchDocsPath, [string]$NewArchDocsPath,
140139
141140 # Clean up links to enum type values (workaround for https://github.com/asklar/winmd2md/issues/10)
142141 (Get-ChildItem - Path $OutputDocsPath - File - Filter *- api- windows.md) | ForEach-Object {
143- $FilePath = $_
144- $FileContent = (Get-Content $FilePath - Raw)
145- $AllTypesByKind [' enum' ] | ForEach-Object {
146- $FileContent = $FileContent -replace " \($_ #\w+\)" , " ($_ )"
142+ $FilePath = $_.FullName
143+ if (Test-Path $FilePath ) {
144+ $FileContent = Get-Content $FilePath - Raw
145+ if ($AllTypesByKind.ContainsKey (' enum' )) {
146+ $AllTypesByKind [' enum' ] | ForEach-Object {
147+ $FileContent = $FileContent -replace " \($_ #\w+\)" , " ($_ )"
148+ }
149+ }
150+ $FileContent | Out-File - Encoding utf8 $FilePath
147151 }
148- $FileContent | Out-File - Encoding utf8NoBOM - NoNewLine $FilePath
149152 }
150153
151154 # Recreate index (workaround for https://github.com/asklar/winmd2md/issues/10)
@@ -159,7 +162,9 @@ Function Merge-WinRtApiDocs([string]$OldArchDocsPath, [string]$NewArchDocsPath,
159162 $IndexContent += " `r`n "
160163
161164 $AllTypesByKind.Keys | Where-Object { $_ -ne ' unknown' } | Sort-Object | ForEach-Object {
162- $IndexContent += " ## $ ( $_.Substring (0 , 1 ).ToUpper()) $ ( $_.Substring (1 )) $ ( $_.EndsWith (" s" ) ? " es" : " s" ) `r`n "
165+ $KindLabel = " $ ( $_.Substring (0 , 1 ).ToUpper()) $ ( $_.Substring (1 )) "
166+ if ($_.EndsWith (" s" )) { $KindLabel += " es" } else { $KindLabel += " s" }
167+ $IndexContent += " ## $KindLabel `r`n "
163168 $AllTypesByKind [$_ ] | Sort-Object | ForEach-Object {
164169 $IndexContent += " - [$_ ]($_ )`r`n "
165170 }
@@ -171,7 +176,7 @@ Function Merge-WinRtApiDocs([string]$OldArchDocsPath, [string]$NewArchDocsPath,
171176 $IndexPath = (Join-Path $OutputDocsPath " index-api-windows.md" )
172177
173178 Write-Host " Creating `" $IndexPath `" "
174- $IndexContent | Out-File - Encoding utf8NoBOM $IndexPath
179+ $IndexContent | Out-File - Encoding utf8 $IndexPath
175180
176181 # Update sidebar
177182 $SidebarsFile = Join-Path $RepoRoot " website/sidebars.json"
@@ -181,9 +186,11 @@ Function Merge-WinRtApiDocs([string]$OldArchDocsPath, [string]$NewArchDocsPath,
181186 $NativeApiEntries += " native-api/Native-API-Reference"
182187
183188 $AllTypesByKind.Keys | Where-Object { $_ -ne ' unknown' } | Sort-Object | ForEach-Object {
189+ $KindLabel = " $ ( $_.Substring (0 , 1 ).ToUpper()) $ ( $_.Substring (1 )) "
190+ if ($_.EndsWith (" s" )) { $KindLabel += " es" } else { $KindLabel += " s" }
184191 $KindObject = @ {}
185192 $KindObject [' type' ] = ' subcategory'
186- $KindObject [' label' ] = " $ ( $_ .Substring ( 0 , 1 ).ToUpper() ) $ ( $_ .Substring ( 1 ) ) $ ( $_ .EndsWith ( " s " ) ? " es " : " s " ) "
193+ $KindObject [' label' ] = $KindLabel
187194 $KindObject [' ids' ] = @ ()
188195 $AllTypesByKind [$_ ] | Sort-Object | ForEach-Object {
189196 $KindObject [' ids' ] += " native-api/$_ "
@@ -228,4 +235,4 @@ finally
228235 Set-Location - Path $StartingLocation
229236}
230237
231- exit 0
238+ exit 0
0 commit comments