build2.ps1

# Set the path to your .psd1 manifest
$psd1Path = ".\OMG.PSUtilities.psd1"
$IncreaseModuleVersion = $true
# Get all public function names (from Public\*.ps1)
$functions = ( Get-ChildItem -Path ".\Public\*.ps1" | ForEach-Object {
    "'$($_.BaseName)'"
} ) -join ",`n "

# Proper replacement block with closing )
$replacement = "FunctionsToExport = @(`n $functions`n )"

# Read current psd1 content
$psd1Content = Get-Content $psd1Path -Raw

# Replace the FunctionsToExport block
$updatedContent = $psd1Content -replace "(?s)FunctionsToExport\s*=\s*@\([^\)]*\)", $replacement

#Increase the module version
if ($updatedContent -match "ModuleVersion\s*=\s*'(\d+)\.(\d+)\.(\d+)'" -and $IncreaseModuleVersion) {
    $major = [int]$matches[1]
    $minor = [int]$matches[2]
    $patch = [int]$matches[3] + 1
    $newVersion = "$major.$minor.$patch"
    
    # Replace the line with the updated version
    $updatedContent = $updatedContent -replace "ModuleVersion\s*=\s*'\d+\.\d+\.\d+'", "ModuleVersion = '$newVersion'"
    
    Write-Host "✅ Module version updated to $newVersion"
} else {
    Write-Warning "⚠️ ModuleVersion not found in the .psd1 file."
}

# Save updated content
Set-Content -Path $psd1Path -Value $updatedContent -Encoding utf8

Write-Host "✅ FunctionsToExport updated in $psd1Path"