@@ -15,25 +15,16 @@ function transpileCommand(patterns, options) {
1515 if ( ! Array . isArray ( patterns ) || typeof options !== 'object' ) {
1616 throw new Error ( "Invalid input: `patterns` should be an array and `options` should be an object." ) ;
1717 }
18-
19- const config = loadConfig ( options . config ) ;
2018
21- const finalPatterns =
22- patterns . length > 0 ? patterns : config . patterns || [ "**/*.js" ] ;
23- let excludePatterns = options . exclude || config . exclude || [ ] ;
24- if ( typeof excludePatterns === "string" ) {
25- excludePatterns = [ excludePatterns ] ; // Convert to array if needed
26- }
27- if ( excludePatterns . length > 0 ) {
28- logMessage (
29- "info" ,
30- `Excluding patterns: ${ excludePatterns . join ( ", " ) } ` ,
31- options . silent
32- ) ;
19+ const config = loadConfig ( options . config ) ;
20+ const finalPatterns = patterns . length ? patterns : config . patterns || [ "**/*.js" ] ;
21+ let excludePatterns = Array . isArray ( options . exclude ) ? options . exclude : [ options . exclude || config . exclude || [ ] ] . flat ( ) ;
22+
23+ if ( excludePatterns . length ) {
24+ logMessage ( "info" , `Excluding patterns: ${ excludePatterns . join ( ", " ) } ` , options . silent ) ;
3325 }
3426
35- const outputDir = options . output || config . output || "dist" ; // Load from config or use default
36-
27+ const outputDir = options . output || config . output || "dist" ;
3728 const isSilent = options . silent ?? config . silent ;
3829 const isVerbose = options . verbose ?? config . verbose ;
3930
@@ -44,56 +35,29 @@ function transpileCommand(patterns, options) {
4435 logMessage ( "info" , "Starting transpilation process..." , isSilent ) ;
4536
4637 try {
47- const files = glob . sync ( finalPatterns . join ( "|" ) , {
48- ignore : excludePatterns ,
49- nodir : true ,
50- } ) ;
38+ const files = glob . sync ( finalPatterns . join ( "|" ) , { ignore : excludePatterns , nodir : true } ) ;
5139
52- if ( files . length === 0 ) {
40+ if ( ! files . length ) {
5341 logMessage ( "warn" , "No files matched for transpilation." , isSilent ) ;
5442 return ;
5543 }
5644
5745 logMessage ( "info" , `Processing ${ files . length } files...` , isSilent ) ;
5846
59- for ( const file of files ) {
47+ files . forEach ( file => {
6048 logMessage ( "info" , `Transpiling: ${ file } ` , isSilent ) ;
6149
6250 try {
63- logMessage (
64- "debug" ,
65- `Source file dirname: ${ path . dirname ( file ) } ` ,
66- isSilent
67- ) ;
68- const destinationFile = path . join (
69- outputDir ,
70- path . dirname ( file ) ,
71- path . basename ( file )
72- ) ;
73- logMessage ( "debug" , `Destination file: ${ destinationFile } ` , isSilent ) ;
74- logMessage (
75- "debug" ,
76- `Destination file dirname: ${ path . dirname ( destinationFile ) } ` ,
77- isSilent
78- ) ;
51+ const destinationFile = path . join ( outputDir , path . dirname ( file ) , path . basename ( file ) ) ;
7952 if ( ! fs . existsSync ( path . dirname ( destinationFile ) ) ) {
80- fs . mkdirSync ( path . dirname ( destinationFile ) , { recursive : true } ) ; // Ensure output directory exists
53+ fs . mkdirSync ( path . dirname ( destinationFile ) , { recursive : true } ) ;
8154 }
82- fs . copyFileSync ( file , destinationFile ) ; // Save transpiled file to output folder
83- logMessage (
84- "info" ,
85- `Successfully transpiled: ${ file } -> ${ destinationFile } ` ,
86- isSilent
87- ) ;
55+ fs . copyFileSync ( file , destinationFile ) ;
56+ logMessage ( "info" , `Successfully transpiled: ${ file } -> ${ destinationFile } ` , isSilent ) ;
8857 } catch ( error ) {
89- logMessage (
90- "error" ,
91- `Failed to transpile ${ file } : ${ error . message } ` ,
92- isSilent
93- ) ;
94- continue ; // Skip to the next file on error
58+ logMessage ( "error" , `Failed to transpile ${ file } : ${ error . message } ` , isSilent ) ;
9559 }
96- }
60+ } ) ;
9761
9862 logMessage ( "info" , "Transpilation process completed!" , isSilent ) ;
9963 } catch ( error ) {
0 commit comments