tools/build.ps1

$ROOT_FOLDER = Resolve-Path $PSScriptRoot\..

Function _Main {
    Invoke-Build
    Update-Manifest
    Copy-Binaries
}

Function Copy-Binaries {
    Copy-Item $ROOT_FOLDER\module\bin\Production\netstandard2.0\*.dll $ROOT_FOLDER\bin\.
}

Function Invoke-Build {
    Push-Location $ROOT_FOLDER\module
    dotnet build -c Production
    Pop-Location
}

Function Update-Manifest {
    [CmdletBinding(SupportsShouldProcess)]
    Param()

    $functions = Get-ChildItem -Recurse -Path $ROOT_FOLDER\script\*\public
    | Select-Object -ExpandProperty BaseName


    $cmdlets = Select-String $ROOT_FOLDER\module\src\*.cs `
        -Pattern '\[Cmdlet\("(.*?)", "(.*?)"\)\]' -AllMatches
    | Select-Object -ExpandProperty Matches
    | % {
        $_ | Select-Object -ExpandProperty Groups
        | Select-Object -Skip 1 -ExpandProperty Value
        | Join-String -Separator '-'
    }

    if ($PSCmdlet.ShouldProcess("Update-ModuleManifest")) {
        Update-ModuleManifest -Path $ROOT_FOLDER\cbsch-pslib.psd1 `
            -FunctionsToExport $functions `
            -CmdletsToExport $cmdlets
    }
}


_Main