Private/Test-PlumberTaskPathExcluded.ps1
|
function Test-PlumberTaskPathExcluded { <# .SYNOPSIS Tests whether a path is excluded for a Plumber task. .DESCRIPTION Reads task-scoped exclude patterns from PlumberConfig.ExcludePaths and returns true when the supplied path matches a pattern for the task. .PARAMETER Task The task name to check. .PARAMETER Path The path to check. .EXAMPLE Test-PlumberTaskPathExcluded -Task Backticks -Path ./Tests/Assets/File.ps1 Returns true when the Backticks task has an exclude path matching the supplied path. #> [CmdletBinding()] [OutputType([bool])] param ( [Parameter(Mandatory)] [string] $Task, [Parameter(Mandatory)] [string] $Path ) if (-not $script:PlumberConfig.ExcludePaths) { return $false } if (-not $script:PlumberConfig.ExcludePaths.ContainsKey($Task)) { return $false } $absolutePath = [System.IO.Path]::GetFullPath($Path).Replace('\', '/') $relativePath = if ($script:PlumberConfig.BuildRoot) { [System.IO.Path]::GetRelativePath($script:PlumberConfig.BuildRoot, $Path) } else { $Path } $normalizedPath = $relativePath.Replace('\', '/') foreach ($pattern in @($script:PlumberConfig.ExcludePaths[$Task])) { $normalizedPattern = $pattern.Replace('\', '/') if ( $normalizedPath -like $normalizedPattern -or $absolutePath -like $normalizedPattern -or $absolutePath -like "*/$normalizedPattern" ) { return $true } } $false } |