diff --git a/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 b/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 index a65809c..72b2a05 100644 --- a/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 +++ b/PSFramework.NuGet/functions/Get/Publish-PSFModule.ps1 @@ -79,7 +79,7 @@ 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 -ReleaseNotes $ReleaseNotes -Prerelease $Prerelease -Cmdlet $PSCmdlet -Continue + Update-PSFModuleManifest -Path $moduleData.ManifestPath -Tags $Tags -LicenseUri $LicenseUri -IconUri $IconUri -ProjectUri $ProjectUri -ReleaseNotes $ReleaseNotes -Prerelease $Prerelease -Cmdlet $PSCmdlet -Continue # Case 1: Publish to Destination Path if ($DestinationPath) { @@ -108,24 +108,4 @@ Remove-PSFTempItem -ModuleName PSFramework.NuGet -Name Publish.* } } -} -<# -- Path -- DestinationPath (-/V3) - -- Repository -- Type -- Credential -- ApiKey - -- SkipAutopmaticTags (V2/-) - Disregard -- Force (V2/-) - Disregard -- SkipDependenciesCheck (-/V3) - Partial (only for V3, as V2 does not support) -- SkipModuleManifestValidate (-/V3) - Always. Cheat to make V2 work out. - -# Will be implemented outside of the Get Commands -- Tags (V2/-) -- LicenseUri (V2/-) -- IconUri (V2/-) -- ProjectUri (V2/-) -#> \ No newline at end of file +} \ No newline at end of file diff --git a/PSFramework.NuGet/functions/Get/Update-PSFModuleManifest.ps1 b/PSFramework.NuGet/functions/Get/Update-PSFModuleManifest.ps1 new file mode 100644 index 0000000..7acefe4 --- /dev/null +++ b/PSFramework.NuGet/functions/Get/Update-PSFModuleManifest.ps1 @@ -0,0 +1,167 @@ +function Update-PSFModuleManifest { + [CmdletBinding()] + param ( + $Path, + + [string[]] + $Tags, + + [string] + $LicenseUri, + + [string] + $IconUri, + + [string] + $ProjectUri, + + [string] + $ReleaseNotes, + + [string] + $Prerelease, + + [switch] + $PassThru, + + $Cmdlet = $PSCmdlet, + + [switch] + $Continue + ) + begin { + #region Utility Functions + function Update-ManifestProperty { + [OutputType([System.Management.Automation.Language.Ast])] + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [System.Management.Automation.Language.Ast] + $Ast, + + [Parameter(Mandatory = $true)] + [string] + $Property, + + [Parameter(Mandatory = $true)] + $Value, + + [Parameter(Mandatory = $true)] + [ValidateSet('String', 'StringArray', 'HashtableArray')] + [string] + $Type + ) + + $mainHash = $Ast.FindAll({ + $args[0] -is [System.Management.Automation.Language.HashtableAst] -and + $args[0].KeyValuePairs.Item1.Value -contains 'RootModule' -and + $args[0].KeyValuePairs.Item1.Value -Contains 'ModuleVersion' + }, $true) + + $entry = $mainhash.KeyValuePairs | Where-Object { $_.Item1.Value -eq $Property } + $stringValue = switch ($Type) { + 'String' { $Value | ConvertTo-Psd1 } + 'StringArray' { , @(, @($Value)) | ConvertTo-Psd1 } + 'HashtableArray' { , @(, @($Value)) | ConvertTo-Psd1 } + } + $format = '{0}' + #region Case: Key Already Exists + if ($entry) { + $start = $entry.Item2.Extent.StartOffset + $end = $entry.Item2.Extent.EndOffset + } + #endregion Case: Key Already Exists + + #region Case: Key Does not exist + else { + $line = $Ast.Extent.Text -split "`n" | Where-Object { $_ -match "#\s+$Property = " } + # Entry already exists but is commented out + if ($line) { + $format = "$Property = {0}" + $index = $Ast.Extent.Text.IndexOf($line) + $start = $index + $line.Length - $line.TrimStart().Length + $end = $index + $line.Length + } + # Entry does not exist already + else { + $indent = ($Ast.Extent.Text -split "`n" | Where-Object { $_ -match "^\s+ModuleVersion" }) -replace '^(\s*).+$', '$1' + $format = "$($indent)$($Property) = {0}`n" + $start = $mainHash.Extent.EndOffset - 1 + $end = $mainHash.Extent.EndOffset - 1 + } + } + #endregion Case: Key Does not exist + + $newText = $Ast.Extent.Text.SubString(0,$start) + ($format -f $stringValue) + $Ast.Extent.SubString($end) + [System.Management.Automation.Language.Parser]::ParseInput($newText, [ref]$null, [ref]$null) + } + #endregion Utility Functions + } + process { + # If Nothing to do, do nothing + if (-not ($Tags -or $LicenseUri -or $IconUri -or $ProjectUri -or $ReleaseNotes -or $Prerelease)) { return } + + $killIt = $ErrorActionPreference -eq 'Stop' + + $ast = [System.Management.Automation.Language.Parser]::ParseFile($Path, [ref]$null, [ref]$null) + + $mainHash = $ast.FindAll({ + $args[0] -is [System.Management.Automation.Language.HashtableAst] -and + $args[0].KeyValuePairs.Item1.Value -contains 'RootModule' -and + $args[0].KeyValuePairs.Item1.Value -Contains 'ModuleVersion' + }, $true) + + if (-not $mainHash) { + Stop-PSFFunction -String 'Update-PSFModuleManifest.Error.BadManifest' -StringValues (Get-Item -Path $Path).BaseName, $Path -Cmdlet $Cmdlet -EnableException $killIt -Continue:$Continue + return + } + + #region PrivateData Content + $privateData = [ordered]@{ + PSData = [ordered]@{ } + } + $replacements = @{ } + + $privateDataAst = $mainHash.KeyValuePairs | Where-Object { $_.Item1.Value -eq 'PrivateData' } | ForEach-Object { $_.Item2.PipelineElements[0].Expression } + + if ($privateDataAst) { + foreach ($pair in $privateDataAst.KeyValuePairs) { + if ($pair.Item1.Value -ne 'PSData') { + $id = "%PSF_$(Get-Random)%" + $privateData[$pair.Item1.Value] = $id + $replacements[$id] = $pair.Item2.Extent.Text + continue + } + + foreach ($subPair in $pair.Item2.PipelineElements[0].Expression.KeyValuePairs) { + $id = "%PSF_$(Get-Random)%" + $privateData.PSData[$subPair.Item1.Value] = $id + $replacements[$id] = $subPair.Item2.Extent.Text + } + } + } + + if ($Tags) { $privateData.PSData['Tags'] = $Tags } + if ($LicenseUri) { $privateData.PSData['LicenseUri'] = $LicenseUri } + if ($IconUri) { $privateData.PSData['IconUri'] = $IconUri } + if ($ProjectUri) { $privateData.PSData['ProjectUri'] = $ProjectUri } + if ($ReleaseNotes) { $privateData.PSData['ReleaseNotes'] = $ReleaseNotes } + if ($Prerelease) { $privateData.PSData['Prerelease'] = $Prerelease } + + $privateDataString = $privateData | ConvertTo-Psd1 -Depth 5 + foreach ($pair in $replacements.GetEnumerator()) { + $privateDataString = $privateDataString -replace "'$($pair.Key)'", $pair.Value + } + + if (-not $privateDataAst) { + $newManifest = $ast.Extent.Text.Insert(($mainHash.Extent.EndOffset - 1), "PrivateData = $privateDataString`n") + } + else { + $newManifest = $ast.Extent.Text.SubString(0, $privateDataAst.Extent.StartOffset) + $privateDataString + $ast.Extent.Text.SubString($privateDataAst.Extent.EndOffset) + } + #endregion PrivateData Content + + if ($PassThru) { $newManifest } + else { $newManifest | Set-Content -Path $Path } + } +} \ No newline at end of file diff --git a/PSFramework.NuGet/functions/Resource/Publish-PSFResourceModule.ps1 b/PSFramework.NuGet/functions/Resource/Publish-PSFResourceModule.ps1 index ecdcb79..c7b1e06 100644 --- a/PSFramework.NuGet/functions/Resource/Publish-PSFResourceModule.ps1 +++ b/PSFramework.NuGet/functions/Resource/Publish-PSFResourceModule.ps1 @@ -1,20 +1,91 @@ -function Publish-PSFResourceModule -{ +function Publish-PSFResourceModule { [CmdletBinding()] Param ( - + [PsfValidateScript('PSFramework.Validate.SafeName', ErrorString = 'PSFramework.Validate.SafeName')] + [string] + $Name, + + [string] + $Version = '1.0.0', + + [Parameter(Mandatory = $true)] + [PsfPath] + $Path, + + [Parameter(Mandatory = $true, ParameterSetName = 'ToRepository')] + [PsfValidateSet(TabCompletion = 'PSFramework.NuGet.Repository')] + [PsfArgumentCompleter('PSFramework.NuGet.Repository')] + [string[]] + $Repository, + + [Parameter(ParameterSetName = 'ToRepository')] + [ValidateSet('All', 'V2', 'V3')] + [string] + $Type = 'All', + + [Parameter(ParameterSetName = 'ToRepository')] + [PSCredential] + $Credential, + + [Parameter(ParameterSetName = 'ToRepository')] + [string] + $ApiKey, + + [Parameter(ParameterSetName = 'ToRepository')] + [switch] + $SkipDependenciesCheck, + + [Parameter(Mandatory = $true, ParameterSetName = 'ToPath')] + [PsfDirectory] + $DestinationPath, + + [object[]] + $RequiredModules, + + [string] + $Description = '', + + [string] + $Author, + + [string[]] + $Tags, + + [string] + $LicenseUri, + + [string] + $IconUri, + + [string] + $ProjectUri, + + [string] + $ReleaseNotes, + + [string] + $Prerelease ) - begin - { - - } - process - { - #TODO: Implement + begin { + $killIt = $ErrorActionPreference -eq 'Stop' + $stagingDirectory = New-PSFTempDirectory -ModuleName 'PSFramework.NuGet' -Name Publish.ResourceModule -DirectoryName $Name + $publishParam = $PSBoundParameters | ConvertTo-PSFHashtable -ReferenceCommand Publish-PSFModule -Exclude Path, ErrorAction } - end - { - + process { + try { + New-DummyModule -Path $stagingDirectory -Name $Name -Version $Version -RequiredModules $RequiredModules -Description $Description -Author $Author -Cmdlet $PSCmdlet + $resources = New-Item -Path $stagingDirectory -Name Resources -ItemType Directory -Force + $Path | Copy-Item -Destination $resources.FullName -Recurse -Force -Confirm:$false -WhatIf:$false + + Publish-PSFModule @publishParam -Path $stagingDirectory -ErrorAction Stop + } + catch { + Stop-PSFFunction -String 'Publish-PSFResourceModule.Error' -StringValues $Name -EnableException $killIt -ErrorRecord $_ -Cmdlet $PSCmdlet + return + } + finally { + Remove-PSFTempItem -ModuleName 'PSFramework.NuGet' -Name Publish.ResourceModule + } } } diff --git a/PSFramework.NuGet/functions/Resource/Save-PSFResourceModule.ps1 b/PSFramework.NuGet/functions/Resource/Save-PSFResourceModule.ps1 index f2c5340..c5eb6ea 100644 --- a/PSFramework.NuGet/functions/Resource/Save-PSFResourceModule.ps1 +++ b/PSFramework.NuGet/functions/Resource/Save-PSFResourceModule.ps1 @@ -136,30 +136,30 @@ try { $saveParam = $PSBoundParameters | ConvertTo-PSFHashtable -ReferenceCommand Save-PSFModule -Exclude Path, ErrorAction Invoke-PSFProtectedCommand -ActionString 'Save-PSFResourceModule.Downloading' -ActionStringValues ($Name -join ', ') -ScriptBlock { - Save-PSFModule @saveParam -Path $tempDirectory -ErrorAction Stop -WhatIf:$false -Confirm:$false + $null = Save-PSFModule @saveParam -Path $tempDirectory -ErrorAction Stop -WhatIf:$false -Confirm:$false } -PSCmdlet $PSCmdlet -EnableException $killIt -WhatIf:$false -Confirm:$false if (Test-PSFFunctionInterrupt) { return } foreach ($pathEntry in $Path) { foreach ($module in Get-ChildItem -Path $tempDirectory) { - foreach ($version in Get-ChildItem -LiteralPath $module.FullName) { - $dataPath = Join-Path -Path $version.FullName -ChildPath 'Resources' + foreach ($versionFolder in Get-ChildItem -LiteralPath $module.FullName) { + $dataPath = Join-Path -Path $versionFolder.FullName -ChildPath 'Resources' if (-not (Test-Path -Path $dataPath)) { - Write-PSFMessage -String 'Save-PSFResourceModule.Skipping.InvalidResource' -StringValues $module.Name, $version.Name + Write-PSFMessage -String 'Save-PSFResourceModule.Skipping.InvalidResource' -StringValues $module.Name, $versionFolder.Name continue } - if (-not $PSCmdlet.ShouldProcess("$($module.Name) ($($version.Name))", "Deploy to $pathEntry")) { + if (-not $PSCmdlet.ShouldProcess("$($module.Name) ($($versionFolder.Name))", "Deploy to $pathEntry")) { continue } - foreach ($item in Get-ChildItem -LiteralPath $version.FullName) { + foreach ($item in Get-ChildItem -LiteralPath $dataPath) { $targetPath = Join-Path -Path $pathEntry -ChildPath $item.Name if (-not $Force -and (Test-path -Path $targetPath)) { - Write-PSFMessage -String 'Save-PSFResourceModule.Skipping.AlreadyExists' -StringValues $module.Name, $version.Name, $item.Name, $pathEntry + Write-PSFMessage -String 'Save-PSFResourceModule.Skipping.AlreadyExists' -StringValues $module.Name, $versionFolder.Name, $item.Name, $pathEntry continue } - Invoke-PSFProtectedCommand -ActionString 'Save-PSFResourceModule.Deploying' -ActionStringValues $module.Name, $version.Name, $item.Name, $pathEntry -ScriptBlock { + Invoke-PSFProtectedCommand -ActionString 'Save-PSFResourceModule.Deploying' -ActionStringValues $module.Name, $versionFolder.Name, $item.Name, $pathEntry -ScriptBlock { Move-Item -LiteralPath $item.FullName -Destination $pathEntry -Force -ErrorAction Stop -Confirm:$false -WhatIf:$false } -Target $item.Name -PSCmdlet $PSCmdlet -EnableException $killIt -Continue -Confirm:$false -WhatIf:$false } diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 index e4bd29a..c79f590 100644 --- a/PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Copy-Module.ps1 @@ -58,7 +58,7 @@ } $destinationPath = Join-Path -Path $Destination -ChildPath $moduleName - try { Copy-Item -Path "$($sourceDirectoryPath.Trim('\/'))\*" Destination $destinationPath -Recurse -Force -ErrorAction Stop } + try { Copy-Item -Path "$($sourceDirectoryPath.Trim('\/'))\*" -Destination $destinationPath -Recurse -Force -ErrorAction Stop } catch { Stop-PSFFunction -String 'Copy-Module.Error.StagingFolderCopy' -StringValues $Path -Target $Path @stopCommon -ErrorRecord $_ return @@ -67,8 +67,9 @@ $hashtableAst = $ast.EndBlock.Statements[0].PipelineElements[0].Expression [PSCustomObject]@{ - Name = $moduleNamee + Name = $moduleName Path = $destinationPath + ManifestPath = Join-Path -Path $destinationPath -ChildPath "$moduleName.psd1" SourcePath = $sourceDirectoryPath Author = @($hashtableAst.KeyValuePairs).Where{ $_.Item1.Value -eq 'Author' }.Item2.PipelineElements.Expression.Value Version = @($hashtableAst.KeyValuePairs).Where{ $_.Item1.Value -eq 'ModuleVersion' }.Item2.PipelineElements.Expression.Value diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/New-DummyModule.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/New-DummyModule.ps1 new file mode 100644 index 0000000..dcc1eed --- /dev/null +++ b/PSFramework.NuGet/internal/functions/Get/Publish/New-DummyModule.ps1 @@ -0,0 +1,40 @@ +function New-DummyModule { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [string] + $Path, + + [Parameter(Mandatory = $true)] + [string] + $Name, + + [string] + $Version = '1.0.0', + + [string] + $Description = '', + + [AllowEmptyString()] + [string] + $Author, + + [object[]] + $RequiredModules, + + $Cmdlet = $PSCmdlet + ) + process { + $param = @{ + Path = Join-Path -Path $Path -ChildPath "$Name.psd1" + RootModule = "$Name.psm1" + ModuleVersion = $Version + Description = $Description + } + if ($Author) { $param.Author = $Author } + if ($RequiredModules) { $param.RequiredModules = $RequiredModules } + + New-ModuleManifest @param + $null = New-Item -Path $Path -Name "$Name.psm1" -ItemType File + } +} \ 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 index f4009c3..23897d7 100644 --- a/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV2.ps1 +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV2.ps1 @@ -23,13 +23,8 @@ $Cmdlet = $PSCmdlet ) process { - <# - TODO: - + Implement SkipModuleManifestValidate? - + Test Publish to local with & without dependencies - + Test publish with fake dependencies - #> $killIt = $ErrorActionPreference -eq 'Stop' + $commonPublish = @{ Repository = $Repository.Name Confirm = $false @@ -40,6 +35,9 @@ if ($SkipDependenciesCheck) { Disable-ModuleCommand -Name 'Get-ModuleDependencies' -ModuleName 'PowerShellGet' + + $customReturn = Get-Module $Module.Path -ListAvailable + Disable-ModuleCommand -Name 'Microsoft.PowerShell.Core\Test-ModuleManifest' -ModuleName 'PowerShellGet' -Return $customReturn } try { @@ -50,6 +48,7 @@ finally { if ($SkipDependenciesCheck) { Enable-ModuleCommand -Name 'Get-ModuleDependencies' -ModuleName 'PowerShellGet' + Enable-ModuleCommand -Name 'Microsoft.PowerShell.Core\Test-ModuleManifest' -ModuleName 'PowerShellGet' } } } diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 index 779d674..f313f48 100644 --- a/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 +++ b/PSFramework.NuGet/internal/functions/Get/Publish/Publish-ModuleV3.ps1 @@ -23,12 +23,18 @@ $Cmdlet = $PSCmdlet ) process { - <# - TODO: - + Implement SkipModuleManifestValidate? - + Test Publish to local with & without dependencies - #> $killIt = $ErrorActionPreference -eq 'Stop' + + # Ensure to now overwrite a local file + if ($Repository.Uri -like 'file:*') { + $targetPath = $Repository.Uri -replace '^file:///' -replace 'file:' + $targetFile = Join-Path -Path $targetPath -ChildPath "$($Module.Name).$($Module.Version).nupkg" + if (Test-Path -path $targetFile) { + Stop-PSFFunction -String 'Publish-ModuleV3.Error.AlreadyPublished' -StringValues $Module.Name, $Module.Version, $Repository.Name -Cmdlet $Cmdlet -EnableException $killIt -Continue:$Continue -ContinueLabel $ContinueLabel -Target "$($Module.Name) ($($Module.Version))" + return + } + } + $commonPublish = @{ Repository = $Repository.Name Confirm = $false @@ -36,7 +42,11 @@ if ($Repository.Credential) { $commonPublish.Credential = $Credential } if ($Credential) { $commonPublish.Credential = $Credential } if ($ApiKey) { $commonPublish.ApiKey = $ApiKey } - if ($SkipDependenciesCheck) { $commonPublish.SkipDependenciesCheck = $SkipDependenciesCheck } + if ($SkipDependenciesCheck) { + $commonPublish.SkipDependenciesCheck = $SkipDependenciesCheck + # Parity with V2 - Disabling the dependency check will also prevent Manifest Validation there + $commonPublish.SkipModuleManifestValidate = $true + } Invoke-PSFProtectedCommand -ActionString 'Publish-ModuleV3.Publish' -ActionStringValues $Module.Name, $Module.Version, $Repository -ScriptBlock { Publish-PSResource @commonPublish -Path $Module.Path -ErrorAction Stop diff --git a/PSFramework.NuGet/internal/functions/Get/Publish/Update-ModuleInformation.ps1 b/PSFramework.NuGet/internal/functions/Get/Publish/Update-ModuleInformation.ps1 deleted file mode 100644 index 194193e..0000000 --- a/PSFramework.NuGet/internal/functions/Get/Publish/Update-ModuleInformation.ps1 +++ /dev/null @@ -1,96 +0,0 @@ -function Update-ModuleInformation { - [CmdletBinding()] - param ( - $Module, - - [string[]] - $Tags, - - [string] - $LicenseUri, - - [string] - $IconUri, - - [string] - $ProjectUri, - - [string] - $ReleaseNotes, - - [string] - $Prerelease, - - $Cmdlet = $PSCmdlet, - - [switch] - $Continue - ) - process { - # If Nothing to do, do nothing - if (-not ($Tags -or $LicenseUri -or $IconUri -or $ProjectUri -or $ReleaseNotes -or $Prerelease)) { return } - - $killIt = $ErrorActionPreference -eq 'Stop' - - $manifestPath = Join-Path -Path $Module.Path -ChildPath "$($Module.Name).psd1" - - $tokens = $null - $errors = $null - $ast = [System.Management.Automation.Language.Parser]::ParseFile($manifestPath, [ref]$tokens, [ref]$errors) - - $mainHash = $ast.FindAll({ - $args[0] -is [System.Management.Automation.Language.HashtableAst] -and - $args[0].KeyValuePairs.Item1.Value -contains 'RootModule' -and - $args[0].KeyValuePairs.Item1.Value -Contains 'ModuleVersion' - }, $true) - - if (-not $mainHash) { - Stop-PSFFunction -String 'Update-ModuleInformation.Error.BadManifest' -StringValues $module.Name, $manifestPath -Cmdlet $Cmdlet -EnableException $killIt -Continue:$Continue - return - } - - $privateData = [ordered]@{ - PSData = [ordered]@{ } - } - $replacements = @{ } - - $privateDataAst = $mainHash.KeyValuePairs | Where-Object { $_.Item1.Value -eq 'PrivateData' } | ForEach-Object { $_.Item2.PipelineElements[0].Expression } - - if ($privateDataAst) { - foreach ($pair in $privateDataAst.KeyValuePairs) { - if ($pair.Item1.Value -ne 'PSData') { - $id = "%PSF_$(Get-Random)%" - $privateData[$pair.Item1.Value] = $id - $replacements[$id] = $pair.Item2.Extent.Text - continue - } - - foreach ($subPair in $pair.Item2.PipelineElements[0].Expression.KeyValuePairs) { - $id = "%PSF_$(Get-Random)%" - $privateData.PSData[$subPair.Item1.Value] = $id - $replacements[$id] = $subPair.Item2.Extent.Text - } - } - } - - if ($Tags) { $privateData.PSData['Tags'] = $Tags } - if ($LicenseUri) { $privateData.PSData['LicenseUri'] = $LicenseUri } - if ($IconUri) { $privateData.PSData['IconUri'] = $IconUri } - if ($ProjectUri) { $privateData.PSData['ProjectUri'] = $ProjectUri } - if ($ReleaseNotes) { $privateData.PSData['ReleaseNotes'] = $ReleaseNotes } - if ($Prerelease) { $privateData.PSData['Prerelease'] = $Prerelease } - - $privateDataString = $privateData | ConvertTo-Psd1 -Depth 5 - foreach ($pair in $replacements.GetEnumerator()) { - $privateDataString = $privateDataString -replace "'$($pair.Key)'", $pair.Value - } - - if (-not $privateDataAst) { - $newManifest = $ast.Extent.Text.Insert(($mainHash.Extent.EndOffset - 1), "PrivateData = $privateDataString") - } - else { - $newManifest = $ast.Extent.Text.SubString(0, $privateDataAst.Extent.StartOffset) + $privateDataString + $ast.Extent.Text.SubString($privateDataAst.Extent.EndOffset) - } - $newManifest | Set-Content -Path $manifestPath - } -} \ No newline at end of file diff --git a/PSFramework.NuGet/internal/functions/Other/Disable-ModuleCommand.ps1 b/PSFramework.NuGet/internal/functions/Other/Disable-ModuleCommand.ps1 index e072284..be14aed 100644 --- a/PSFramework.NuGet/internal/functions/Other/Disable-ModuleCommand.ps1 +++ b/PSFramework.NuGet/internal/functions/Other/Disable-ModuleCommand.ps1 @@ -7,12 +7,25 @@ [Parameter(Mandatory = $true)] [string] - $ModuleName + $ModuleName, + + $Return ) process { - Import-Module $ModuleName + if ($PSBoundParameters.Keys -contains 'Return') { + $script:ModuleCommandReturns[$Name] = $Return + } + + + Import-Module $ModuleName -Verbose:$False & (Get-Module $ModuleName) { - function script:psfFunctionOverride { } + function script:psfFunctionOverride { + $calledAs = $MyInvocation.InvocationName + $returns = & (Get-Module PSFramework.NuGet) { $script:ModuleCommandReturns } + if ($returns.Keys -contains $calledAs) { + $returns[$calledAs] + } + } Set-Alias -Name $args[0] -Value psfFunctionOverride -Scope Script } $Name } diff --git a/PSFramework.NuGet/internal/functions/Other/Enable-ModuleCommand.ps1 b/PSFramework.NuGet/internal/functions/Other/Enable-ModuleCommand.ps1 index 8232b9c..440b997 100644 --- a/PSFramework.NuGet/internal/functions/Other/Enable-ModuleCommand.ps1 +++ b/PSFramework.NuGet/internal/functions/Other/Enable-ModuleCommand.ps1 @@ -10,7 +10,7 @@ $ModuleName ) process { - Import-Module $ModuleName + Import-Module $ModuleName -Verbose:$False $module = Get-Module -Name $ModuleName $internal = [PSFramework.Utility.UtilityHost]::GetPrivateProperty('Internal', $module.SessionState) diff --git a/PSFramework.NuGet/internal/scripts/variables.ps1 b/PSFramework.NuGet/internal/scripts/variables.ps1 index 5019922..1effd5f 100644 --- a/PSFramework.NuGet/internal/scripts/variables.ps1 +++ b/PSFramework.NuGet/internal/scripts/variables.ps1 @@ -10,4 +10,7 @@ $script:psget = @{ $script:psget = @{ } # What paths are available for Install-PSFModule's "-Scope" parameter -$script:moduleScopes = @{ } \ No newline at end of file +$script:moduleScopes = @{ } + +# Static Override values provided when using Disable-ModuleCommand +$script:ModuleCommandReturns = @{ } \ No newline at end of file