* Recursively searches the given searchPaths for js files. * @param {Array. } searchPaths * @param {number} [depth] * @fires sourceFileFound
(searchPaths = [], depth = 1, filter)
| 23 | * @fires sourceFileFound |
| 24 | */ |
| 25 | scan(searchPaths = [], depth = 1, filter) { |
| 26 | let currentFile; |
| 27 | let filePaths = []; |
| 28 | |
| 29 | searchPaths.forEach($ => { |
| 30 | const filepath = path.resolve( env.pwd, decodeURIComponent($) ); |
| 31 | |
| 32 | try { |
| 33 | currentFile = fs.statSync(filepath); |
| 34 | } |
| 35 | catch (e) { |
| 36 | logger.error('Unable to find the source file or directory %s', filepath); |
| 37 | |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if ( currentFile.isFile() ) { |
| 42 | filePaths.push(filepath); |
| 43 | } |
| 44 | else { |
| 45 | filePaths = filePaths.concat( fs.ls(filepath, depth) ); |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | filePaths = filePaths.filter($ => filter.isIncluded($)); |
| 50 | |
| 51 | filePaths = filePaths.filter($ => { |
| 52 | const e = { fileName: $ }; |
| 53 | |
| 54 | this.emit('sourceFileFound', e); |
| 55 | |
| 56 | return !e.defaultPrevented; |
| 57 | }); |
| 58 | |
| 59 | return filePaths; |
| 60 | } |
| 61 | } |
| 62 | exports.Scanner = Scanner; |
no test coverage detected