diff --git a/New-Sample.ps1 b/New-Sample.ps1 index e7cc47ba0..3ae9bd710 100644 --- a/New-Sample.ps1 +++ b/New-Sample.ps1 @@ -96,26 +96,26 @@ begin{ $readmeSourceCreditText = "Sample first appeared on [https://pnp.github.io/cli-microsoft365/sample-scripts/spo/add-app-catalog/](https://pnp.github.io/cli-microsoft365/sample-scripts/spo/add-app-catalog/)" $scriptBlockEnding = "***" - $psScriptPlaceholderReplaceHeader = "`powershell" - $psScriptBashPlaceholderReplaceHeader = "``````bash" - $psScriptPlaceholderReplaceFooter = "``" + $psScriptPlaceholderReplaceHeader = '```powershell' + $psScriptBashPlaceholderReplaceHeader = '```bash' + $psScriptPlaceholderReplaceFooter = '```' $psScriptPlaceholderReplaceBody = "" - $psScriptBlock = @" -```````powershell + $psScriptBlock = @' +```powershell -``````` -"@ +``` +'@ - $bashScriptBlock = @" -```````bash + $bashScriptBlock = @' +```bash -``````` -"@ +``` +'@ # Todo: Example on all the tool tab types $tabBlocks = @{ @@ -160,7 +160,7 @@ begin{ "CliForMicrosoft365Bash" = [PSCustomObject]@{ Tab = "# [CLI for Microsoft 365 using Bash](#tab/cli-m365-bash)" IncludeBlock = "[!INCLUDE [More about CLI for Microsoft 365](../../docs/includes/MORE-CLIM365.md)]" - ScriptBlock = $psScriptBlock + ScriptBlock = $bashScriptBlock Reference = [PSCustomObject]@{ "name" = "Want to learn more about CLI for Microsoft 365 and the commands" "description" = "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands." diff --git a/site/tests/generator.ps1 b/site/tests/generator.ps1 index dee9aabfb..3e75e1a63 100644 --- a/site/tests/generator.ps1 +++ b/site/tests/generator.ps1 @@ -20,6 +20,10 @@ try { $readme = Get-Content -LiteralPath $readmePath -Raw $metadata = @(Get-Content -LiteralPath (Join-Path $sample 'assets\sample.json') -Raw | ConvertFrom-Json)[0] if ([regex]::Matches($readme, '(?m)^# \[.+\]\(#tab/').Count -ne 8) { throw 'All must generate eight code tabs.' } + if ([regex]::Matches($readme, '(?m)^```powershell\s*$').Count -ne 7) { throw 'All must generate seven PowerShell code blocks.' } + if ([regex]::Matches($readme, '(?m)^```bash\s*$').Count -ne 1) { throw 'All must generate one Bash code block.' } + if ([regex]::Matches($readme, '(?m)^```\s*$').Count -ne 8) { throw 'Each generated code block must have a closing fence.' } + if ([regex]::Matches($readme, '').Count -ne 8) { throw 'Each generated code block must have a script placeholder.' } if (@($metadata.metadata).Count -ne 7) { throw 'All must generate seven unique tool keys, with CLI shared by PowerShell and Bash.' } if ($readme -match '\.\./\.\./docfx/') { throw 'Generator must use the migrated shared include paths.' } if ($readme.TrimEnd().Split("`n")[-1] -notmatch 'script-samples/scripts/spo-generator-check') { throw 'Incorrect final view tracker.' } @@ -32,7 +36,11 @@ try { $arguments.ScriptTool = @('CliForMicrosoft365', 'CliForMicrosoft365Bash') & $generator @arguments $cli = @(Get-Content -LiteralPath (Join-Path $fixture 'scripts\spo-cli-check\assets\sample.json') -Raw | ConvertFrom-Json)[0] + $cliReadme = Get-Content -LiteralPath (Join-Path $fixture 'scripts\spo-cli-check\README.md') -Raw if (@($cli.metadata).Count -ne 1) { throw 'CLI variants must not duplicate metadata keys.' } + if ([regex]::Matches($cliReadme, '(?m)^# \[.+\]\(#tab/').Count -ne 2) { throw 'CLI selection must generate only the two selected tabs.' } + if ($cliReadme -notmatch '(?s)# \[CLI for Microsoft 365 using PowerShell\]\(#tab/cli-m365-ps\)\s+```powershell\s+\s+```') { throw 'CLI PowerShell tab must contain a PowerShell code block.' } + if ($cliReadme -notmatch '(?s)# \[CLI for Microsoft 365 using Bash\]\(#tab/cli-m365-bash\)\s+```bash\s+\s+```') { throw 'CLI Bash tab must contain a Bash code block.' } Write-Host 'Generator checks passed: all tools, unique metadata, migrated includes, tracker, and overwrite protection.' } finally { Get-ChildItem -LiteralPath $fixture -Recurse -File | Remove-Item -Force