PublishToPSGallery.ps1
# Date: 2022-04-06 cls $baseFolder = $PSScriptRoot Write-Verbose "STATUS : BaseFolder = $baseFolder" -v if ( -not($baseFolder) ) { $baseFolder = Get-Location } if ( $name = ([regex]::match($baseFolder, '.+\\Modules\\(.[^\\]+)')).groups[1].value ) { Write-Verbose "SUCCESS: Modulename extracted from path: $name" -v } else { Write-Warning "ERROR : Could not extract modulename from $baseFolder" break } # Set $baseFolder to folder where modulefile is to be saved $baseFolder = ([regex]::match($baseFolder, '.+\\Modules\\(.[^\\]+)')).groups[0].value Write-Verbose "STATUS : Removing module $name from this computer" -v Remove-Module $name -ea SilentlyContinue Uninstall-Module $name -Force -ea SilentlyContinue Remove-Item $baseFolder\$name.psd1 -Confirm:$false -Force -ea SilentlyContinue Remove-Item $baseFolder\$name.psm1 -Confirm:$false -Force -ea SilentlyContinue Remove-Item "$((Get-PSRepository PSGallery).SourceLocation)\$name.$(Get-Date -Format 'yyMM.dd.0' ).nupkg" -ea SilentlyContinue if ( $name -eq '3LPublishing' ) { Write-Verbose "STATUS : Loading Publishing functions" -v (Get-ChildItem $baseFolder\Source\Public\*.ps1) | foreach { . $_.FullName } } Write-Verbose "STATUS : Modulefile will be created in: $baseFolder" -v Write-Verbose "STATUS : Calling New-3lModuleFile" -v new-3lModuleFile -path $baseFolder -Verbose try { $splat = @{ 'modulePath' = (gci "$baseFolder\$name.psm1"); 'version' = (Get-Date -Format 'yyMM.dd.0' ); 'repository' = 'PSGallery' } if ( [array]$publicFunctions = (Get-ChildItem -Path "$baseFolder\Source\Public" -ErrorAction SilentlyContinue).BaseName ) { $splat.Add('functionsToExport', $publicFunctions) } Write-Verbose "STATUS : Calling Publish-3LScriptOrModule" -v Publish-3LScriptOrModule @splat -UseSavedSettings -Verbose -ErrorAction Stop Start-Sleep 5 } catch { Write-Error $_ Read-Host 'Press [Enter] to continue' } Install-Module $publishModule -Repository 'PSGallery' |