InvokeAbilityHelpers.psm1

# Implement your module commands in this script.

if (-not $DependenciesPath ) {
    $DependenciesPath = (Join-Path $PSScriptRoot Dependencies)
}

$defaultDependencyTags = @("dev")
$defaultPsDependVersion = '0.1.62'


$defaultPsDependConfiguration = @{
    PSDependOptions                                                                                              = @{
        AddToPath = $true
    }
    InvokeBuild                                                                                                  = @{
        Version        = '4.1.0'
        Tags           = 'dev', 'prod'
        DependencyType = 'PSGalleryModule'
    }
}
Write-Verbose ("DependenciesPath [{0}]" -f $DependenciesPath) -Verbose
if (-not(Get-InstalledModule PSDepend -RequiredVersion $defaultPsDependVersion -ErrorAction SilentlyContinue)) {
    Install-Module PSDepend -RequiredVersion $defaultPsDependVersion -Force -Scope CurrentUser
}
# -ProjectPath (Get-Location).Path
    
Write-Verbose ("Import or Install Dependencies") -Verbose
Import-Module PSDepend -RequiredVersion $defaultPsDependVersion
Invoke-PSDepend -InputObject $defaultPsDependConfiguration  -Install -Import -Force `
    -Target $DependenciesPath -Tags $defaultDependencyTags -ErrorAction Stop -Verbose

# Export only the functions using PowerShell standard verb-noun naming.
# Be sure to list each exported functions in the FunctionsToExport field of the module manifest file.
# This improves performance of command discovery in PowerShell.


function Invoke-BuildStep {
    param (
        [Parameter(Mandatory = $false)] 
        $Task = "default",
        [Parameter(Mandatory = $false)]
        $OutputPath,
        [Parameter(Mandatory = $false)]
        $ProjectPath
    )

    if (-not $ProjectPath ) {
        $ProjectPath = Resolve-Path  (Get-Location).Path
    }
        
    if (-not $OutputPath ) {
        $OutputPath = (Join-Path $ProjectPath)
    }


    $PSBoundParameters.Add("File", (Join-Path $PSScriptRoot Invoke-BuildStep.task.ps1))


    Write-Verbose ("ProjectPath [{0}]" -f $ProjectPath) -Verbose
    Write-Verbose ("OutputPath [{0}]" -f $OutputPath) -Verbose

    Invoke-Build @PSBoundParameters -Result result

    # Invoke-Build $Task {
    # Task default UpdateConfiguration
    # Task UpdateConfiguration{
    # echo "test"
    # }
    # } -Result result

    if ($Result.Error) {exit 1} else {exit 0}
    
    
}
Export-ModuleMember -Function Invoke-BuildStep