@@ -50,6 +50,17 @@ async function outputFile(file, contents) {
50
50
await fs . promises . writeFile ( file , contents , 'utf8' )
51
51
}
52
52
53
+ function drainStdin ( ) {
54
+ return new Promise ( ( resolve , reject ) => {
55
+ let result = ''
56
+ process . stdin . on ( 'data' , ( chunk ) => {
57
+ result += chunk
58
+ } )
59
+ process . stdin . on ( 'end' , ( ) => resolve ( result ) )
60
+ process . stdin . on ( 'error' , ( err ) => reject ( err ) )
61
+ } )
62
+ }
63
+
53
64
function help ( { message, usage, commands, options } ) {
54
65
let indent = 2
55
66
@@ -364,7 +375,7 @@ async function build() {
364
375
input = args [ '--input' ] = args [ '_' ] [ 1 ]
365
376
}
366
377
367
- if ( input && ! fs . existsSync ( ( input = path . resolve ( input ) ) ) ) {
378
+ if ( input && input !== '-' && ! fs . existsSync ( ( input = path . resolve ( input ) ) ) ) {
368
379
console . error ( `Specified input file ${ args [ '--input' ] } does not exist.` )
369
380
process . exit ( 9 )
370
381
}
@@ -558,9 +569,21 @@ async function build() {
558
569
} )
559
570
}
560
571
561
- let css = input
562
- ? fs . readFileSync ( path . resolve ( input ) , 'utf8' )
563
- : '@tailwind base; @tailwind components; @tailwind utilities'
572
+ let css = await ( ( ) => {
573
+ // Piping in data, let's drain the stdin
574
+ if ( input === '-' ) {
575
+ return drainStdin ( )
576
+ }
577
+
578
+ // Input file has been provided
579
+ if ( input ) {
580
+ return fs . readFileSync ( path . resolve ( input ) , 'utf8' )
581
+ }
582
+
583
+ // No input file provided, fallback to default atrules
584
+ return '@tailwind base; @tailwind components; @tailwind utilities'
585
+ } ) ( )
586
+
564
587
return processCSS ( css )
565
588
}
566
589
@@ -694,9 +717,21 @@ async function build() {
694
717
} )
695
718
}
696
719
697
- let css = input
698
- ? fs . readFileSync ( path . resolve ( input ) , 'utf8' )
699
- : '@tailwind base; @tailwind components; @tailwind utilities'
720
+ let css = await ( ( ) => {
721
+ // Piping in data, let's drain the stdin
722
+ if ( input === '-' ) {
723
+ return drainStdin ( )
724
+ }
725
+
726
+ // Input file has been provided
727
+ if ( input ) {
728
+ return fs . readFileSync ( path . resolve ( input ) , 'utf8' )
729
+ }
730
+
731
+ // No input file provided, fallback to default atrules
732
+ return '@tailwind base; @tailwind components; @tailwind utilities'
733
+ } ) ( )
734
+
700
735
let result = await processCSS ( css )
701
736
env . DEBUG && console . timeEnd ( 'Finished in' )
702
737
return result
0 commit comments