Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions utilities/tools/Set-ModuleReadMe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function Set-ParametersSection {
# 2. Create header including optional columns
$newSectionContent += @(
('**{0} parameters**' -f $category),
(''),
'',
('| Parameter Name | Type | {0}{1}Description |' -f ($hasDefault ? 'Default Value | ' : ''), ($hasAllowed ? 'Allowed Values | ' : '')),
('| :-- | :-- | {0}{1}:-- |' -f ($hasDefault ? ':-- | ' : ''), ($hasAllowed ? ':-- | ' : ''))
)
Expand Down Expand Up @@ -650,6 +650,11 @@ function ConvertTo-FormattedJSONParameterObject {
[string] $BicepParamBlock
)

if ([String]::IsNullOrEmpty($BicepParamBlock)) {
# Case: No mandatory parameters
return @{}
}

# [1/4] Detect top level params for later processing
$bicepParamBlockArray = $BicepParamBlock -split '\n'
$topLevelParamIndent = ([regex]::Match($bicepParamBlockArray[0], '^(\s+).*')).Captures.Groups[1].Value.Length
Expand Down Expand Up @@ -966,8 +971,14 @@ function Set-DeploymentExamplesSection {
$rawBicepExampleArray = $rawBicepExample -split '\n'
$moduleDeploymentPropertyIndent = ([regex]::Match($rawBicepExampleArray[1], '^(\s+).*')).Captures.Groups[1].Value.Length
$paramsStartIndex = ($rawBicepExampleArray | Select-String ("^[\s]{$moduleDeploymentPropertyIndent}params:[\s]*\{") | ForEach-Object { $_.LineNumber - 1 })[0] + 1
$paramsEndIndex = ($rawBicepExampleArray[($paramsStartIndex + 1)..($rawBicepExampleArray.Count)] | Select-String "^[\s]{$moduleDeploymentPropertyIndent}\}" | ForEach-Object { $_.LineNumber - 1 })[0] + $paramsStartIndex
$paramBlock = ($rawBicepExampleArray[$paramsStartIndex..$paramsEndIndex] | Out-String).TrimEnd()
if ($rawBicepExampleArray[$paramsStartIndex].Trim() -ne '}') {
# Handle case where param block is empty
$paramsEndIndex = ($rawBicepExampleArray[($paramsStartIndex + 1)..($rawBicepExampleArray.Count)] | Select-String "^[\s]{$moduleDeploymentPropertyIndent}\}" | ForEach-Object { $_.LineNumber - 1 })[0] + $paramsStartIndex
$paramBlock = ($rawBicepExampleArray[$paramsStartIndex..$paramsEndIndex] | Out-String).TrimEnd()
} else {
$paramBlock = ''
$paramsEndIndex = $paramsStartIndex
}

# [5/6] Convert Bicep parameter block to JSON parameter block to enable processing
$conversionInputObject = @{
Expand All @@ -987,7 +998,12 @@ function Set-DeploymentExamplesSection {
# --------------------- #
if ($addBicep) {

$formattedBicepExample = $rawBicepExample[0..($paramsStartIndex - 1)] + ($bicepExample -split '\n') + $rawBicepExample[($paramsEndIndex + 1)..($rawBicepExample.Count)]
if ([String]::IsNullOrEmpty($paramBlock)) {
# Handle case where param block is empty
$formattedBicepExample = $rawBicepExample[0..($paramsStartIndex - 1)] + $rawBicepExample[($paramsEndIndex)..($rawBicepExample.Count)]
} else {
$formattedBicepExample = $rawBicepExample[0..($paramsStartIndex - 1)] + ($bicepExample -split '\n') + $rawBicepExample[($paramsEndIndex + 1)..($rawBicepExample.Count)]
}

$SectionContent += @(
'',
Expand Down