psake / PowerShellBuild

Common build tasks for psake and Invoke-Build that build and test PowerShell modules
MIT License
134 stars 24 forks source link

Implement a better Build.Exclude #42

Closed pauby closed 3 years ago

pauby commented 4 years ago

The Build.Exclude configuration is simply an array of strings passed to the Get-ChildItem -Exclude parameter. This is very inflexible and ... a little rubbish. If you try and exclude anything but file(s) it doesn't work.

Expected Behavior

We should implement a Build.ExcludePattern and / or Build.ExcludeWildcard that allows the exclusion to match on a regular expression or wildcards.

The names above are just examples.

Current Behavior

The Build.Exclude configuration is simply an array of strings passed to the Get-ChildItem -Exclude parameter. This is very inflexible and ... a little rubbish. If you try and exclude anything but file(s) it doesn't work.

Possible Solution

I'm happy to submit a PR for this but looking to get agreement on the specifics above.

Your Environment

devblackops commented 4 years ago

@pauby Since Exclude is treated as an array of regex patterns when Compile is $true, how about we make the behavior consistent when it's $false as well? We can take that same logic and use Get-ChildItem and exclude matches instead of Copy-Item?

Thoughts?

pauby commented 4 years ago

Since Exclude is treated as an array of regex patterns when Compile is $true

I didn't actually know that. Just checked it out and indeed it is! What is even more embarrassing is that I added it. Brain. Gone.

I agree that is the best option and makes it consistent.

Plork commented 4 years ago

At the moment it seems broken as well tbh.

When you don't pass any 'exclude' its an empty array.

image

So for each regex in this aray it checks for a '-notmatch'. But since the array is 0 it never checks for anything.

So before this little "hack" my "AllScripts" contains 2 files and after this it contains 0.

Before loop image

After loop image