Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"touch": "1.0.0"
},
"dependencies": {
"@simenb/eslint-file-util": "0.0.3",
"async": "1.5.2",
"chalk": "1.1.3",
"chokidar": "1.5.2",
Expand Down
54 changes: 17 additions & 37 deletions src/utils/getFiles.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict'

var fs = require( 'fs' )
var glob = require( 'glob' )
var async = require( 'async' )
var path = require( 'path' )
var globUtil = require( '@simenb/eslint-file-util/lib/util/glob-util' )

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

if ( typeof dir === 'string' ) {
return glob( dir, {}, function( err, files ) {
if ( err ) { throw err }
var arrayOfDirs = Array.isArray( dir ) ? dir : [dir]

files = files.filter( function( file ) {
var excluded = false
var relPath = path.relative( dir.replace( '/**/*.styl', '' ), file )
var globPatterns = globUtil.resolveFileGlobPatterns( arrayOfDirs, { extensions: ['.styl'] } )
var files = globUtil.listFilesToProcess( globPatterns, {
ignorePattern: this.config.exclude,
ignoreFileName: '.stylintignore'
} )

this.config.exclude.forEach( function( exclude ) {
excluded = excluded || exclude.match( relPath )
} )
files = files
.filter( function( file ) {
return !file.ignored
} )
.map( function( file ) {
return file.filename
} )

return !excluded
}, this )
this.cache.filesLen = files.length - 1
this.cache.files = files

this.cache.filesLen = files.length - 1
this.cache.files = files

return async.map( this.cache.files, fs.readFile, this.parse.bind( this ) )
}.bind( this ) )
}
else if ( dir instanceof Array ) {

var files = dir.filter( function( filepath ) {
var excluded = false

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

return !excluded
}, this )

this.cache.filesLen = files.length - 1
this.cache.files = files
return this.cache.files.forEach( function( file ) {
return this.read( file )
}.bind( this ) )
}
return async.map( this.cache.files, fs.readFile, this.parse.bind( this ) )
}

module.exports = getFiles