AL/Get-ALDependenciesFromAppJson.ps1

function Get-ALDependenciesFromAppJson {
    Param(
        [Parameter(Mandatory = $true)]
        $appJson,
        [Parameter(Mandatory = $true)]
        [string]$sourcePath,
        [Parameter(Mandatory = $true)]
        [string] $devOpsToken,
        [Parameter(Mandatory = $false)]
        [string]$containerName,
        [Parameter(Mandatory = $false)]
        [switch] $skipVerification,
        [Parameter(Mandatory = $false)]
        [switch] $Install,
        [switch] $TenantScope
    )

    foreach ($Dependency in $appJson.dependencies | Where-Object Name -NotLike '*Test*' | Where-Object Name -NotLike '*Runtime*') {
        if ($null -ne $Dependency) {
            $envDependency = (Get-DependencyFromEnvironment -sourcePath $sourcePath -name $Dependency.name)
            if ($null -ne $envDependency) {
                Write-Host "Getting dependencies for $($envDependency.name)"
                $apps = Get-DevOpsArtifacts -devOpsOrganization $envDependency.organization -devOpsFeed $envDependency.devOpsFeed -devOpsArtifactName $envDependency.devOpsArtifactName -version $envDependency.version -devOpsToken $devOpsToken -destination (Join-Path $sourcePath ".alpackages")
                if ($null -eq $envDependency.branchName) {
                    $dependencyAppJson = Get-AppJsonForProjectAndRepo -devOpsOrganization $envDependency.organization -devOpsProjectName $envDependency.project -repositoryName $envDependency.repo -devOpsToken $devOpsToken
                }
                else {
                    $dependencyAppJson = Get-AppJsonForProjectAndRepo -devOpsOrganization $envDependency.organization -devOpsProjectName $envDependency.project -repositoryName $envDependency.repo -devOpsToken $devOpsToken -branchName $envDependency.branchName
                }
            }
            else {
                if ($Dependency.publisher -eq 'Microsoft') {
                    $Apps = @()
                    $DependencyAppJson = $null #ConvertFrom-Json '{}'
                }
            }

            # get dependencies for dependency app
            if ($null -ne $DependencyAppJson) {
                Get-ALDependenciesFromAppJson -AppJson $dependencyAppJson -sourcePath $sourcePath -devOpsToken $devOpsToken -containerName $containerName -skipVerification:$skipVerification -Install:$Install
            }

            # copy and install apps
            foreach ($app in $apps) {
                Write-Host "Processing artifact $app"

                if ($Install.IsPresent) {
                    try {
                        $publishParameters = @{
                            containerName = $containerName
                            appFile       = $app
                            install       = $true
                            sync          = $true
                        }

                        if ($TenantScope.IsPresent) {
                            $publishParameters.Add('scope', 'Tenant')
                            $publishParameters.Add('tenant', 'Default')
                        }

                        $publishParameters.Add('skipVerification', $true)
                        
                        Publish-NavContainerApp @publishParameters
                    }
                    catch {
                        if (!($_.Exception.Message.Contains('already published'))) {
                            throw $_.Exception.Message
                        }
                    }
                }
            }
        }
    }
}
Export-ModuleMember Get-ALDependenciesFromAppJson