Skip to content

Commit 65cf080

Browse files
committed
Reviewed script
1 parent 10644ef commit 65cf080

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

tools/ExamplesGenerator.ps1

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ function Update-ExampleFile {
304304
$HeadCount = $HeaderList.Count
305305
$ExampleCount = $ExampleList.Count
306306
$WrongExamplesCount = 0;
307+
$SkippedExample = -1
308+
$ContainsRightExamples = $False
307309
#===========================Importing new examples into files ============================================#
308310
if ($ReplaceEverything -and $ExampleCount -gt 0 -and $HeadCount -eq $ExampleCount) {
309311
Clear-Content $ExampleFile -Force
@@ -315,12 +317,16 @@ function Update-ExampleFile {
315317

316318
$TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n"
317319
Add-Content -Path $ExampleFile -Value $TotalText
320+
$ContainsRightExamples = $True
318321
}else{
319322
$WrongExamplesCount++
323+
$SkippedExample++
320324

321325
}
322326
}
323327
}
328+
#The code below updates existing examples
329+
#------------------------------------------------------------#
324330
$PatternToSearch = "Import-Module Microsoft.Graph.$Module"
325331
if(($Content | Select-String -pattern $SearchText) -and ($Content | Select-String -pattern "This example shows")){
326332
$ContainsPatternToSearch = $False
@@ -331,14 +337,17 @@ function Update-ExampleFile {
331337
}
332338
if($ContainsPatternToSearch){
333339
Clear-Content $ExampleFile -Force
334-
#Replace everything
335340
for ($d = 0; $d -lt $HeaderList.Count; $d++) {
341+
if($ExampleList[$d].Contains($Command)){
336342
$CodeValue = $ExampleList[$d].Trim()
337343
$TitleValue = "### " + $HeaderList[$d].Trim()
338344
$Code = "``````powershell`r$CodeValue`r`n``````"
339345

340346
$TotalText = "$TitleValue`r`n`n$Code`r`n$Description`r`n"
341347
Add-Content -Path $ExampleFile -Value $TotalText
348+
}else{
349+
$SkippedExample++
350+
}
342351
}
343352

344353
}else{
@@ -349,7 +358,36 @@ function Update-ExampleFile {
349358
}
350359

351360
}
352-
if($WrongExamplesCount -gt 0){
361+
#The code below corrects the numbering of the example headers/title if there is a situation where
362+
#some examples are wrong(which are left out) and some are right
363+
#-----------------------------------------------------------------------------------------------#
364+
$AvailableCorrectExamples = 1
365+
if($SkippedExample -gt -1){
366+
$NewContent = Get-Content -Path $ExampleFile
367+
foreach($C in $NewContent){
368+
if($C.Contains("Example")){
369+
$SearchString = $c.Split(":")
370+
$StringToReplace = $SearchString[0]
371+
$ReplacementString = "### Example $AvailableCorrectExamples"
372+
(Get-Content -Path $ExampleFile) -replace $StringToReplace, $ReplacementString | Set-Content $ExampleFile
373+
$AvailableCorrectExamples++
374+
}
375+
}
376+
if(-not(Test-Path -PathType Container $FolderForExamplesToBeReviewed)){
377+
New-Item -ItemType Directory -Force -Path $FolderForExamplesToBeReviewed
378+
}
379+
if (-not (Test-Path "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed")) {
380+
"Command, ExternalDocsUrl, ApiVersion" | Out-File -FilePath "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed" -Encoding ASCII
381+
}
382+
383+
$File = Get-Content "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed"
384+
$containsWord = $File | % { $_ -match "$Command, $ExternalDocUrl, $GraphProfile, $UriPath" }
385+
if (-not($containsWord -contains $true)) {
386+
"$Command, $ExternalDocUrl, $GraphProfile, $UriPath" | Out-File -FilePath "$FolderForExamplesToBeReviewed\$ExamplesToBeReviewed" -Append -Encoding ASCII
387+
}
388+
}
389+
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------#
390+
if(($WrongExamplesCount -gt 0) -and -not($ContainsRightExamples)){
353391
$DefaultBoilerPlate = "### Example 1: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n### Example 2: {{ Add title here }}`r`n``````powershell`r`n PS C:\> {{ Add code here }}`r`n`n{{ Add output here }}`r`n```````n`n{{ Add description here }}`r`n`n"
354392
Add-Content -Path $ExampleFile -Value $DefaultBoilerPlate.Trim()
355393
#Log api path api version and equivalent external doc url giving wron examples

0 commit comments

Comments
 (0)