1
+ import chalk from 'chalk' ;
1
2
import { readdir , mkdir , readFile , writeFile } from 'fs' ;
2
3
import * as lightningcss from 'lightningcss' ;
3
4
import { join , dirname , relative } from 'path' ;
@@ -11,6 +12,7 @@ import {fileURLToPath} from 'url';
11
12
const args = argv . slice ( 2 ) ;
12
13
const configArg = args . find ( ( arg ) => arg . startsWith ( '--config=' ) ) ;
13
14
if ( configArg === undefined ) {
15
+ console . error ( chalk . red ( 'Error: Missing --config=[PATH] argument' ) ) ;
14
16
throw new Error ( 'Missing --config=[PATH] argument' ) ;
15
17
}
16
18
const tsConfigPath = configArg . split ( '=' ) [ 1 ] ;
@@ -76,12 +78,16 @@ const pushImports = (currentFile, importPaths, files) => {
76
78
function convertCssToJs ( srcPath , distPath , file ) {
77
79
readFile ( srcPath , 'utf8' , async ( err , data ) => {
78
80
if ( err ) {
81
+ console . error ( chalk . red ( `Error reading file: ${ srcPath } ` ) ) ;
79
82
throw err ;
80
83
}
81
84
82
85
const files = [ file ] ;
83
86
84
- console . log ( `Processing ${ srcPath } -> ${ distPath } ` ) ;
87
+ console . log (
88
+ chalk . blue ( 'Processing:' ) ,
89
+ chalk . green ( `${ srcPath } -> ${ distPath } ` )
90
+ ) ;
85
91
const imports = Array . from ( data . matchAll ( importMatcher ) ) . flatMap (
86
92
( match ) => match
87
93
) ;
@@ -112,31 +118,35 @@ function convertCssToJs(srcPath, distPath, file) {
112
118
113
119
writeFile ( jsPath , fileContent , ( err ) => {
114
120
if ( err ) {
121
+ console . error ( chalk . red ( `Error writing file: ${ jsPath } ` ) ) ;
115
122
throw err ;
116
123
}
124
+ console . log ( chalk . blue ( 'Successfully processed:' ) , chalk . green ( jsPath ) ) ;
117
125
} ) ;
118
126
} ) ;
119
127
}
120
-
121
128
function processCssFiles ( srcDir , distDir ) {
122
129
readdir ( srcDir , { withFileTypes : true } , ( err , files ) => {
123
130
if ( err ) {
131
+ console . error ( chalk . red ( `Error reading directory: ${ srcDir } ` ) ) ;
124
132
throw err ;
125
133
}
126
134
127
135
files . forEach ( ( file ) => {
128
136
const srcPath = join ( srcDir , file . name ) ;
129
137
130
138
if ( file . isDirectory ( ) ) {
139
+ console . log ( chalk . blue ( 'Entering directory:' ) , chalk . green ( srcPath ) ) ;
131
140
processCssFiles ( srcPath , join ( distDir , file . name ) ) ;
132
141
} else if ( file . isFile ( ) && file . name . endsWith ( '.css' ) ) {
133
142
const relPath = relative ( srcDir , srcPath ) ;
134
143
const distPath = join ( distDir , relPath ) ;
135
144
const targetDir = dirname ( distPath ) ;
136
- console . log ( ` Processing CSS for ${ srcPath } ` ) ;
145
+ console . log ( chalk . blue ( ' Processing CSS for:' ) , chalk . green ( srcPath ) ) ;
137
146
138
147
mkdir ( targetDir , { recursive : true } , ( err ) => {
139
148
if ( err ) {
149
+ console . error ( chalk . red ( `Error creating directory: ${ targetDir } ` ) ) ;
140
150
throw err ;
141
151
}
142
152
convertCssToJs ( srcPath , distPath , file ) ;
0 commit comments