From 610a74fa5fcff7289a10f0c3cbc216700e9daf7f Mon Sep 17 00:00:00 2001 From: Friedrich Weinmann Date: Tue, 31 Dec 2024 11:20:00 +0100 Subject: [PATCH] updates --- .../functions/Get/Publish-PSFModule.ps1 | 72 ++++++++++++++++--- .../functions/Get/Publish/Copy-Module.ps1 | 22 ++++++ .../Get/Publish/Publish-ModuleToPath.ps1 | 10 +++ .../Get/Publish/Publish-ModuleV2.ps1 | 10 +++ .../Get/Publish/Publish-ModuleV3.ps1 | 10 +++ .../Get/Publish/Update-ModuleInformation.ps1 | 10 +++ 6 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 create mode 100644 PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleToPath.ps1 create mode 100644 PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV2.ps1 create mode 100644 PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 create mode 100644 PSFramework.NuGet/internal/functions/Get/Publish/Update-ModuleInformation.ps1 diff --git a/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 b/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 index eaa541f..39808dd 100644 --- a/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 +++ b/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 @@ -1,5 +1,4 @@ -function Publish-PSFModule -{ +function Publish-PSFModule { [CmdletBinding(DefaultParameterSetName = 'ToRepository')] Param ( [Parameter(Mandatory = $true)] @@ -25,13 +24,14 @@ [string] $ApiKey, + [Parameter(ParameterSetName = 'ToRepository')] + [switch] + $SkipDependenciesCheck, + [Parameter(Mandatory = $true, ParameterSetName = 'ToPath')] [PsfDirectory] $DestinationPath, - [switch] - $SkipDependenciesCheck, - [string[]] $Tags, @@ -45,12 +45,64 @@ $ProjectUri ) - begin - { + begin { + #region Setup + $killIt = $ErrorActionPreference = 'Stop' + if ($Repository) { + # Resolve Repositories + Search-PSFPowerShellGet + $repositories = Resolve-Repository -Name $Repository -Type $Type -Cmdlet $PSCmdlet | Group-Object Name | ForEach-Object { + @($_.Group | Sort-Object Type -Descending)[0] + } + } + # Create Temp Directories + $workingDirectory = New-PSFTempDirectory -ModuleName PSFramework.NuGet -Name Publish.Work + $stagingDirectory = New-PSFTempDirectory -ModuleName PSFramework.NuGet -Name Publish.Staging + + $commonPublish = @{ + StagingDirectory = $stagingDirectory + Cmdlet = $PSCmdlet + Continue = $true + ContinueLabel = 'repo' + } + if ($ApiKey) { $commonPublish.ApiKey = $ApiKey } + if ($Credential) { $commonPublish.Credential = $Credential } + if ($SkipDependenciesCheck) { $commonPublish.SkipDependenciesCheck = $SkipDependenciesCheck } + #endregion Setup } - process - { - #TODO: Implement + process { + try { + foreach ($sourceModule in $Path) { + # Update Metadata per Parameter + $moduleData = Copy-Module -Path $sourceModule -Destination $workingDirectory -Cmdlet $PSCmdlet -Continue + Update-ModuleInformation -Module $moduleData -Tags $Tags -LicenseUri $LicenseUri -IconUri $IconUri -ProjectUri $ProjectUri -Cmdlet $PSCmdlet -Continue + + # Case 1: Publish to Destination Path + if ($DestinationPath) { + Publish-ModuleToPath -Module $moduleData -Path $DestinationPath -Cmdlet $PSCmdlet + continue + } + + # Case 2: Publish to Repository + :repo foreach ($repositoryObject in $repositories) { + switch ($repositoryObject.Type) { + V2 { + Publish-ModuleV2 @commonPublish -Module $moduleData -Repository $repositoryObject.Name + } + V3 { + Publish-ModuleV3 @commonPublish -Module $moduleData -Repository $repositoryObject.Name + } + default { + Stop-PSFFunction -String 'Publish-PSFModule.Error.UnexpectedRepositoryType' -StringValues $repositoryObject.Name, $repositoryObject.Type -Continue -Cmdlet $PSCmdlet -EnableException $killIt + } + } + } + } + } + finally { + # Cleanup Temp Directory + Remove-PSFTempItem -ModuleName PSFramework.NuGet -Name Publish.* + } } } <# diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 new file mode 100644 index 0000000..6920ace --- /dev/null +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 @@ -0,0 +1,22 @@ +function Copy-Module { + [CmdletBinding()] + param ( + [string] + $Path, + + [string] + $Destination, + + $Cmdlet, + + [switch] + $Continue, + + [string] + $ContinueLabel + ) + process { + #TODO: Implement + throw "Not Implemented Yet" + } +} \ No newline at end of file diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleToPath.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleToPath.ps1 new file mode 100644 index 0000000..c54866f --- /dev/null +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleToPath.ps1 @@ -0,0 +1,10 @@ +function Publish-ModuleToPath { + [CmdletBinding()] + param ( + + ) + process { + #TODO: Implement + throw "Not Implemented Yet" + } +} \ No newline at end of file diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV2.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV2.ps1 new file mode 100644 index 0000000..ec53a4e --- /dev/null +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV2.ps1 @@ -0,0 +1,10 @@ +function Publish-ModuleV2 { + [CmdletBinding()] + param ( + + ) + process { + #TODO: Implement + throw "Not Implemented Yet" + } +} \ No newline at end of file diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 new file mode 100644 index 0000000..bfee2ef --- /dev/null +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 @@ -0,0 +1,10 @@ +function Publish-ModuleV3 { + [CmdletBinding()] + param ( + + ) + process { + #TODO: Implement + throw "Not Implemented Yet" + } +} \ No newline at end of file diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Update-ModuleInformation.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Update-ModuleInformation.ps1 new file mode 100644 index 0000000..1f38760 --- /dev/null +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Update-ModuleInformation.ps1 @@ -0,0 +1,10 @@ +function Update-ModuleInformation { + [CmdletBinding()] + param ( + + ) + process { + #TODO: Implement + throw "Not Implemented Yet" + } +} \ No newline at end of file