Skip to content

Commit 8e679e8

Browse files
author
Kapil Borle
committed
Update and rename command data generator file
1 parent ab58624 commit 8e679e8

2 files changed

Lines changed: 59 additions & 48 deletions

File tree

Utils/New-CmdletDataFile.ps1

Lines changed: 0 additions & 48 deletions
This file was deleted.

Utils/New-CommandDataFile.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
$jsonVersion = "0.0.1"
2+
$builtinModulePath = Join-Path $pshome 'Modules'
3+
if (-not (Test-Path $builtinModulePath))
4+
{
5+
throw new "$builtinModulePath does not exist! Cannot create command data file."
6+
}
7+
8+
Function IsPSEditionDesktop
9+
{
10+
$PSEdition -eq $null -or $PSEdition -eq 'Desktop'
11+
}
12+
13+
Function Get-CmdletDataFileName
14+
{
15+
$edition = 'core'
16+
$os = 'windows'
17+
if ((IsPSEditionDesktop))
18+
{
19+
$edition = 'desktop'
20+
}
21+
else
22+
{
23+
if ($IsLinux)
24+
{
25+
$os = 'linux'
26+
}
27+
elseif ($IsOSX)
28+
{
29+
$os = 'osx'
30+
}
31+
# else it is windows, which is already set
32+
}
33+
$sb = New-Object 'System.Text.StringBuilder'
34+
$sb.Append($edition) | Out-Null
35+
$sb.Append('-') | Out-Null
36+
$sb.Append($PSVersionTable.PSVersion.ToString()) | Out-Null
37+
$sb.Append('-') | Out-Null
38+
$sb.Append($os) | Out-Null
39+
$sb.Append('.json') | Out-Null
40+
$sb.ToString()
41+
}
42+
43+
$jsonData = @{}
44+
$jsonData['SchemaVersion'] = $jsonVersion
45+
$shortModuleInfos = Get-ChildItem -Path $builtinModulePath `
46+
| Where-Object {($_ -is [System.IO.DirectoryInfo]) -and (Get-Module $_.Name -ListAvailable)} `
47+
| ForEach-Object {
48+
$modules = Get-Module $_.Name -ListAvailable
49+
$modules | ForEach-Object {
50+
$module = $_
51+
Write-Progress $module.Name
52+
$commands = Get-Command -Module $module
53+
$shortCommands = $commands | select -Property Name,@{Label='CommandType';Expression={$_.CommandType.ToString()}},ParameterSets
54+
$shortModuleInfo = $module | select -Property Name,@{Label='Version';Expression={$_.Version.ToString()}}
55+
Add-Member -InputObject $shortModuleInfo -NotePropertyName 'ExportedCommands' -NotePropertyValue $shortCommands -PassThru
56+
}
57+
}
58+
$jsonData['Modules'] = $shortModuleInfos
59+
$jsonData | ConvertTo-Json -Depth 4 | Out-File ((Get-CmdletDataFileName))

0 commit comments

Comments
 (0)