-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new function to get package id from publisher, name and id --------- Co-authored-by: freddydk <freddydk@users.noreply.github.com> Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
- Loading branch information
1 parent
40f7c4a
commit 8a8f866
Showing
7 changed files
with
71 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<# | ||
.Synopsis | ||
PROOF OF CONCEPT PREVIEW: Get Business Central NuGet Package Id from Publisher, Name and Id | ||
.Description | ||
Get Business Central NuGet Package Id from Publisher, Name and Id | ||
.OUTPUTS | ||
string | ||
Package Id | ||
.PARAMETER packageIdTemplate | ||
Template for package id with placeholders for publisher, name, id and version | ||
.PARAMETER publisher | ||
App Publisher (will be normalized) | ||
.PARAMETER name | ||
App name (will be normalized) | ||
.PARAMETER id | ||
App Id (must be a GUID if present) | ||
.PARAMETER tag | ||
Tag to add to the package id | ||
.PARAMETER version | ||
App Version | ||
.EXAMPLE | ||
Get-BcNuGetPackageId -publisher 'Freddy Kristiansen' -name 'Bing Maps PTE' -id '165d73c1-39a4-4fb6-85a5-925edc1684fb' | ||
#> | ||
function Get-BcNuGetPackageId { | ||
Param( | ||
[Parameter(Mandatory=$false)] | ||
[string] $packageIdTemplate = '{publisher}.{name}.{tag}.{id}', | ||
[Parameter(Mandatory=$true)] | ||
[string] $publisher, | ||
[Parameter(Mandatory=$true)] | ||
[string] $name, | ||
[Parameter(Mandatory=$false)] | ||
[string] $id = '', | ||
[Parameter(Mandatory=$false)] | ||
[string] $tag = '', | ||
[Parameter(Mandatory=$false)] | ||
[string] $version = '' | ||
) | ||
|
||
if ($id) { | ||
try { $id = ([GUID]::Parse($id)).Guid } catch { throw "App id must be a valid GUID: $id" } | ||
} | ||
$nname = [nuGetFeed]::Normalize($name) | ||
$npublisher = [nuGetFeed]::Normalize($publisher) | ||
if ($nname -eq '') { throw "App name is invalid: '$name'" } | ||
if ($npublisher -eq '') { throw "App publisher is invalid: '$publisher'" } | ||
|
||
$packageIdTemplate = $packageIdTemplate.replace('{id}',$id).replace('{publisher}',$npublisher).replace('{tag}',$tag).replace('{version}',$version).replace('..','.').TrimEnd('.') | ||
# Max. Length of NuGet Package Id is 100 - we shorten the name part of the id if it is too long | ||
$packageId = $packageIdTemplate.replace('{name}',$nname) | ||
if ($packageId.Length -ge 100) { | ||
if ($nname.Length -gt ($packageId.Length - 99)) { | ||
$nname = $nname.Substring(0, $nname.Length - ($packageId.Length - 99)) | ||
} | ||
else { | ||
throw "Package id is too long: $packageId, unable to shorten it" | ||
} | ||
$packageId = $packageIdTemplate.replace('{name}',$nname) | ||
} | ||
return $packageId | ||
} | ||
Export-ModuleMember -Function Get-BcNuGetPackageId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters