Skip to content

Commit 4ff9dff

Browse files
refactor(ngfs): pattern match with minimatch
1 parent 11348e4 commit 4ff9dff

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

packages/ng-schematics/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
"@igniteui/angular-templates": "~19.0.1430",
2424
"@igniteui/cli-core": "~14.3.0",
2525
"@schematics/angular": "~19.0.0",
26-
"rxjs": "^7.8.1"
26+
"rxjs": "^7.8.1",
27+
"minimatch": "^10.0.1"
2728
},
2829
"devDependencies": {
2930
"@types/jasmine": "^5.1.4",
3031
"@types/node": "^22.5.5",
32+
"@types/minimatch": "^5.1.2",
3133
"jasmine": "^5.3.0",
3234
"typescript": "~5.6.2"
3335
},

packages/ng-schematics/src/utils/NgFileSystem.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { DirEntry, FileEntry, Tree } from "@angular-devkit/schematics";
22
import { App, FS_TOKEN, FS_TYPE_TOKEN, FsTypes, IFileSystem } from "@igniteui/cli-core";
3+
import { minimatch } from 'minimatch';
34

45
export class NgTreeFileSystem implements IFileSystem {
56
constructor(private tree: Tree) { }
67
public fileExists(filePath: string): boolean {
78
return this.tree.exists(filePath);
89
}
910

10-
public readFile(filePath: string, encoding?: string): string {
11+
public readFile(filePath: string, _encoding?: string): string {
1112
return (this.tree.read(filePath) || "").toString();
1213
}
1314

@@ -29,25 +30,23 @@ export class NgTreeFileSystem implements IFileSystem {
2930
public glob(dirPath: string, pattern: string, ignorePattern?: string): string[] {
3031
const dir = this.tree.getDir(dirPath);
3132
const entries: string[] = [];
32-
const wildcard = "**/*";
33-
pattern = pattern.split(wildcard).pop() || pattern;
34-
ignorePattern = ignorePattern?.split(wildcard).pop() || ignorePattern;
3533

3634
const visitor = (_fullPath: string, entry?: Readonly<FileEntry>): void => {
37-
if (entry?.path.endsWith(pattern)) {
35+
if (entry && minimatch(entry.path, pattern)) {
3836
entries.push(entry.path);
3937
}
4038
};
39+
4140
if (ignorePattern) {
4241
dir.subfiles.forEach(file => {
43-
if (file.endsWith(pattern)) {
42+
if (minimatch(file, pattern) && !minimatch(file, ignorePattern)) {
4443
entries.push(file);
4544
}
4645
});
4746

4847
const recurse = (dir: DirEntry): void => {
4948
for (const subdirPath of dir.subdirs) {
50-
if (!subdirPath.includes(ignorePattern)) {
49+
if (!minimatch(subdirPath, ignorePattern)) {
5150
const currDir = dir.dir(subdirPath);
5251
if (currDir.subdirs.length) {
5352
recurse(currDir);
@@ -56,14 +55,13 @@ export class NgTreeFileSystem implements IFileSystem {
5655
currDir.visit(visitor);
5756
}
5857
}
59-
}
58+
};
6059

6160
recurse(dir);
6261
return entries;
6362
}
6463

6564
dir.visit(visitor);
66-
6765
return entries;
6866
}
6967
}

yarn.lock

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,7 +4915,7 @@ [email protected]:
49154915
dependencies:
49164916
brace-expansion "^2.0.1"
49174917

4918-
minimatch@^10.0.0:
4918+
minimatch@^10.0.0, minimatch@^10.0.1:
49194919
version "10.0.1"
49204920
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.0.1.tgz#ce0521856b453c86e25f2c4c0d03e6ff7ddc440b"
49214921
integrity sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==
@@ -6701,7 +6701,16 @@ stream-throttle@^0.1.3:
67016701
commander "^2.2.0"
67026702
limiter "^1.0.5"
67036703

6704-
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
6704+
"string-width-cjs@npm:string-width@^4.2.0":
6705+
version "4.2.3"
6706+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
6707+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
6708+
dependencies:
6709+
emoji-regex "^8.0.0"
6710+
is-fullwidth-code-point "^3.0.0"
6711+
strip-ansi "^6.0.1"
6712+
6713+
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
67056714
version "4.2.3"
67066715
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
67076716
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -6761,7 +6770,14 @@ string_decoder@~1.1.1:
67616770
dependencies:
67626771
safe-buffer "~5.1.0"
67636772

6764-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6773+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
6774+
version "6.0.1"
6775+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
6776+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
6777+
dependencies:
6778+
ansi-regex "^5.0.1"
6779+
6780+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
67656781
version "6.0.1"
67666782
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
67676783
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -7408,7 +7424,7 @@ wordwrap@^1.0.0:
74087424
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
74097425
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
74107426

7411-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
7427+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
74127428
version "7.0.0"
74137429
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
74147430
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -7426,6 +7442,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
74267442
string-width "^4.1.0"
74277443
strip-ansi "^6.0.0"
74287444

7445+
wrap-ansi@^7.0.0:
7446+
version "7.0.0"
7447+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
7448+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
7449+
dependencies:
7450+
ansi-styles "^4.0.0"
7451+
string-width "^4.1.0"
7452+
strip-ansi "^6.0.0"
7453+
74297454
wrap-ansi@^8.1.0:
74307455
version "8.1.0"
74317456
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)