11var fs = require ( 'fs-extra' ) ;
22var klawSync = require ( 'klaw-sync' ) ;
33var os = require ( 'os' ) ;
4+ var path = require ( 'path' ) ;
45
56var FileError = require ( '../errors/file_error' ) ;
67
78/**
89 * Search files recursivly and filter with include / exlude filters
910 */
1011function FindFiles ( ) {
11- this . path = './' ;
12+ this . path = process . cwd ( ) ;
1213 this . excludeFilters = [ ] ;
1314 this . includeFilters = [ ] ;
1415}
@@ -23,9 +24,9 @@ module.exports = new FindFiles();
2324 *
2425 * @param {String } path
2526 */
26- FindFiles . prototype . setPath = function ( path ) {
27+ FindFiles . prototype . setPath = function ( newPath ) {
2728 if ( path ) {
28- this . path = path ;
29+ this . path = path . resolve ( newPath ) ;
2930 }
3031} ;
3132
@@ -59,6 +60,7 @@ FindFiles.prototype.setIncludeFilters = function(includeFilters) {
5960FindFiles . prototype . search = function ( ) {
6061 var self = this ;
6162 var files = [ ] ;
63+
6264 try {
6365 files = klawSync ( self . path ) . map ( function ( entry ) {
6466 return entry . path ;
@@ -136,14 +138,12 @@ FindFiles.prototype.search = function() {
136138 }
137139
138140 // remove source path prefix
139- if ( self . path !== './' ) {
140- files = files . map ( function ( filename ) {
141- if ( filename . startsWith ( self . path ) ) {
142- return filename . substr ( self . path . length + 1 ) ; // + 1 / at the end
143- }
144- return filename ;
145- } ) ;
146- }
141+ files = files . map ( function ( filename ) {
142+ if ( filename . startsWith ( self . path ) ) {
143+ return filename . substr ( self . path . length + 1 ) ;
144+ }
145+ return filename ;
146+ } ) ;
147147 }
148148 return files ;
149149} ;
0 commit comments