Skip to content
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
8 changes: 8 additions & 0 deletions .publishignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# specifies files which will NOT be published to PS Gallery
.*
PesterTestResults.xml
tools/*
Tests/*
img/*
Docs/*.md
cab/
18 changes: 14 additions & 4 deletions tools/PublishModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (($Module.Version.ToString() -split '\.').Count -lt 3) {
}

# test if remote is not the same
"Checking for module with version $($Module.Version) online..."
if (Find-Module -Name $ModuleName -RequiredVersion ($Module.Version) -Repository PSGallery -ea 0) {
throw 'Module with same version already exists'
} else {
Expand All @@ -46,11 +47,20 @@ $Destination2 = Join-Path $Destination $ModuleName
if (Test-Path $Destination2) {Remove-Item $Destination2 -Recurse -Force}
Copy-Item -Path . -Destination $Destination -Recurse # it creates folder $ModuleName

# remove not needed files (starting with dot and from .gitignore)
# remove not needed files (as per .publishignore)
"Removing not needed files"
[string[]]$Exclude = (Get-Content '.gitignore')
Get-ChildItem -Path $Destination2 -Recurse -Force | where Name -Match '^\.' | Remove-Item -Recurse -Force
Get-ChildItem -Path $Destination2 -Include $Exclude -Recurse -Force | Remove-Item -Recurse -Force
$pwdLength = $Destination2.Length + 1
foreach ($line in (Get-Content '.publishignore'| where {$_ -notlike '#*'})) {
#"Checking files like $line"
foreach ($file in (Get-ChildItem -Path $Destination2 -Recurse -Force -File)) {
$relativeName = $file.FullName.Substring($pwdLength) -replace '\\','/'
#"$relativeName"
if ($relativeName -like $line) {
"Removing $relativeName"
Remove-Item $file.FullName -Recurse -Force
}
}
}

# publish
Read-Host "All prerequisites check. Press Enter to Publish module or Ctrl+C to abort"
Expand Down