| 1 |
#Requires -Version 5.1 |
| 2 |
|
| 3 |
<# |
| 4 |
.SYNOPSIS |
| 5 |
Generates Markdown documentation for Shoutrrr services. |
| 6 |
|
| 7 |
.DESCRIPTION |
| 8 |
This script generates Markdown documentation for Shoutrrr services using the shoutrrr CLI. |
| 9 |
It supports generating documentation for all services or a specific service. |
| 10 |
Skips 'standard' and 'xmpp' services as they are not applicable. |
| 11 |
|
| 12 |
.PARAMETER ServiceName |
| 13 |
Optional. The name of a specific service to generate documentation for. |
| 14 |
If not provided, generates documentation for all services. |
| 15 |
|
| 16 |
.EXAMPLE |
| 17 |
.\generate-service-config-docs.ps1 |
| 18 |
|
| 19 |
Generates documentation for all services. |
| 20 |
|
| 21 |
.EXAMPLE |
| 22 |
.\generate-service-config-docs.ps1 -ServiceName discord |
| 23 |
|
| 24 |
Generates documentation for the discord service only. |
| 25 |
#> |
| 26 |
|
| 27 |
param( |
| 28 |
[string]$ServiceName |
| 29 |
) |
| 30 |
|
| 31 |
# Enable strict error handling |
| 32 |
$ErrorActionPreference = "Stop" |
| 33 |
|
| 34 |
# Get script and repository paths |
| 35 |
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 36 |
$repoRoot = Split-Path -Parent $scriptDir |
| 37 |
$servicesPath = Join-Path $repoRoot "pkg\services" |
| 38 |
|
| 39 |
# Function to generate documentation for a service |
| 40 |
function Generate-Docs { |
| 41 |
param( |
| 42 |
[string]$Service, |
| 43 |
[string]$Category |
| 44 |
) |
| 45 |
|
| 46 |
$docsPath = Join-Path $repoRoot "docs\services\$Category\$Service" |
| 47 |
|
| 48 |
Write-Host "Creating docs for $Category/$Service... " -ForegroundColor Cyan -NoNewline |
| 49 |
|
| 50 |
# Create directory if it doesn't exist |
| 51 |
New-Item -ItemType Directory -Path $docsPath -Force | Out-Null |
| 52 |
|
| 53 |
# Run shoutrrr docs command |
| 54 |
$shoutrrrPath = Join-Path $repoRoot "shoutrrr" |
| 55 |
$outputFile = Join-Path $docsPath "config.md" |
| 56 |
|
| 57 |
$process = Start-Process -FilePath "go" -ArgumentList "run", "`"$shoutrrrPath`"", "docs", "-f", "markdown", $Service -RedirectStandardOutput $outputFile -NoNewWindow -Wait -PassThru |
| 58 |
|
| 59 |
if ($process.ExitCode -eq 0) { |
| 60 |
Write-Host "Done!" -ForegroundColor Green |
| 61 |
} else { |
| 62 |
Write-Host "Failed!" -ForegroundColor Red |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
# Check if a specific service was requested |
| 67 |
if ($ServiceName) { |
| 68 |
# Find the service directory |
| 69 |
$serviceDir = Get-ChildItem -Path $servicesPath -Recurse -Directory | Where-Object { $_.Name -eq $ServiceName } | Select-Object -First 1 |
| 70 |
|
| 71 |
if (-not $serviceDir) { |
| 72 |
Write-Host "Service $ServiceName not found" -ForegroundColor Red |
| 73 |
exit 1 |
| 74 |
} |
| 75 |
|
| 76 |
$category = Split-Path -Parent $serviceDir.FullName | Split-Path -Leaf |
| 77 |
Generate-Docs -Service $ServiceName -Category $category |
| 78 |
exit 0 |
| 79 |
} |
| 80 |
|
| 81 |
# Debug: Print the services path |
| 82 |
Write-Host "Debug: Checking services path: $servicesPath" |
| 83 |
|
| 84 |
# Check if services directory exists and has subdirectories |
| 85 |
if (-not (Test-Path $servicesPath)) { |
| 86 |
Write-Host "Services path $servicesPath does not exist" -ForegroundColor Red |
| 87 |
exit 1 |
| 88 |
} |
| 89 |
|
| 90 |
$categoryDirs = Get-ChildItem -Path $servicesPath -Directory |
| 91 |
if ($categoryDirs.Count -eq 0) { |
| 92 |
Write-Host "No service directories found in $servicesPath" -ForegroundColor Red |
| 93 |
Write-Host "Debug: Contents of ${servicesPath}:" |
| 94 |
Get-ChildItem -Path $servicesPath | Format-Table -AutoSize |
| 95 |
exit 1 |
| 96 |
} |
| 97 |
|
| 98 |
# Process all services |
| 99 |
foreach ($categoryDir in $categoryDirs) { |
| 100 |
$category = $categoryDir.Name |
| 101 |
|
| 102 |
$serviceDirs = Get-ChildItem -Path $categoryDir.FullName -Directory |
| 103 |
|
| 104 |
foreach ($serviceDir in $serviceDirs) { |
| 105 |
$service = $serviceDir.Name |
| 106 |
|
| 107 |
# Skip specific services |
| 108 |
if ($service -eq "standard" -or $service -eq "xmpp") { |
| 109 |
continue |
| 110 |
} |
| 111 |
|
| 112 |
# Debug: Print the service being processed |
| 113 |
Write-Host "Debug: Processing service: $category/$service" |
| 114 |
|
| 115 |
Generate-Docs -Service $service -Category $category |
| 116 |
} |
| 117 |
} |