Skip to content

Commit

Permalink
Merge pull request #223 from lellimecnar/exclude
Browse files Browse the repository at this point in the history
Exclude pattern support
  • Loading branch information
Ross committed Nov 6, 2015
2 parents 2d0f331 + 2c82c15 commit a9348b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"chokidar": "1.2.0",
"glob": "5.0.15",
"lodash.defaults": "3.1.2",
"minimatch": "3.0.0",
"path-is-absolute": "1.0.0",
"stampit": "1.1.0",
"strip-json-comments": "1.0.4",
Expand Down
18 changes: 18 additions & 0 deletions src/utils/getFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var fs = require( 'fs' )
var glob = require( 'glob' )
var async = require( 'async' )
var path = require( 'path' )
var Minimatch = require( 'minimatch' ).Minimatch

/**
* @description globs files and returns an array, used in various methods
Expand All @@ -14,8 +16,24 @@ var getFiles = function( dir ) {
throw new TypeError( 'getFiles err. Expected string, but received: ' + typeof dir )
}

this.config.exclude = ( this.config.exclude || [] ).map( function( exclude ) {
return new Minimatch( exclude, {
matchBase: true
} )
} )

glob( dir, {}, function( err, files ) {
if ( err ) { throw err }
files = files.filter( function( file ) {
var excluded = false
var relPath = path.relative( dir.replace( '/**/*.styl', '' ), file )

this.config.exclude.forEach( function( exclude ) {
excluded = excluded || exclude.match( relPath )
} )

return !excluded
}, this )
this.cache.filesLen = files.length - 1
this.cache.files = files
return async.map( this.cache.files, fs.readFile, this.parse.bind( this ) )
Expand Down

0 comments on commit a9348b0

Please sign in to comment.