Skip to content

Commit

Permalink
feat: Save-MarkdownHelp -JsonDataPath / -NoJson ( Fixes #208, Fixes #179
Browse files Browse the repository at this point in the history
 )

Co-authored-by: Chrissy LeMaire <8278033+potatoqualitee@users.noreply.github.com>
  • Loading branch information
James Brundage and potatoqualitee committed Oct 13, 2024
1 parent 493ebd3 commit 53c84db
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions Commands/Save-MarkdownHelp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -291,15 +307,19 @@

# 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

# If -Wiki was passed, call Get-MarkDownHelp with -Wiki (this impacts link format)
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)
Expand All @@ -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) {
Expand Down

0 comments on commit 53c84db

Please sign in to comment.