11import  path  from  'path' ; 
22import  fs ,  {  readdir  }  from  'node:fs/promises' ; 
3+ import  {  glob ,  globSync ,  globStream ,  globStreamSync ,  Glob  }  from  'glob' ; 
34import  {  join  }  from  'node:path' ; 
45import  {  Smell ,  SmellDetector ,  SupportedLanguages  }  from  'smelly-detector' ; 
56import  {  SmellsAggreagtor ,  SmellsList  }  from  'smelly-detector/reports' ; 
7+ import  {  statSync  }  from  'fs' ; 
68
79const  args  =  process . argv ; 
810const  fileName  =  args [ 2 ] ; 
@@ -11,7 +13,7 @@ const report = args[4];
1113const  reportOutput  =  args [ 5 ] ; 
1214
1315if  ( ! fileName )  { 
14-   console . error ( '[SMELLY] please provide a test file' ) ; 
16+   console . error ( '[SMELLY] please provide a test file or a regex to search for test files ' ) ; 
1517  process . exit ( ) ; 
1618} 
1719
@@ -22,24 +24,23 @@ const walk: any = async (dirPath: string) => Promise.all(
2224  } ) ) 
2325) ; 
2426
25- async   function  execute ( )  { 
27+ function  isDirectorySync ( path :  string ) :  boolean  { 
2628  try  { 
27-     const  isFile  =  await  fs . stat ( fileName ) ; 
28-     if  ( isFile  &&  isFile . isFile ( ) )  { 
29-       const  fileContents  =  await  fs . readFile ( fileName ,  {  encoding : 'utf8'  } ) ; 
30-       const  smellDetector  =  new  SmellDetector ( fileContents ,  language ) ; 
31- 
32-       const  aggregator  =  [ {  fileName,  smells : smellDetector . findAll ( ) . smells ,  language } ] ; 
33-       
34-       const  to  =  path . resolve ( reportOutput . replace ( '--report-output=' ,  '' ) ) ; 
35-       const  report  =  new  SmellsAggreagtor ( aggregator ,  {  to } ) ; 
36-       await  report . build ( ) ; 
29+     const  stats  =  statSync ( path ) ; 
30+     return  stats . isDirectory ( ) ; 
31+   }  catch  ( error )  { 
32+     return  false ; 
33+   } 
34+ } 
3735
38-       console . info ( 'Report HTML generated' ) ; 
36+ async  function  execute ( )  { 
37+   try  { 
38+     if  ( isDirectorySync ( fileName ) )  { 
39+       console . info ( '[SMELLY] please use a regex or a file' ) ; 
3940      return ; 
4041    } 
4142
42-     const  allFiles  =  await  walk ( fileName ) ; 
43+     const  allFiles  =  await  glob ( fileName ) ; 
4344    const  pathWithAllFilesFound  =  allFiles . flat ( Number . POSITIVE_INFINITY ) ; 
4445
4546    if  ( report )  { 
0 commit comments