Closed msarchet closed 10 years ago
You win the first pull request race! Congrats! :+1:
I'm thinking we want to syntactically keep it as just a bit of logic inside the current Source function rather than an overload, to be called like this:
// single files
pvc.Source("app.less", "app/colors.less")
// globbed files
pvc.Source("*/**.less")
To do this, I think we'd use the GetFiles (or maybe EnumerateFiles, might be faster) method with a * pattern to essentially just recurse the directory structure relative to the working directory returning everything then run it through a glob matching deal like https://github.com/SLaks/Minimatch/blob/master/Minimatch/Minimatcher.cs (embedded with credits within PVC to avoid the extra external dependency)
Reason for the extra lib and matching rather than using the pattern matching builtin is that we want to support /* or css//* or similar as valid patterns. Also negative matching is a good extra.
The trick would basically be looking for glob characters in the passed in params array to see if we need to glob or not.
Thoughts?
Didn't realize minmatch had been ported to csharp. I'll makes the changes and update the PR.
So took a quick look at the minmatch lib.
It looks like the default use case is to create a matcher
var mm = new Minimatcher(searchPattern);
if (mm.IsMatch(somePath)) {
// The path matches! Do some cool stuff!
}
var matchingPaths = mm.Filter(allPaths);
So do we want to do some intelligent guessing at what path someone is wanting to match on or just use the dir that pvc is ran from?
I think leaning towards the paths just originating from the directory in which the script is invoked make the most sense.
So it would have Source look something like
var mm = new Minimatcher(searchPattern);
var allPaths = Directory.EnumerateFiles(Directory.GetCurrentDirectory());
var matchingPaths = mm.Filter(allPaths);
var streams = matchingPaths.Select(x => new PvcStream(new FileStream(x, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)).As(x));
return new PvcPipe(streams);
Sound good?
yup, that sounds right though we'll need a Minimatcher instance per string passed into Source right?
Done : D
Moved the matching to a separate method for easier testing
Looks great, any chance you can pull latest into it? Thanks!
Welcome to the contributors list Michael!
This is just an initial spike to see if this fits into the pattern
This is related to issue #2.