11#!/usr/bin/env node
22
33const fs = require ( 'fs' )
4+ const path = require ( 'path' )
45const postcss = require ( 'postcss' ) ;
56const autoprefixer = require ( 'autoprefixer' ) ;
67const nested = require ( 'postcss-nested' ) ;
@@ -11,9 +12,9 @@ const mediaMinMax = require('postcss-media-minmax');
1112const customMedia = require ( 'postcss-custom-media' ) ;
1213const imports = require ( 'postcss-easy-import' ) ;
1314
14- const src = require ( './src' ) ;
1515const lh = require ( './lib/lh' ) ;
1616const typeScale = require ( './lib/type-scale' ) ;
17+ const use = require ( './lib/use' )
1718
1819const command = {
1920 name : process . argv [ 2 ] ,
@@ -33,16 +34,16 @@ const compile = async src => await postcss()
3334 . use ( autoprefixer ( ) )
3435 . process ( src , { parser : scssSyntax , from : command . input } ) ;
3536
36- const build = ( ) => {
37- compile ( fs . readFileSync ( command . input , 'utf8' ) ) . then ( css => {
38- fs . writeFile ( command . output , css , err => {
37+ const build = ( input , output ) => {
38+ compile ( fs . readFileSync ( input , 'utf8' ) ) . then ( css => {
39+ fs . writeFile ( output , css , err => {
3940 if ( err ) throw err
40- console . log ( `File written: ${ command . output } \nFrom: ${ command . input } ` ) ;
41+ console . log ( `File written: ${ output } \nFrom: ${ input } ` ) ;
4142 } )
4243 } ) ;
4344} ;
4445
45- const watch = async path => {
46+ const watch = path => {
4647 console . log ( `Currently watching for changes in: ${ path } ` ) ;
4748
4849 fs . watch ( path , { recursive : true } , ( eventType , filename ) => {
@@ -53,13 +54,12 @@ const watch = async path => {
5354
5455switch ( command . name ) {
5556 case 'compile' :
56- build ( ) ;
57-
57+ build ( command . input , command . output ) ;
5858 break
59- case 'watch' :
60- build ( ) ;
61- watch ( src ) . catch ( console . error ) ;
6259
60+ case 'watch' :
61+ build ( command . input , command . output ) ;
62+ watch ( path . dirname ( command . input ) ) ;
6363 break
6464
6565 default :
0 commit comments