From d67415f6ac6c3508bf82caa803e0a8777f475930 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Mon, 29 Jul 2024 06:53:20 +0300 Subject: [PATCH] Replace Tabs with Spaces to follow the conventions - Make 'ExcludedFiles' validation step check all filepaths before finally checking if any has failed --- tools/Invoke-Preprocessing.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index 51f6f7df..f6bac06d 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -72,13 +72,19 @@ throw "[Invoke-Preprocessing] Invalid Paramter Value for 'WorkingDir', passed value: '$WorkingDir'. Either the path is a File or Non-Existing/Invlid, please double check your code." } - if ((-NOT ($ExcludedFiles.Count -eq 0)) -AND (-NOT $SkipExcludedFilesValidation)) { - ForEach ($excludedFile in $ExcludedFiles) { + $count = $ExcludedFiles.Count + if ((-NOT ($count -eq 0)) -AND (-NOT $SkipExcludedFilesValidation)) { + for ($i = 0; $i -lt $count; $i++) { + $excludedFile = $ExcludedFiles[$i] $filePath = "$(($WorkingDir -replace ('\\$', '')) + '\' + ($excludedFile -replace ('\.\\', '')))" if (-NOT (Get-ChildItem -Recurse -Path "$filePath" -File)) { - throw "[Invoke-Preprocessing] File Path & File Pattern was not found '$filePath', use '-SkipExcludedFilesValidation' switch to skip this check." + $failedFilesList += "'$filePath', " } } + $failedFilesList = $failedFilesList -replace (',\s*$', '') + if (-NOT $failedFilesList -eq "") { + throw "[Invoke-Preprocessing] One or more File Paths & File Patterns were not found, you can use '-SkipExcludedFilesValidation' switch to skip this check, and the failed files are: $failedFilesList" + } } $files = Get-ChildItem $WorkingDir -Recurse -Exclude $ExcludedFiles -File @@ -123,7 +129,7 @@ -replace ('\}\s*Catch', '} catch') ` -replace ('\}\s*Catch\s*(?(\[.*?\]\s*(\,)?\s*)+)\s*\{', '} catch ${exceptions} {') ` -replace ('\}\s*Catch\s*(?\[.*?\])\s*\{', '} catch ${exceptions} {') ` - -replace ('(?\[.*?\])\s*(?\$.*?(,|\s*\)))', '${parameter_type}${str_after_type}') ` + -replace ('(?\[.*?\])\s*(?\$.*?(,|\s*\)))', '${parameter_type}${str_after_type}') ` | Set-Content "$file" Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100)