1- import { Tree } from "@angular-devkit/schematics" ;
1+ import { DirEntry , FileEntry , Tree } from "@angular-devkit/schematics" ;
22import { App , FS_TOKEN , FS_TYPE_TOKEN , FsTypes , IFileSystem } from "@igniteui/cli-core" ;
33
44export class NgTreeFileSystem implements IFileSystem {
@@ -23,23 +23,46 @@ export class NgTreeFileSystem implements IFileSystem {
2323 /**
2424 * Returns a list of file paths under a directory based on a match pattern
2525 * @param dirPath Root dir to search in
26- * @param pattern Supports only recursive wildcard ' \*\*\/\*'
27- * @param ignorePattern Optional pattern to ignore
26+ * @param pattern Supports only recursive wildcard ` \*\*\/\*`
27+ * @param ignorePattern Optional pattern to ignore for each subdirectory
2828 */
2929 public glob ( dirPath : string , pattern : string , ignorePattern ?: string ) : string [ ] {
3030 const dir = this . tree . getDir ( dirPath ) ;
3131 const entries : string [ ] = [ ] ;
32- pattern = pattern . split ( "**/*" ) . pop ( ) || pattern ;
33-
34- dir . visit ( ( _fullPath , entry ) => {
35- if ( ignorePattern && entry ?. path . includes ( ignorePattern ) ) {
36- return ;
37- }
32+ const wildcard = "**/*" ;
33+ pattern = pattern . split ( wildcard ) . pop ( ) || pattern ;
34+ ignorePattern = ignorePattern ?. split ( wildcard ) . pop ( ) || ignorePattern ;
3835
36+ const visitor = ( _fullPath : string , entry ?: Readonly < FileEntry > ) : void => {
3937 if ( entry ?. path . endsWith ( pattern ) ) {
4038 entries . push ( entry . path ) ;
4139 }
42- } ) ;
40+ } ;
41+ if ( ignorePattern ) {
42+ dir . subfiles . forEach ( file => {
43+ if ( file . endsWith ( pattern ) ) {
44+ entries . push ( file ) ;
45+ }
46+ } ) ;
47+
48+ const recurse = ( dir : DirEntry ) : void => {
49+ for ( const subdirPath of dir . subdirs ) {
50+ if ( ! subdirPath . includes ( ignorePattern ) ) {
51+ const currDir = dir . dir ( subdirPath ) ;
52+ if ( currDir . subdirs . length ) {
53+ recurse ( currDir ) ;
54+ return ;
55+ }
56+ currDir . visit ( visitor ) ;
57+ }
58+ }
59+ }
60+
61+ recurse ( dir ) ;
62+ return entries ;
63+ }
64+
65+ dir . visit ( visitor ) ;
4366
4467 return entries ;
4568 }
0 commit comments