functions/powershell/module/Invoke-PublishModule.ps1
function Invoke-PublishModule { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$Path, [Parameter(Mandatory = $true)] [string]$NuGetApiKey, [Parameter(Mandatory = $false)] [string]$ExcludeListFile = '.\exclude-files.json', [switch]$SkipCleanup ) $Path = (Resolve-Path -Path $Path).Path $ExcludeListFile = (Resolve-Path -Path $ExcludeListFile).Path Test-Path -Path $Path -ErrorAction Stop $moduleName = Split-Path -Path $Path -Leaf # Create temporary workdir $tempDir = Join-Path -Path $env:TMP -ChildPath (New-TemporaryFile).BaseName $tempDir = Join-Path $tempDir -ChildPath $moduleName New-Item -ItemType Directory -Path $tempDir | Out-Null # Copy files except excluded ones $files = Get-ChildItem -Path $Path -Recurse -File if (Test-Path -Path $ExcludeListFile) { $files = Get-FilteredFiles -Files $files -ExcludeListFile $ExcludeListFile -RootPath $Path } $files | ForEach-Object { $target = Join-Path $tempDir ($_.FullName.Substring($Path.Length).TrimStart('\')) New-Item -ItemType Directory -Force -Path (Split-Path $target) | Out-Null Copy-Item -Path $_.FullName -Destination $target } # Confirm before actual publish $confirmation = Read-Host "Publish module from '$tempDir' to PowerShell Gallery? (y/n)" if ($confirmation -ne 'y') { Write-Verbose 'User aborted publishing process!' return } # Modul veröffentlichen try { $newModule = Publish-Module -Path $tempDir -NuGetApiKey $NuGetApiKey -ErrorAction Stop Write-Output "✅ Modul "($moduleName)" published to PSGallery." return $newModule } catch { throw $_ } finally { if (-not $SkipCleanup) { Remove-Item -Path $tempDir -Recurse -Force } } } |