1
1
var fs = require ( 'fs-extra' ) ;
2
2
var klawSync = require ( 'klaw-sync' ) ;
3
3
var os = require ( 'os' ) ;
4
+ var path = require ( 'path' ) ;
4
5
5
6
var FileError = require ( '../errors/file_error' ) ;
6
7
7
8
/**
8
9
* Search files recursivly and filter with include / exlude filters
9
10
*/
10
11
function FindFiles ( ) {
11
- this . path = './' ;
12
+ this . path = process . cwd ( ) ;
12
13
this . excludeFilters = [ ] ;
13
14
this . includeFilters = [ ] ;
14
15
}
@@ -23,9 +24,9 @@ module.exports = new FindFiles();
23
24
*
24
25
* @param {String } path
25
26
*/
26
- FindFiles . prototype . setPath = function ( path ) {
27
+ FindFiles . prototype . setPath = function ( newPath ) {
27
28
if ( path ) {
28
- this . path = path ;
29
+ this . path = path . resolve ( newPath ) ;
29
30
}
30
31
} ;
31
32
@@ -59,6 +60,7 @@ FindFiles.prototype.setIncludeFilters = function(includeFilters) {
59
60
FindFiles . prototype . search = function ( ) {
60
61
var self = this ;
61
62
var files = [ ] ;
63
+
62
64
try {
63
65
files = klawSync ( self . path ) . map ( function ( entry ) {
64
66
return entry . path ;
@@ -136,14 +138,12 @@ FindFiles.prototype.search = function() {
136
138
}
137
139
138
140
// 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
+ } ) ;
147
147
}
148
148
return files ;
149
149
} ;
0 commit comments