diff --git a/Commands/Save-MarkdownHelp.ps1 b/Commands/Save-MarkdownHelp.ps1 index a7c9f581..a81a64b4 100644 --- a/Commands/Save-MarkdownHelp.ps1 +++ b/Commands/Save-MarkdownHelp.ps1 @@ -162,7 +162,17 @@ # If the value is a [string], it will be expanded # In either context, `$_` will be the current attribute. [PSObject] - $FormatAttribute + $FormatAttribute, + + # The path where json data should be located. + # If this is not provided, it will be assumed to be a subdirectory of the -OutputPath. + # Specifically, it will be assumed to be: `$OutputPath/_data/Help` + [string] + $JsonDataPath, + + # If set, will not output json data files. + [switch] + $NoJson ) begin { @@ -252,6 +262,12 @@ $null = New-Item -ItemType Directory -Path $OutputPath # create it. } + if (-not $PSBoundParameters.JsonDataPath) { + $JsonDataPath = Join-Path $OutputPath '_data' | Join-Path -ChildPath 'Help' + } else { + $JsonDataPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($JsonDataPath) + } + if ((-not $ExcludeSubModule) -and (-not $IncludeSubmodule)) { Push-Location $theModuleRoot @@ -291,6 +307,9 @@ # Determine the output path for each item. $docOutputPath = Join-Path $outputPath ($cmd.Name + '.md') + if ($JsonDataPath) { + $jsonOutputPath = Join-Path $JsonDataPath ($cmd.Name + '.json') + } # Prepare a splat for this command by copying out base splat. $getMarkdownHelpSplat = @{Name="$cmd"} + $getMarkdownHelpSplatBase @@ -298,8 +317,9 @@ if ($Wiki) { $getMarkdownHelpSplat.Wiki = $Wiki } # otherwise, pass down the parent of $OutputPath. else { $getMarkdownHelpSplat.GitHubDocRoot = "$($outputPath|Split-Path -Leaf)"} - - $markdownTopic = Get-MarkdownHelp @getMarkdownHelpSplat + + $markdownTopic = Get-MarkdownHelp @getMarkdownHelpSplat + $markdownFile = if ($markdownTopic.Save) { $markdownTopic.Save($docOutputPath) @@ -312,6 +332,20 @@ $markdownFile } } + if ($JsonDataPath -and -not $NoJson) { + $jsonFile = + if ($markdownTopic.SaveJson) { + $markdownTopic.SaveJson($jsonOutputPath) + } else { $null } + + if ($jsonFile) { + $filesChanged += $jsonFile + + if ($PassThru) { # If -PassThru was provided, get the path. + $jsonFile + } + } + } } if ($Command) {