@@ -45,6 +45,60 @@ function Test-PlaceholderContent {
4545 }
4646}
4747
48+ function Write-CommandMetadata {
49+ param (
50+ [Parameter (Mandatory )]
51+ [string ]$ModuleManifestPath ,
52+ [Parameter (Mandatory )]
53+ [string ]$OutputPath
54+ )
55+
56+ if (-not (Test-Path - LiteralPath $ModuleManifestPath - PathType Leaf)) {
57+ return
58+ }
59+
60+ $resolvedManifestPath = [System.IO.Path ]::GetFullPath($ModuleManifestPath )
61+ Remove-Module - Name $moduleName - Force - ErrorAction SilentlyContinue
62+ try {
63+ Import-Module $resolvedManifestPath - Force - ErrorAction Stop | Out-Null
64+ $allCommands = @ (Get-Command - Module $moduleName - ErrorAction Stop)
65+ $aliasesByTarget = @ {}
66+
67+ foreach ($aliasCommand in $allCommands | Where-Object CommandType -EQ ' Alias' ) {
68+ $targetName = $aliasCommand.ResolvedCommandName
69+ if ([string ]::IsNullOrWhiteSpace($targetName )) {
70+ continue
71+ }
72+
73+ if (-not $aliasesByTarget.ContainsKey ($targetName )) {
74+ $aliasesByTarget [$targetName ] = [System.Collections.Generic.List [string ]]::new()
75+ }
76+
77+ if (-not $aliasesByTarget [$targetName ].Contains($aliasCommand.Name )) {
78+ $null = $aliasesByTarget [$targetName ].Add($aliasCommand.Name )
79+ }
80+ }
81+
82+ $commandMetadata = foreach ($command in $allCommands | Where-Object CommandType -In @ (' Function' , ' Cmdlet' , ' Filter' , ' ExternalScript' ) | Sort-Object Name) {
83+ [ordered ]@ {
84+ name = $command.Name
85+ kind = if ($command.CommandType -EQ ' Cmdlet' ) { ' Cmdlet' } else { ' Function' }
86+ aliases = @ ($aliasesByTarget [$command.Name ] | Sort-Object - Unique)
87+ }
88+ }
89+
90+ $payload = [ordered ]@ {
91+ moduleName = $moduleName
92+ generatedAt = (Get-Date ).ToString(' o' )
93+ commands = @ ($commandMetadata )
94+ }
95+
96+ $payload | ConvertTo-Json - Depth 6 | Set-Content - LiteralPath $OutputPath - Encoding UTF8
97+ } finally {
98+ Remove-Module - Name $moduleName - Force - ErrorAction SilentlyContinue
99+ }
100+ }
101+
48102$helpPath = Find-HelpFile
49103if (-not $helpPath -and -not $SkipBuild ) {
50104 $previousRefresh = $env: RefreshPSD1Only
@@ -78,11 +132,16 @@ if (Test-Path -LiteralPath $apiRoot) {
78132New-Item - ItemType Directory - Path $apiRoot - Force | Out-Null
79133Copy-Item - LiteralPath $helpPath - Destination (Join-Path $apiRoot " $moduleName -help.xml" ) - Force
80134
135+ $psd1Path = Join-Path $repoRoot " $moduleName .psd1"
136+ if (Test-Path - LiteralPath $psd1Path - PathType Leaf) {
137+ Copy-Item - LiteralPath $psd1Path - Destination (Join-Path $apiRoot " $moduleName .psd1" ) - Force
138+ Write-CommandMetadata - ModuleManifestPath $psd1Path - OutputPath (Join-Path $apiRoot ' command-metadata.json' )
139+ }
140+
81141if (Test-Path - LiteralPath $examplesSource - PathType Container) {
82142 Copy-Item - LiteralPath $examplesSource - Destination $examplesTarget - Recurse - Force
83143}
84144
85- $psd1Path = Join-Path $repoRoot " $moduleName .psd1"
86145$version = $null
87146if (Test-Path - LiteralPath $psd1Path - PathType Leaf) {
88147 $version = (Import-PowerShellDataFile - Path $psd1Path ).ModuleVersion.ToString()
0 commit comments