@@ -50,6 +50,21 @@ 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 ( 'readable' , ( ) => {
57
+ let chunk
58
+ while ( ( chunk = process . stdin . read ( ) ) !== null ) {
59
+ result += chunk
60
+ }
61
+ } )
62
+
63
+ process . stdin . on ( 'end' , ( ) => resolve ( result ) )
64
+ process . stdin . on ( 'error' , ( err ) => reject ( err ) )
65
+ } )
66
+ }
67
+
53
68
function help ( { message, usage, commands, options } ) {
54
69
let indent = 2
55
70
@@ -558,9 +573,21 @@ async function build() {
558
573
} )
559
574
}
560
575
561
- let css = input
562
- ? fs . readFileSync ( path . resolve ( input ) , 'utf8' )
563
- : '@tailwind base; @tailwind components; @tailwind utilities'
576
+ let css = await ( async ( ) => {
577
+ // Input file has been provided
578
+ if ( input ) {
579
+ fs . readFileSync ( path . resolve ( input ) , 'utf8' )
580
+ }
581
+
582
+ // Piping in data, let's drain the stdin
583
+ if ( ! process . stdin . isTTY ) {
584
+ return await drainStdin ( )
585
+ }
586
+
587
+ // No input file provided, fallback to default atrules
588
+ return '@tailwind base; @tailwind components; @tailwind utilities'
589
+ } ) ( )
590
+
564
591
return processCSS ( css )
565
592
}
566
593
@@ -694,9 +721,21 @@ async function build() {
694
721
} )
695
722
}
696
723
697
- let css = input
698
- ? fs . readFileSync ( path . resolve ( input ) , 'utf8' )
699
- : '@tailwind base; @tailwind components; @tailwind utilities'
724
+ let css = await ( async ( ) => {
725
+ // Input file has been provided
726
+ if ( input ) {
727
+ fs . readFileSync ( path . resolve ( input ) , 'utf8' )
728
+ }
729
+
730
+ // Piping in data, let's drain the stdin
731
+ if ( ! process . stdin . isTTY ) {
732
+ return await drainStdin ( )
733
+ }
734
+
735
+ // No input file provided, fallback to default atrules
736
+ return '@tailwind base; @tailwind components; @tailwind utilities'
737
+ } ) ( )
738
+
700
739
let result = await processCSS ( css )
701
740
env . DEBUG && console . timeEnd ( 'Finished in' )
702
741
return result
0 commit comments