tools/Update-Manifest.ps1


$ROOT_FOLDER = Resolve-Path $PSScriptRoot\..

$functions = (Get-ChildItem $ROOT_FOLDER\script\*\public\*
| Select-Object -ExpandProperty BaseName
| % {
    "$(" " * 4)`"$_`""
}) -join ",`n"


$cmdlets = Select-String $ROOT_FOLDER\module\src\*Cmdlet.cs `
    -Pattern '\[Cmdlet\("(.*?)", "(.*?)"\)\]' -AllMatches `
| Select-Object -ExpandProperty Matches `
| % {
    $_ | Select-Object -ExpandProperty Groups `
    | Select-Object -Skip 1 -ExpandProperty Value `
    | Join-String -Separator '-'
} | % {
    "$(" " * 4)`"$_`""
} | Join-String -Separator ",`n"

$manifest = Get-Content $ROOT_FOLDER\cbsch-pslib.psd1 -Raw -Encoding utf8

$exportText = @"
# StartGenerated
FunctionsToExport = @(
$functions
)
 
CmdletsToExport = @(
$cmdlets
)
# EndGenerated
"@


[Regex]::Replace($manifest,
    # "FunctionsToExport = @\(.*?\)",
    "# StartGenerated.*# EndGenerated",
    "$exportText",
    [System.Text.RegularExpressions.RegexOptions]::Singleline)
| Set-Content -Path $ROOT_FOLDER\cbsch-pslib.psd1 -Encoding utf8 -NoNewline