Skip to content

Commit

Permalink
Continued work on package deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichWeinmann committed Nov 29, 2024
1 parent 3df7ca0 commit cfec316
Show file tree
Hide file tree
Showing 15 changed files with 1,053 additions and 71 deletions.
15 changes: 8 additions & 7 deletions PSFramework.NuGet/PSFramework.NuGet.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
Author = 'Friedrich Weinmann'

# Company or vendor of this module
CompanyName = 'Microsoft'
CompanyName = ' '

# Copyright statement for this module
Copyright = 'Copyright (c) 2023 Friedrich Weinmann'
Copyright = 'Copyright (c) 2024 Friedrich Weinmann'

# Description of the functionality provided by this module
Description = 'A wrapper around the PowerShellGet modules'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'
PowerShellVersion = '5.1'

# Modules that must be imported into the global environment prior to importing
# this module
RequiredModules = @(
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.7.270' }
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.12.346' }
)

# Assemblies that must be loaded prior to importing this module
Expand All @@ -41,6 +41,7 @@
# Functions to export from this module
FunctionsToExport = @(
'Find-PSFModule'
'Get-PSFModuleSignature'
'Get-PSFPowerShellGet'
'Get-PSFRepository'
'Install-PSFModule'
Expand Down Expand Up @@ -77,13 +78,13 @@
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()
Tags = @('nuget', 'modules', 'psresource')

# A URL to the license for this module.
# LicenseUri = ''
LicenseUri = 'https://github.com/PowershellFrameworkCollective/PSFramework.NuGet/blob/master/LICENSE'

# A URL to the main website for this project.
# ProjectUri = ''
ProjectUri = 'https://github.com/PowershellFrameworkCollective/PSFramework.NuGet'

# A URL to an icon representing this module.
# IconUri = ''
Expand Down
2 changes: 1 addition & 1 deletion PSFramework.NuGet/functions/Get/Get-PSFRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Type = 'V2'
Status = $status
Trusted = $repository.Trusted
Priority = -1
Priority = Get-PSFConfigValue -FullName "PSFramework.NuGet.Repositories.$($repository.Name).Priority" -Fallback 100
Uri = $repository.SourceLocation
Object = $repository
}
Expand Down
81 changes: 68 additions & 13 deletions PSFramework.NuGet/functions/Get/Save-PSFModule.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
function Save-PSFModule
{
[CmdletBinding()]
function Save-PSFModule {
[CmdletBinding(PositionalBinding = $false, DefaultParameterSetName = 'ByName', SupportsShouldProcess = $true)]
Param (

[Parameter(Mandatory = $true, Position = 0, ParameterSetName = 'ByName')]
[string[]]
$Name,

[Parameter(ParameterSetName = 'ByName')]
[string]
$Version,

[Parameter(ParameterSetName = 'ByName')]
[switch]
$Prerelease,

[Parameter(Mandatory = $true, Position = 1)]
[string]
$Path,

[PSFComputer[]]
$ComputerName,

[switch]
$SkipDependency,

[switch]
$AuthenticodeCheck = (Get-PSFConfigValue -FullName 'PSFramework.NuGet.Install.AuthenticodeSignature.Check'),

[switch]
$Force,

[PSCredential]
$Credential,

[PsfArgumentCompleter('PSFramework.NuGet.Repository')]
[string[]]
$Repository,

[switch]
$TrustRepository,

[ValidateSet('All', 'V2', 'V3')]
[string]
$Type = 'All',

[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'ByObject')]
[object[]]
$InputObject
)

begin
{
begin {
$repositories = Resolve-Repository -Name $Repository -Type $Type -Cmdlet $PSCmdlet # Terminates if no repositories found
$resolvedPaths = Resolve-RemotePath -Path $Path -ComputerName $ComputerName -TargetHandling Any -Cmdlet $PSCmdlet # Errors for bad paths, terminates if no path

$tempDirectory = New-PSFTempDirectory -Name Staging -ModuleName PSFramework.NuGet
}
process
{
#TODO: Implement
}
end
{

process {
try {
$installData = switch ($PSCmdlet.ParameterSetName) {
ByObject { Resolve-ModuleTarget -InputObject $InputObject -Cmdlet $PSCmdlet }
ByName { Resolve-ModuleTarget -Name $Name -Version $Version -Prerelease:$Prerelease -Cmdlet $PSCmdlet }
}
if (-not $PSCmdlet.ShouldProcess(($installData.Name -join ', '), "Saving modules to $Path")) {
return
}

Save-StagingModule -InstallData $installData -Path $tempDirectory -Repositories $repositories -Cmdlet $PSCmdlet -Credential $Credential -SkipDependency:$SkipDependency -AuthenticodeCheck:$AuthenticodeCheck
#TODO: Implement
Publish-StagingModule -Path $tempDirectory -TargetPath $resolvedPaths -Force:$Force
}
finally {
Remove-PSFTempItem -Name Staging -ModuleName PSFramework.NuGet
}
}
}
2 changes: 1 addition & 1 deletion PSFramework.NuGet/functions/Get/Update-PSFRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Available settings:
- Uri: Url or filesystem path to the repository. Used for both install and publish.
- Priority: Priority of a PowerShellGet V3 Repository. Numeric value, determines repository precedence
- Priority: Priority of a PowerShell Repository. Numeric value, determines repository precedence.
- Type: What kind of PowerShellGet version to apply the configuration to. Details on the options below. Defaults to 'Any'.
- Trusted: Whether the repository should be trusted. Can be set to 0, 1, $false or $true. Defaults to $true.
- Present: Whether the repository should exist at all. Can be set to 0, 1, $false or $true. Defaults to $true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
begin {
$code = {
$modules = Get-Module -Name PowerShellGet -ListAvailable
$modulesV3 = Get-Module -Name Microsoft.PowerShell.PSResourceGet -ListAvailable

$isOnWindows = $PSVersionTable.PSVersion.Major -lt 6 -or $isWindows
if ($isOnWindows) {
Expand All @@ -52,7 +53,7 @@
PSTypeName = 'PSFramework.NuGet.GetReport'
ComputerName = $env:COMPUTERNAME
V2 = ($modules | Where-Object { $_.Version.Major -lt 3 }) -as [bool]
V3 = ($modules | Where-Object { $_.Version.Major -eq 3 }) -as [bool]
V3 = $modulesV3 -as [bool]
V2CanInstall = $v2CanInstall
V2CanPublish = Test-Path -Path $nugetPath
Modules = $modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
Resolved = $resolvedUrl
FileName = ''
}
$onlineVersion[$link].FileName = '{0}-{1}.zip' -f $pkgData[$link].Name, $pkgData[$link].Version
$onlineVersion[$link].FileName = '{0}-{1}.zip' -f $onlineVersion[$link].Name, $onlineVersion[$link].Version
}
}
#endregion Check Online
Expand All @@ -99,6 +99,7 @@

# If online version is newer than internal, download to appdata as cached version
if ('Online' -eq $source) {
if (-not (Test-Path -Path $SourcePath)) { $null = New-Item -Path $SourcePath -ItemType Directory -Force }
Save-PSFPowerShellGet -Path $SourcePath # This can never happen if the user specified a path, so no risk of overwriting.
}

Expand Down Expand Up @@ -182,7 +183,13 @@
#region V2 Bootstrap
V2Binaries {
if ($isOnWindows) {
if (-not (Test-Path -Path "$env:ProgramFiles\Microsoft\Windows\PowerShell\PowerShellGet")) {
$null = New-Item -Path "$env:ProgramFiles\Microsoft\Windows\PowerShell\PowerShellGet" -ItemType Directory -Force
}
Copy-Item -Path (Join-Path -Path $tempFolder -ChildPath 'NuGet.exe') -Destination "$env:ProgramFiles\Microsoft\Windows\PowerShell\PowerShellGet" -Force
if (-not (Test-Path -Path "$env:ProgramFiles\PackageManagement\ProviderAssemblies\nuget\2.8.5.208")) {
$null = New-Item -Path "$env:ProgramFiles\PackageManagement\ProviderAssemblies\nuget\2.8.5.208" -ItemType Directory -Force
}
Copy-Item -Path (Join-Path -Path $tempFolder -ChildPath 'Microsoft.PackageManagement.NuGetProvider.dll') -Destination "$env:ProgramFiles\PackageManagement\ProviderAssemblies\nuget\2.8.5.208" -Force
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
function Save-PSFPowerShellGet {
<#
.SYNOPSIS
Downloads and provides the latest packages for both PowerShellGet V2 and V3.
.DESCRIPTION
Downloads and provides the latest packages for both PowerShellGet V2 and V3.
These can then be used by this module to deploy and bootstrap offline computers with package management tooling.
.PARAMETER Path
The path where to deploy the module packages as zip-files.
Must be a directory.
Defaults to: %AppData%/PowerShell/PSFramework/modules/PowerShellGet
.EXAMPLE
PS C:\> Save-PSFPowerShellGet
Downloads and deploys the latest version of Get V2 & V3 to "%AppData%/PowerShell/PSFramework/modules/PowerShellGet"
#>
[CmdletBinding()]
param (
[PsfValidateScript('PSFramework.Validate.FSPath.Folder', ErrorMessage = 'PSFramework.Validate.FSPath.Folder')]
[PsfValidateScript('PSFramework.Validate.FSPath.Folder', ErrorString = 'PSFramework.Validate.FSPath.Folder')]
[string]
$Path
)
Expand Down
Loading

0 comments on commit cfec316

Please sign in to comment.