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

Commit 432b55c

Browse files
Benny1007alerickson
authored andcommitted
fix#191 update publish-module to allow exclude files. (#453)
1 parent 8416d39 commit 432b55c

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

Tests/PSGetPublishModule.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Describe PowerShell.PSGet.PublishModuleTests -Tags 'BVT','InnerLoop' {
134134
#
135135
# Expected Result: should be able to publish a module
136136
#
137-
It PublishModuleWithNameForSxSVersion {
137+
It "PublishModuleWithNameForSxSVersion" {
138138
$version = "2.0.0.0"
139139
$semanticVersion = '2.0.0'
140140
RemoveItem "$script:PublishModuleBase\*"

src/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ function Publish-PSArtifactUtility {
6363

6464
[Parameter(ParameterSetName = 'PublishModule')]
6565
[Uri]
66-
$ProjectUri
66+
$ProjectUri,
67+
68+
[Parameter(ParameterSetName = 'PublishModule')]
69+
[string[]]
70+
$Exclude
6771
)
6872

6973
Install-NuGetClientBinaries -CallerPSCmdlet $PSCmdlet -BootstrapNuGetExe
@@ -203,6 +207,11 @@ function Publish-PSArtifactUtility {
203207
}
204208
}
205209

210+
$nuspecFiles = ""
211+
if ($Exclude) {
212+
$nuspecFileExcludePattern = $Exclude -Join ";"
213+
$nuspecFiles = @{ src = "**/*.*"; exclude = $nuspecFileExcludePattern }
214+
}
206215

207216
# Add PSModule and PSGet format version tags
208217
if (-not $Tags) {
@@ -368,6 +377,10 @@ function Publish-PSArtifactUtility {
368377
Dependencies = $dependencies
369378
}
370379

380+
if ($nuspecFiles) {
381+
$params.Add('Files', $nuspecFiles)
382+
}
383+
371384
try {
372385
$NuspecFullName = New-NuspecFile @params
373386
}

src/PowerShellGet/public/psgetfunctions/Publish-Module.ps1

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ function Publish-Module {
7070
[Uri]
7171
$ProjectUri,
7272

73+
[Parameter(ParameterSetName = "ModuleNameParameterSet")]
74+
[ValidateNotNullOrEmpty()]
75+
[string[]]
76+
$Exclude,
77+
7378
[Parameter()]
7479
[switch]
7580
$Force,
@@ -137,8 +142,7 @@ function Publish-Module {
137142

138143
if (-not $DestinationLocation -or
139144
(-not (Microsoft.PowerShell.Management\Test-Path $DestinationLocation) -and
140-
-not (Test-WebUri -uri $DestinationLocation)))
141-
{
145+
-not (Test-WebUri -uri $DestinationLocation))) {
142146
$message = $LocalizedData.PSGalleryPublishLocationIsMissing -f ($Repository, $Repository)
143147
ThrowError -ExceptionName "System.ArgumentException" `
144148
-ExceptionMessage $message `
@@ -370,12 +374,12 @@ function Publish-Module {
370374
# This finds all the items without force (leaving out hidden files and dirs) then copies them
371375
Microsoft.PowerShell.Management\Get-ChildItem $Path -recurse |
372376
Microsoft.PowerShell.Management\Copy-Item -Force -Confirm:$false -WhatIf:$false -Destination {
373-
if ($_.PSIsContainer) {
374-
Join-Path $tempModulePathForFormatVersion $_.Parent.FullName.substring($path.length)
375-
}
376-
else {
377-
join-path $tempModulePathForFormatVersion $_.FullName.Substring($path.Length)
378-
}
377+
if ($_.PSIsContainer) {
378+
Join-Path $tempModulePathForFormatVersion $_.Parent.FullName.substring($path.length)
379+
}
380+
else {
381+
join-path $tempModulePathForFormatVersion $_.FullName.Substring($path.Length)
382+
}
379383
}
380384

381385
try {
@@ -561,6 +565,9 @@ function Publish-Module {
561565
if ($PSBoundParameters.Containskey('Credential')) {
562566
$PublishPSArtifactUtility_Params.Add('Credential', $Credential)
563567
}
568+
if ($Exclude) {
569+
$PublishPSArtifactUtility_Params.Add('Exclude', $Exclude)
570+
}
564571
Publish-PSArtifactUtility @PublishPSArtifactUtility_Params
565572
}
566573
}

0 commit comments

Comments
 (0)