@@ -7,7 +7,7 @@ import * as path from 'path';
7
7
* @param isDebugEnabled - Whether debugging is enabled
8
8
*/
9
9
export function log ( message : string , isDebugEnabled : boolean ) : void {
10
- if ( isDebugEnabled ) return ;
10
+ if ( ! isDebugEnabled ) return ;
11
11
console . info ( message ) ;
12
12
}
13
13
@@ -19,7 +19,8 @@ export function log(message: string, isDebugEnabled: boolean): void {
19
19
export function isValidClassName ( className : string ) : boolean {
20
20
// Class names must start with a letter, underscore, or hyphen
21
21
// and can be followed by letters, numbers, underscores, or hyphens
22
- return / ^ - ? [ _ a - z A - Z ] + [ _ a - z A - Z 0 - 9 - ] * $ / . test ( className ) ;
22
+ const CLASS_NAME_REGEX = / ^ - ? [ _ a - z A - Z ] + [ _ a - z A - Z 0 - 9 - ] * $ / ;
23
+ return CLASS_NAME_REGEX . test ( className ) ;
23
24
}
24
25
25
26
interface FileInfo {
@@ -35,17 +36,21 @@ interface FileInfo {
35
36
*/
36
37
export function findFiles ( dir : string , pattern : RegExp ) : FileInfo [ ] {
37
38
const files : FileInfo [ ] = [ ] ;
38
- const findFilesRecursive = ( currentDir : string ) => {
39
- const dirFiles = fs . readdirSync ( currentDir ) ;
40
- dirFiles . forEach ( ( file ) => {
41
- const fullPath = path . join ( currentDir , file ) ;
42
- if ( fs . statSync ( fullPath ) . isDirectory ( ) ) {
39
+
40
+ function findFilesRecursive ( currentDir : string ) : void {
41
+ const dirEntries = fs . readdirSync ( currentDir , { withFileTypes : true } ) ;
42
+
43
+ for ( const entry of dirEntries ) {
44
+ const fullPath = path . join ( currentDir , entry . name ) ;
45
+
46
+ if ( entry . isDirectory ( ) ) {
43
47
findFilesRecursive ( fullPath ) ;
44
- } else if ( pattern . test ( file ) ) {
45
- files . push ( { name : file , path : fullPath } ) ;
48
+ } else if ( pattern . test ( entry . name ) ) {
49
+ files . push ( { name : entry . name , path : fullPath } ) ;
46
50
}
47
- } ) ;
48
- } ;
51
+ }
52
+ }
53
+
49
54
findFilesRecursive ( dir ) ;
50
55
return files ;
51
56
}
0 commit comments