PublishToMyRepo.ps1

# Date: 2021-10-25
cls
$baseFolder = $PSScriptRoot

if ( -not($baseFolder) ) {

    $baseFolder = Get-Location

}

if ( $name = ([regex]::match($baseFolder, '.+\\Modules\\(.[^\\]+)')).groups[1].value ) {
    Write-Verbose "Modulename extracted from path: $name" -v
}
else {
    Write-Warning "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 "Modulefile will be created in: $baseFolder" -v

new-3lModuleFile -path $baseFolder -Verbose

try {

    $splat = @{
        'modulePath' = (gci "$baseFolder\$name.psm1");
        'version'    = (Get-Date -Format 'yyMM.dd.0' );
        'repository' = 'MyRepo'
    }

    if ( [array]$publicFunctions = Get-ChildItem -Path "$baseFolder\Source\Public" -ErrorAction SilentlyContinue ) {
        $splat.Add('functionsToExport', $publicFunctions)
    }

    Publish-3LScriptOrModule @splat -UseSavedSettings -Verbose -ErrorAction Stop
    Start-Sleep 5
}
catch {
    Write-Error $_
    Read-Host 'Press [Enter] to continue'
}