Private/Invoke-CliBackend.ps1

function Invoke-CliBackend {
    <#
    .SYNOPSIS
        Adapter that dispatches pack or analyze to uipcli, uipathcli, or
        UiPath.WorkflowCompiler.
 
    .NOTES
        uipathcli flag names verified against `uipathcli --help` from
        https://github.com/UiPath/uipathcli releases. Update if the Go CLI
        changes its argument interface.
 
        The workflowcompiler backend invokes the engine that both other backends
        drive internally. It is the only one of the three that can control
        --include-sources; uipcli hardcodes it to true and exposes no flag.
    #>

    param(
        [ValidateSet('pack', 'analyze')]
        [string]   $Op,

        [ValidateSet('uipcli', 'uipathcli', 'workflowcompiler')]
        [string]   $Backend,

        [string]   $UipcliExe,
        [string]   $UipathcliExe,
        [string]   $ProjectJson,
        [string]   $OutputDir    = '',   # pack only
        [string[]] $ExtraArgs    = @(),

        # workflowcompiler backend only
        [hashtable]$WorkflowCompiler = @{},
        [hashtable]$PackOptions      = @{},
        [hashtable]$PackSettings     = @{}
    )

    if ($Backend -eq 'workflowcompiler') {
        switch ($Op) {
            'pack' {
                # The compiler takes the project directory, not project.json.
                $projectDir = Split-Path -Parent $ProjectJson
                return Invoke-WorkflowCompilerPack `
                    -WorkflowCompiler $WorkflowCompiler `
                    -ProjectDir       $projectDir `
                    -OutputDir        $OutputDir `
                    -PackOptions      $PackOptions `
                    -PackSettings     $PackSettings `
                    -ExtraArgs        $ExtraArgs
            }
            'analyze' {
                throw "The 'workflowcompiler' backend does not support analyze. Use -Backend uipcli or uipathcli."
            }
        }
    } elseif ($Backend -eq 'uipcli') {
        switch ($Op) {
            'pack' {
                $packArgs = @('package', 'pack', $ProjectJson, '-o', $OutputDir)
                if ($env:UIPATH_DISABLE_TELEMETRY) { $packArgs += '--disableTelemetry' }
                if ($ExtraArgs.Count -gt 0) { $packArgs += $ExtraArgs }
                return Invoke-UipcliPack -UipcliExe $UipcliExe -PackArgs $packArgs
            }
            'analyze' {
                $analyzeArgs = @('package', 'analyze', $ProjectJson)
                if ($ExtraArgs.Count -gt 0) { $analyzeArgs += $ExtraArgs }
                return Invoke-UipathcliCommand -UipathcliExe $UipcliExe -CliArgs $analyzeArgs
            }
        }
    } else {
        # uipathcli (Go binary) — syntax: uipath studio package <op> --source <path> ...
        switch ($Op) {
            'pack' {
                $packArgs = @('studio', 'package', 'pack', '--source', $ProjectJson, '--destination', $OutputDir)
                if ($ExtraArgs.Count -gt 0) { $packArgs += $ExtraArgs }
                return Invoke-UipathcliCommand -UipathcliExe $UipathcliExe -CliArgs $packArgs
            }
            'analyze' {
                $analyzeArgs = @('studio', 'package', 'analyze', '--source', $ProjectJson)
                if ($ExtraArgs.Count -gt 0) { $analyzeArgs += $ExtraArgs }
                return Invoke-UipathcliCommand -UipathcliExe $UipathcliExe -CliArgs $analyzeArgs
            }
        }
    }
}