@@ -11,6 +11,7 @@ const mediaMinMax = require('postcss-media-minmax');
11
11
const customMedia = require ( 'postcss-custom-media' ) ;
12
12
const imports = require ( 'postcss-easy-import' ) ;
13
13
14
+ const src = require ( './src' ) ;
14
15
const lh = require ( './lib/lh' ) ;
15
16
const typeScale = require ( './lib/type-scale' ) ;
16
17
@@ -32,16 +33,35 @@ const compile = async src => await postcss()
32
33
. use ( autoprefixer ( ) )
33
34
. process ( src , { parser : scssSyntax , from : command . input } ) ;
34
35
36
+ const build = ( ) => {
37
+ compile ( fs . readFileSync ( command . input , 'utf8' ) ) . then ( css => {
38
+ fs . writeFile ( command . output , css , err => {
39
+ if ( err ) throw err
40
+ console . log ( `File written: ${ command . output } \nFrom: ${ command . input } ` ) ;
41
+ } )
42
+ } ) ;
43
+ } ;
44
+
45
+ const watch = async path => {
46
+ console . log ( `Currently watching for changes in: ${ path } ` ) ;
47
+
48
+ fs . watch ( path , { recursive : true } , ( eventType , filename ) => {
49
+ console . log ( `${ eventType . charAt ( 0 ) . toUpperCase ( ) + eventType . slice ( 1 ) } in: ${ filename } ` ) ;
50
+ build ( ) ;
51
+ } ) ;
52
+ } ;
35
53
36
54
switch ( command . name ) {
37
55
case 'compile' :
38
- compile ( fs . readFileSync ( command . input , 'utf8' ) ) . then ( css => {
39
- fs . writeFile ( command . output , css , err => {
40
- if ( err ) throw err
41
- console . log ( `File written: ${ command . output } \nFrom: ${ command . input } ` ) ;
42
- } )
43
- } )
56
+ build ( ) ;
57
+
44
58
break
59
+ case 'watch' :
60
+ build ( ) ;
61
+ watch ( src ) . catch ( console . error ) ;
62
+
63
+ break
64
+
45
65
default :
46
66
console . log ( 'Unknown command' )
47
67
break
0 commit comments