Skip to content

Commit cb0b98b

Browse files
authored
should be it (#28)
1 parent 43eb2a9 commit cb0b98b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

.publishignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# specifies files which will NOT be published to PS Gallery
2+
.*
3+
PesterTestResults.xml
4+
tools/*
5+
Tests/*
6+
img/*
7+
Docs/*.md
8+
cab/

tools/PublishModule.ps1

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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..."
2728
if (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
4647
if (Test-Path $Destination2) {Remove-Item $Destination2 -Recurse -Force}
4748
Copy-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
5666
Read-Host "All prerequisites check. Press Enter to Publish module or Ctrl+C to abort"

0 commit comments

Comments
 (0)