Deploy.ps1

$functionFile = Get-Content *.psm1

if (($functionFile -match "^function ").Count -eq 0) {
    write-host -BackgroundColor red NO FUNCTIONS AVAILABLE
}
$specFunctions =  ($functionFile -match "^function ").Replace("function","").Replace("Function","").Replace("{","").Replace("(","").Replace(")","").Trim()
$replaceFunctions = "FunctionsToExport = @('"+($specFunctions -join "','")+"')"

$file = Get-ChildItem *.psd1
$specFile = Get-Content $file.Name

$specFile = $specFile -replace "FunctionsToExport(.*)",$replaceFunctions


#write specFile
Set-Content -Path $file.Name -Value $specFile

$nuspecfile = Get-ChildItem *.nuspec
if (-not $nuspecfile) {
    Write-host -BackgroundColor red NUSPEC file not AVAILABLE
    nuget spec ($file.Name.split('.'))[0]
    throw 'nuspec was not found. please update before rerun'
}


$xml = [xml](Get-Content $nuspecfile)

$xml.SelectNodes("//version") | % { 
    write-host tes is $_."#text" 
    $oldVersion = $_."#text"
    $numbers = $_."#text".Split(".");
    $numbers[2] = [int]$numbers[2] += 1
    $_."#text" = $numbers -join '.'
    }
$xml.Save(((Get-location).Path+ "/" +$nuspecfile.Name))


$filePSD = Get-ChildItem *.psd1
(get-content $filePSD).replace($oldVersion ,$numbers -join '.') | Out-file -FilePath $filePSD -Force


Remove-Item *.nupkg
nuget pack $nuspecfile 
$filePackage = Get-ChildItem *.nupkg
#nuget push -Source "nuget.org" -ApiKey oy2ipnyjfhwklixog7pqjh3fchttciguxptqspvxwqw5oy ($filePackage.FullName)
Publish-Module -path .\ -NugetAPIKey "oy2ipnyjfhwklixog7pqjh3fchttciguxptqspvxwqw5oy"

#Save-Module -Name Ublion-Topbakkers -Repository LeftPowershell -Path '.'
#Publish-Module -Path 'C:\Users\Sascha Greven\Documents\Tobakkers\Ublion-Topbakkers' -Repository LeftPowershell -NuGetApiKey yfxh774wuu37u4e3v7z7xun3xk24petl6cjcobkv44zp5s5u2pqa