1
1
import autoprefixer from 'autoprefixer'
2
2
import bytes from 'bytes'
3
3
import chalk from 'chalk'
4
- import postcss from 'postcss'
5
4
import prettyHrtime from 'pretty-hrtime'
6
5
7
6
import tailwind from '../..'
8
7
9
8
import commands from '.'
9
+ import compile from '../compile'
10
10
import * as emoji from '../emoji'
11
11
import * as utils from '../utils'
12
12
@@ -57,68 +57,37 @@ function stopWithHelp(...msgs) {
57
57
utils . die ( )
58
58
}
59
59
60
- /**
61
- * Compiles CSS file.
62
- *
63
- * @param {string } inputFile
64
- * @param {string } configFile
65
- * @param {string } outputFile
66
- * @param {boolean } autoprefix
67
- * @return {Promise }
68
- */
69
- function build ( inputFile , configFile , outputFile , autoprefix ) {
70
- const css = utils . readFile ( inputFile )
71
-
72
- return new Promise ( ( resolve , reject ) => {
73
- postcss ( [ tailwind ( configFile ) ] . concat ( autoprefix ? [ autoprefixer ] : [ ] ) )
74
- . process ( css , {
75
- from : inputFile ,
76
- to : outputFile ,
77
- } )
78
- . then ( resolve )
79
- . catch ( reject )
80
- } )
81
- }
82
-
83
60
/**
84
61
* Compiles CSS file and writes it to stdout.
85
62
*
86
- * @param {string } inputFile
87
- * @param {string } configFile
88
- * @param {string } outputFile
89
- * @param {boolean } autoprefix
63
+ * @param {CompileOptions } compileOptions
90
64
* @return {Promise }
91
65
*/
92
- function buildToStdout ( inputFile , configFile , outputFile , autoprefix ) {
93
- return build ( inputFile , configFile , outputFile , autoprefix ) . then ( result =>
94
- process . stdout . write ( result . css )
95
- )
66
+ function buildToStdout ( compileOptions ) {
67
+ return compile ( compileOptions ) . then ( result => process . stdout . write ( result . css ) )
96
68
}
97
69
98
70
/**
99
71
* Compiles CSS file and writes it to a file.
100
72
*
101
- * @param {string } inputFile
102
- * @param {string } configFile
103
- * @param {string } outputFile
104
- * @param {boolean } autoprefix
73
+ * @param {CompileOptions } compileOptions
105
74
* @param {int[] } startTime
106
75
* @return {Promise }
107
76
*/
108
- function buildToFile ( inputFile , configFile , outputFile , autoprefix , startTime ) {
77
+ function buildToFile ( compileOptions , startTime ) {
109
78
utils . header ( )
110
79
utils . log ( )
111
- utils . log ( emoji . go , 'Building...' , chalk . bold . cyan ( inputFile ) )
80
+ utils . log ( emoji . go , 'Building...' , chalk . bold . cyan ( compileOptions . inputFile ) )
112
81
113
- return build ( inputFile , configFile , outputFile , autoprefix ) . then ( result => {
114
- utils . writeFile ( outputFile , result . css )
82
+ return compile ( compileOptions ) . then ( result => {
83
+ utils . writeFile ( compileOptions . outputFile , result . css )
115
84
116
85
const prettyTime = prettyHrtime ( process . hrtime ( startTime ) )
117
86
118
87
utils . log ( )
119
88
utils . log ( emoji . yes , 'Finished in' , chalk . bold . magenta ( prettyTime ) )
120
89
utils . log ( emoji . pack , 'Size:' , chalk . bold . magenta ( bytes ( result . css . length ) ) )
121
- utils . log ( emoji . disk , 'Saved to' , chalk . bold . cyan ( outputFile ) )
90
+ utils . log ( emoji . disk , 'Saved to' , chalk . bold . cyan ( compileOptions . outputFile ) )
122
91
utils . footer ( )
123
92
} )
124
93
}
@@ -145,9 +114,15 @@ export function run(cliParams, cliOptions) {
145
114
! utils . exists ( configFile ) &&
146
115
stop ( chalk . bold . magenta ( configFile ) , 'does not exist.' )
147
116
117
+ const compileOptions = {
118
+ inputFile,
119
+ outputFile,
120
+ plugins : [ tailwind ( configFile ) ] . concat ( autoprefix ? [ autoprefixer ] : [ ] ) ,
121
+ }
122
+
148
123
const buildPromise = outputFile
149
- ? buildToFile ( inputFile , configFile , outputFile , autoprefix , startTime )
150
- : buildToStdout ( inputFile , configFile , outputFile , autoprefix )
124
+ ? buildToFile ( compileOptions , startTime )
125
+ : buildToStdout ( compileOptions )
151
126
152
127
buildPromise . then ( resolve ) . catch ( reject )
153
128
} )
0 commit comments