diff --git a/.publishignore b/.publishignore new file mode 100644 index 0000000..afbce2b --- /dev/null +++ b/.publishignore @@ -0,0 +1,8 @@ +# specifies files which will NOT be published to PS Gallery +.* +PesterTestResults.xml +tools/* +Tests/* +img/* +Docs/*.md +cab/ \ No newline at end of file diff --git a/tools/PublishModule.ps1 b/tools/PublishModule.ps1 index 8534063..8a13471 100644 --- a/tools/PublishModule.ps1 +++ b/tools/PublishModule.ps1 @@ -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 { @@ -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"