@@ -4,10 +4,11 @@ import chalk from 'chalk'
44import postcss from 'postcss'
55import prettyHrtime from 'pretty-hrtime'
66
7- import commands from '.'
8- import emoji from '../emoji'
97import tailwind from '../..'
10- import { die , error , exists , footer , header , log , readFile , writeFile } from '../utils'
8+
9+ import commands from '.'
10+ import * as emoji from '../emoji'
11+ import * as utils from '../utils'
1112
1213export const usage = 'build <file> [options]'
1314export const description = 'Compiles Tailwind CSS file.'
@@ -34,9 +35,9 @@ export const optionMap = {
3435 * @param {...string } [msgs]
3536 */
3637function stop ( ...msgs ) {
37- header ( )
38- error ( ...msgs )
39- die ( )
38+ utils . header ( )
39+ utils . error ( ...msgs )
40+ utils . die ( )
4041}
4142
4243/**
@@ -45,10 +46,10 @@ function stop(...msgs) {
4546 * @param {...string } [msgs]
4647 */
4748function stopWithHelp ( ...msgs ) {
48- header ( )
49- error ( ...msgs )
49+ utils . header ( )
50+ utils . error ( ...msgs )
5051 commands . help . forCommand ( commands . build )
51- die ( )
52+ utils . die ( )
5253}
5354
5455/**
@@ -60,7 +61,7 @@ function stopWithHelp(...msgs) {
6061 * @return {Promise }
6162 */
6263function build ( inputFile , configFile , outputFile ) {
63- const css = readFile ( inputFile )
64+ const css = utils . readFile ( inputFile )
6465
6566 return new Promise ( ( resolve , reject ) => {
6667 postcss ( [ tailwind ( configFile ) , autoprefixer ] )
@@ -95,20 +96,20 @@ function buildToStdout(inputFile, configFile, outputFile) {
9596 * @return {Promise }
9697 */
9798function buildToFile ( inputFile , configFile , outputFile , startTime ) {
98- header ( )
99- log ( )
100- log ( emoji . go , 'Building...' , chalk . bold . cyan ( inputFile ) )
99+ utils . header ( )
100+ utils . log ( )
101+ utils . log ( emoji . go , 'Building...' , chalk . bold . cyan ( inputFile ) )
101102
102103 return build ( inputFile , configFile , outputFile ) . then ( result => {
103- writeFile ( outputFile , result . css )
104+ utils . writeFile ( outputFile , result . css )
104105
105106 const prettyTime = prettyHrtime ( process . hrtime ( startTime ) )
106107
107- log ( )
108- log ( emoji . yes , 'Finished in' , chalk . bold . magenta ( prettyTime ) )
109- log ( emoji . pack , 'Size:' , chalk . bold . magenta ( bytes ( result . css . length ) ) )
110- log ( emoji . disk , 'Saved to' , chalk . bold . cyan ( outputFile ) )
111- footer ( )
108+ utils . log ( )
109+ utils . log ( emoji . yes , 'Finished in' , chalk . bold . magenta ( prettyTime ) )
110+ utils . log ( emoji . pack , 'Size:' , chalk . bold . magenta ( bytes ( result . css . length ) ) )
111+ utils . log ( emoji . disk , 'Saved to' , chalk . bold . cyan ( outputFile ) )
112+ utils . footer ( )
112113 } )
113114}
114115
@@ -127,13 +128,16 @@ export function run(cliParams, cliOptions) {
127128 const outputFile = cliOptions . output && cliOptions . output [ 0 ]
128129
129130 ! inputFile && stopWithHelp ( 'CSS file is required.' )
130- ! exists ( inputFile ) && stop ( chalk . bold . magenta ( inputFile ) , 'does not exist.' )
131- configFile && ! exists ( configFile ) && stop ( chalk . bold . magenta ( configFile ) , 'does not exist.' )
131+ ! utils . exists ( inputFile ) && stop ( chalk . bold . magenta ( inputFile ) , 'does not exist.' )
132+
133+ configFile &&
134+ ! utils . exists ( configFile ) &&
135+ stop ( chalk . bold . magenta ( configFile ) , 'does not exist.' )
132136
133- const promise = outputFile
137+ const buildPromise = outputFile
134138 ? buildToFile ( inputFile , configFile , outputFile , startTime )
135139 : buildToStdout ( inputFile , configFile , outputFile )
136140
137- promise . then ( resolve ) . catch ( reject )
141+ buildPromise . then ( resolve ) . catch ( reject )
138142 } )
139143}
0 commit comments