File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111import fs from 'fs'
1212import {
1313 isArray ,
14+ isDirectoryPath ,
15+ isFilePath ,
1416 isInvalidPath
1517} from 'itee-validators'
1618import path from 'path'
@@ -22,9 +24,8 @@ function getPathsUnder ( directoryPath ) {
2224/**
2325 * Allow to search all files under filePaths in a recursive way
2426 *
25- * @param {Array.<string>|string } filePaths - The files paths where search files
27+ * @param {Array.<string>|string } paths - The files paths where search files
2628 * @returns {Array } - The paths of finded files
27- * @private
2829 */
2930function getFilesPathsUnder ( paths ) {
3031
@@ -36,20 +37,20 @@ function getFilesPathsUnder ( paths ) {
3637 const localPath = _paths [ pathIndex ]
3738
3839 if ( isInvalidPath ( localPath ) ) {
40+
3941 console . error ( `The path "${ localPath } " is not valid !` )
40- continue
41- }
4242
43- const stats = fs . statSync ( localPath )
44- if ( stats . isFile ( ) ) {
43+ } else if ( isFilePath ( localPath ) ) {
4544
4645 files . push ( localPath )
4746
48- } else if ( stats . isDirectory ( ) ) {
47+ } else if ( isDirectoryPath ( localPath ) ) {
4948
5049 const subPaths = getPathsUnder ( localPath )
51- const subFilesPaths = subPaths . forEach ( ( name ) => { getFilesPathsUnder ( path . resolve ( localPath , name ) ) } )
52- Array . prototype . push . apply ( files , subFilesPaths )
50+ const subFilesPaths = subPaths . map ( ( subPath ) => { return getFilesPathsUnder ( path . resolve ( localPath , subPath ) ) } )
51+ if ( subFilesPaths ) {
52+ files = [ ] . concat ( ...subFilesPaths )
53+ }
5354
5455 } else {
5556
You can’t perform that action at this time.
0 commit comments