Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cowboy/grunt
base: 1c7a465e3c
...
head fork: cowboy/grunt
compare: 0b7eae22b6
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 38 additions and 43 deletions.
  1. +38 −43 lib/grunt/file.js
View
81 lib/grunt/file.js
@@ -29,13 +29,13 @@ var YAML = require('js-yaml');
var win32 = process.platform === 'win32';
// Normalize \\ paths to / paths.
-function unixifyPath(filepath) {
+var unixifyPath = function(filepath) {
if (win32) {
return filepath.replace(/\\/g, '/');
} else {
return filepath;
}
-}
+};
// Change the current base path (ie, CWD) to the specified path.
file.setBase = function() {
@@ -43,34 +43,22 @@ file.setBase = function() {
process.chdir(dirpath);
};
-// Match a filepath or filepaths against one or more wildcard patterns. Returns
-// all matching filepaths.
-file.match = function(options, patterns, filepaths) {
- if (grunt.util.kindOf(options) !== 'object') {
- filepaths = patterns;
- patterns = options;
- options = {};
- }
- // Return empty set if patterns or filepaths are completely empty.
- if (patterns == null || filepaths == null) { return []; }
- // Normalize patterns and filepaths to arrays.
- if (!Array.isArray(patterns)) { patterns = [patterns]; }
- if (!Array.isArray(filepaths)) { filepaths = [filepaths]; }
- // Return empty set if there are no patterns or filepaths.
- if (patterns.length === 0 || filepaths.length === 0) { return []; }
+// Process specified wildcard glob patterns or filenames against a
+// callback, processing templates, excluding and uniquing files in the
+// result set.
+var processPatterns = function(patterns, fn) {
// Filepaths to return.
var result = [];
// Flattened, Underscore.js-chainable set of patterns.
- grunt.util._(patterns).chain().flatten().map(function(pattern) {
- // Process any templates.
- return grunt.template.process(pattern);
- }).each(function(pattern) {
+ grunt.util._(patterns).chain().flatten().each(function(pattern) {
+ // If pattern is a template, process it accordingly.
+ pattern = grunt.template.process(pattern);
// If the first character is ! it should be omitted
var exclusion = pattern.indexOf('!') === 0;
// If the pattern is an exclusion, remove the !
if (exclusion) { pattern = pattern.slice(1); }
// Find all matching files for this pattern.
- var matches = filepaths.filter(file.glob.minimatch.filter(pattern, options));
+ var matches = fn(pattern);
if (exclusion) {
// If an exclusion, remove matching files.
result = grunt.util._.difference(result, matches);
@@ -83,6 +71,27 @@ file.match = function(options, patterns, filepaths) {
};
// Match a filepath or filepaths against one or more wildcard patterns. Returns
+// all matching filepaths.
+file.match = function(options, patterns, filepaths) {
+ if (grunt.util.kindOf(options) !== 'object') {
+ filepaths = patterns;
+ patterns = options;
+ options = {};
+ }
+ // Return empty set if either patterns or filepaths was omitted.
+ if (patterns == null || filepaths == null) { return []; }
+ // Normalize patterns and filepaths to arrays.
+ if (!Array.isArray(patterns)) { patterns = [patterns]; }
+ if (!Array.isArray(filepaths)) { filepaths = [filepaths]; }
+ // Return empty set if there are no patterns or filepaths.
+ if (patterns.length === 0 || filepaths.length === 0) { return []; }
+ // Return all matching filepaths.
+ return processPatterns(patterns, function(pattern) {
+ return filepaths.filter(file.glob.minimatch.filter(pattern, options));
+ });
+};
+
+// Match a filepath or filepaths against one or more wildcard patterns. Returns
// true if any of the patterns match.
file.isMatch = function() {
return file.match.apply(file, arguments).length > 0;
@@ -100,31 +109,17 @@ file.expand = function() {
// Use the first argument if it's an Array, otherwise convert the arguments
// object to an array and use that.
var patterns = Array.isArray(args[0]) ? args[0] : args;
- // Filepaths to return.
- var result = [];
- // Flattened, Underscore.js-chainable set of patterns.
- grunt.util._(patterns).chain().flatten().each(function(pattern) {
- // If pattern is a template, process it accordingly.
- pattern = grunt.template.process(pattern);
- // If the first character is ! it should be omitted
- var exclusion = pattern.indexOf('!') === 0;
- // If the pattern is an exclusion, remove the !
- if (exclusion) { pattern = pattern.slice(1); }
+ // Return empty set if there are no patterns or filepaths.
+ if (patterns.length === 0) { return []; }
+ // Return all matching filepaths.
+ return processPatterns(patterns, function(pattern) {
// Find all matching files for this pattern.
- var matches = file.glob.glob(pattern, options);
- if (exclusion) {
- // If an exclusion, remove matching files.
- result = grunt.util._.difference(result, matches);
- } else {
- // Otherwise add matching files.
- result = result.concat(matches);
- }
+ return file.glob.glob(pattern, options);
});
- return grunt.util._(result).uniq();
};
// Further filter file.expand.
-function expandByType(type) {
+var expandByType = function(type) {
var args = grunt.util.toArray(arguments).slice(1);
// If the first argument is an options object, grab it.
var options = grunt.util.kindOf(args[0]) === 'object' ? args[0] : {};
@@ -138,7 +133,7 @@ function expandByType(type) {
return false;
}
});
-}
+};
// A few type-specific file expansion methods.
file.expandDirs = expandByType.bind(file, 'isDirectory');

No commit comments for this range

Something went wrong with that request. Please try again.