Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

fix#191 update publish-module to allow exclude files. #453

Merged
merged 2 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/PSGetPublishModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Describe PowerShell.PSGet.PublishModuleTests -Tags 'BVT','InnerLoop' {
#
# Expected Result: should be able to publish a module
#
It PublishModuleWithNameForSxSVersion {
It "PublishModuleWithNameForSxSVersion" {
$version = "2.0.0.0"
$semanticVersion = '2.0.0'
RemoveItem "$script:PublishModuleBase\*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ function Publish-PSArtifactUtility {

[Parameter(ParameterSetName = 'PublishModule')]
[Uri]
$ProjectUri
$ProjectUri,

[Parameter(ParameterSetName = 'PublishModule')]
[string[]]
$Exclude
)

Install-NuGetClientBinaries -CallerPSCmdlet $PSCmdlet -BootstrapNuGetExe
Expand Down Expand Up @@ -203,6 +207,11 @@ function Publish-PSArtifactUtility {
}
}

$nuspecFiles = ""
if ($Exclude) {
$nuspecFileExcludePattern = $Exclude -Join ";"
$nuspecFiles = @{ src = "**/*.*"; exclude = $nuspecFileExcludePattern }
}

# Add PSModule and PSGet format version tags
if (-not $Tags) {
Expand Down Expand Up @@ -368,6 +377,10 @@ function Publish-PSArtifactUtility {
Dependencies = $dependencies
}

if ($nuspecFiles) {
$params.Add('Files', $nuspecFiles)
}

try {
$NuspecFullName = New-NuspecFile @params
}
Expand Down
23 changes: 15 additions & 8 deletions src/PowerShellGet/public/psgetfunctions/Publish-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ function Publish-Module {
[Uri]
$ProjectUri,

[Parameter(ParameterSetName = "ModuleNameParameterSet")]
[ValidateNotNullOrEmpty()]
[string[]]
$Exclude,

[Parameter()]
[switch]
$Force,
Expand Down Expand Up @@ -137,8 +142,7 @@ function Publish-Module {

if (-not $DestinationLocation -or
(-not (Microsoft.PowerShell.Management\Test-Path $DestinationLocation) -and
-not (Test-WebUri -uri $DestinationLocation)))
{
-not (Test-WebUri -uri $DestinationLocation))) {
$message = $LocalizedData.PSGalleryPublishLocationIsMissing -f ($Repository, $Repository)
ThrowError -ExceptionName "System.ArgumentException" `
-ExceptionMessage $message `
Expand Down Expand Up @@ -370,12 +374,12 @@ function Publish-Module {
# This finds all the items without force (leaving out hidden files and dirs) then copies them
Microsoft.PowerShell.Management\Get-ChildItem $Path -recurse |
Microsoft.PowerShell.Management\Copy-Item -Force -Confirm:$false -WhatIf:$false -Destination {
if ($_.PSIsContainer) {
Join-Path $tempModulePathForFormatVersion $_.Parent.FullName.substring($path.length)
}
else {
join-path $tempModulePathForFormatVersion $_.FullName.Substring($path.Length)
}
if ($_.PSIsContainer) {
Join-Path $tempModulePathForFormatVersion $_.Parent.FullName.substring($path.length)
}
else {
join-path $tempModulePathForFormatVersion $_.FullName.Substring($path.Length)
}
}

try {
Expand Down Expand Up @@ -561,6 +565,9 @@ function Publish-Module {
if ($PSBoundParameters.Containskey('Credential')) {
$PublishPSArtifactUtility_Params.Add('Credential', $Credential)
}
if ($Exclude) {
$PublishPSArtifactUtility_Params.Add('Exclude', $Exclude)
}
Publish-PSArtifactUtility @PublishPSArtifactUtility_Params
}
}
Expand Down