Skip to content
Merged
Show file tree
Hide file tree
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: 12 additions & 12 deletions New-Sample.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<your script>"

$psScriptBlock = @"
```````powershell
$psScriptBlock = @'
```powershell

<your script>

```````
"@
```
'@

$bashScriptBlock = @"
```````bash
$bashScriptBlock = @'
```bash

<your script>

```````
"@
```
'@

# Todo: Example on all the tool tab types
$tabBlocks = @{
Expand Down Expand Up @@ -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."
Expand Down
8 changes: 8 additions & 0 deletions site/tests/generator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<your script>').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.' }
Expand All @@ -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+<your script>\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+<your script>\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
Expand Down
Loading