@@ -17,6 +17,12 @@ import { debugDetailsTable } from './debug'
1717import { handleError , PrettyError } from './errors'
1818import { getWatcher } from './watcher'
1919
20+ function createCliLogger ( options : Pick < CliOptions , 'stdout' > ) {
21+ return options . stdout
22+ ? consola . create ( { stdout : process . stderr } )
23+ : consola
24+ }
25+
2026async function resolveOptions ( options : CliOptions , userConfig : ResolvedConfig ) : Promise < ResolvedCliOptions > {
2127 const resolvedOptions = {
2228 ...options ,
@@ -48,7 +54,9 @@ async function resolveOptions(options: CliOptions, userConfig: ResolvedConfig):
4854 }
4955
5056 if ( resolvedOptions . writeTransformed ) {
51- consola . warn ( `--write-transformed is deprecated, please use ${ yellow ( '--rewrite' ) } instead.` )
57+ createCliLogger ( options ) . warn (
58+ `--write-transformed is deprecated, please use ${ yellow ( '--rewrite' ) } instead.` ,
59+ )
5260 }
5361
5462 return resolvedOptions
@@ -138,24 +146,25 @@ export async function build(_options: CliOptions) {
138146 const fileCache = new Map < string , FileEntryItem [ ] > ( )
139147 const configResult = await initializeConfig ( _options )
140148 const options = await resolveOptions ( _options , configResult . config )
149+ const logger = createCliLogger ( options )
141150 options . ctx = configResult . ctx
142151
143152 if ( options . stdout && options . outFile ) {
144- consola . fatal ( `Cannot use --stdout and --out-file at the same time` )
153+ logger . fatal ( `Cannot use --stdout and --out-file at the same time` )
145154 return
146155 }
147156
148- consola . log ( green ( `UnoCSS v${ version } ` ) )
157+ logger . log ( green ( `UnoCSS v${ version } ` ) )
149158
150159 if ( options . watch )
151- consola . start ( `UnoCSS in watch mode...` )
160+ logger . start ( `UnoCSS in watch mode...` )
152161 else
153- consola . start ( `UnoCSS for production...` )
162+ logger . start ( `UnoCSS for production...` )
154163
155164 await parseEntries ( options , fileCache )
156165
157166 if ( fileCache . size === 0 ) {
158- consola . warn ( 'No files matched the provided patterns.' )
167+ logger . warn ( 'No files matched the provided patterns.' )
159168 return
160169 }
161170
@@ -207,8 +216,8 @@ export async function build(_options: CliOptions) {
207216 watcher . add ( configSources )
208217
209218 if ( type === 'change' )
210- consola . info ( `${ cyan ( basename ( file ) ) } changed, setting new config` )
211- consola . info (
219+ logger . info ( `${ cyan ( basename ( file ) ) } changed, setting new config` )
220+ logger . info (
212221 `Watching for changes in ${
213222 [
214223 ...options . entries . flatMap ( i => i . patterns ) ,
@@ -220,7 +229,7 @@ export async function build(_options: CliOptions) {
220229 }
221230 else {
222231 if ( type === 'change' ) {
223- consola . log ( `${ green ( type ) } ${ dim ( file ) } ` )
232+ logger . log ( `${ green ( type ) } ${ dim ( file ) } ` )
224233 const content = await fs . readFile ( absolutePath , 'utf8' )
225234 const matchedEntry = fileCache . keys ( ) . find ( outfile => outfile === absolutePath )
226235 if ( matchedEntry )
@@ -234,7 +243,7 @@ export async function build(_options: CliOptions) {
234243 }
235244 }
236245 else if ( type === 'unlink' ) {
237- consola . log ( `${ green ( type ) } ${ dim ( file ) } ` )
246+ logger . log ( `${ green ( type ) } ${ dim ( file ) } ` )
238247 for ( const [ , files ] of fileCache . entries ( ) ) {
239248 const index = files . findIndex ( f => f . id === absolutePath )
240249 if ( index !== - 1 ) {
@@ -243,7 +252,7 @@ export async function build(_options: CliOptions) {
243252 }
244253 }
245254 else if ( type === 'add' ) {
246- consola . log ( `${ green ( type ) } ${ dim ( file ) } ` )
255+ logger . log ( `${ green ( type ) } ${ dim ( file ) } ` )
247256 await parseEntries ( options , fileCache )
248257 }
249258 }
0 commit comments