functions/Publish-MyModule.ps1
function Publish-MyModule { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$Path, [Parameter(Mandatory = $false)] [string]$ExcludeListFile = '.\exclude-files.json', [switch]$SkipCleanup ) $Path = (Resolve-Path -Path $Path).Path $ExcludeListFile = (Resolve-Path -Path $ExcludeListFile).Path $moduleName = Split-Path -Path $Path -Leaf $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" try { $null = Test-ModuleManifest -Path $moduleManifestPath -ErrorAction Stop } catch { throw "Das Modulmanifest '$moduleManifestPath' ist ungültig oder enthält Fehler: $($_.Exception.Message)" } # Temporäres Arbeitsverzeichnis erstellen $tempDir = Join-Path -Path $env:TMP -ChildPath (New-TemporaryFile).BaseName $tempDir = Join-Path $tempDir -ChildPath $moduleName New-Item -ItemType Directory -Path $tempDir | Out-Null # Nur erlaubte Dateien kopieren $files = Get-ChildItem -Path $Path -Recurse -File $filteredFiles = Get-FilteredFiles -Files $files -ExcludeListFile $ExcludeListFile -RootPath $Path $filteredFiles| 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 } # Bestätigung vor dem Veröffentlichen $confirmation = Read-Host "Modul unter '$tempDir' zur PowerShell Gallery veröffentlichen? (y/n)" if ($confirmation -ne 'y') { Write-Host 'Veröffentlichung abgebrochen.' return } # Modul veröffentlichen try { $apiKey = Get-Secret -Name NuGetApiKeyBcAdmin -AsPlainText Publish-Module -Path $tempDir -NuGetApiKey $apiKey -ErrorAction Stop Write-Output "✅ Modul BcAdmin erfolgreich veröffentlicht." } catch { throw $_ } finally { if (-not $SkipCleanup) { Remove-Item -Path $tempDir -Recurse -Force } } } |