ps/Modules/Alkami.PowerShell.Choco/Private/IsPackageWidget.ps1
2023-05-30 22:51:22 -07:00

49 lines
1.3 KiB
PowerShell

function IsPackageWidget {
<#
.SYNOPSIS
Returns true if a given package name is a widget.
#>
[CmdletBinding()]
[OutputType([System.Boolean])]
Param(
[Parameter(Mandatory = $true)]
[string]$packageName
)
# Match known Widget naming conventions.
$widgetNames = @("Alkami.Apps*", "Alkami.Client*", "Alkami.Modules*", "Alkami.WebExtensions*");
foreach ($name in $widgetNames) {
if ($packageName -match $name) {
return $true;
}
}
# Onto fallback methods if naive name matching doesn't work.
# Parse tags from the verbose output of a choco search.
Write-Host "Pulling tags for package '$packageName'";
$verboseOutput = (choco search -l -verbose -e $packageName);
$tagLine = $verboseOutput | Where-Object { ($_.Trim().StartsWith("Tags:")) };
if (!($tagLine)) {
return $false;
}
$tagLine = $tagLine.Substring($tagLine.IndexOf(":") + 1);
$option = [System.StringSplitOptions]::RemoveEmptyEntries;
$tags = $tagLine.Split(' ', $option);
if ($tags.count -eq 0) {
return $false;
}
foreach ($tag in $tags) {
if ($tag.ToLower() -match "widget") {
return $true;
}
}
# No widget tag found.
return $false;
}