@@ -24,6 +24,7 @@ if (($Module.Version.ToString() -split '\.').Count -lt 3) {
2424}
2525
2626# test if remote is not the same
27+ " Checking for module with version $ ( $Module.Version ) online..."
2728if (Find-Module - Name $ModuleName - RequiredVersion ($Module.Version ) - Repository PSGallery - ea 0 ) {
2829 throw ' Module with same version already exists'
2930} else {
@@ -46,11 +47,20 @@ $Destination2 = Join-Path $Destination $ModuleName
4647if (Test-Path $Destination2 ) {Remove-Item $Destination2 - Recurse - Force}
4748Copy-Item - Path . - Destination $Destination - Recurse # it creates folder $ModuleName
4849
49- # remove not needed files (starting with dot and from .gitignore )
50+ # remove not needed files (as per .publishignore )
5051" Removing not needed files"
51- [string []]$Exclude = (Get-Content ' .gitignore' )
52- Get-ChildItem - Path $Destination2 - Recurse - Force | where Name -Match ' ^\.' | Remove-Item - Recurse - Force
53- Get-ChildItem - Path $Destination2 - Include $Exclude - Recurse - Force | Remove-Item - Recurse - Force
52+ $pwdLength = $Destination2.Length + 1
53+ foreach ($line in (Get-Content ' .publishignore' | where {$_ -notlike ' #*' })) {
54+ # "Checking files like $line"
55+ foreach ($file in (Get-ChildItem - Path $Destination2 - Recurse - Force - File)) {
56+ $relativeName = $file.FullName.Substring ($pwdLength ) -replace ' \\' , ' /'
57+ # "$relativeName"
58+ if ($relativeName -like $line ) {
59+ " Removing $relativeName "
60+ Remove-Item $file.FullName - Recurse - Force
61+ }
62+ }
63+ }
5464
5565# publish
5666Read-Host " All prerequisites check. Press Enter to Publish module or Ctrl+C to abort"
0 commit comments