1
1
#!/usr/bin/env node
2
2
3
3
const fs = require ( 'fs' )
4
+ const path = require ( 'path' )
4
5
const postcss = require ( 'postcss' ) ;
5
6
const autoprefixer = require ( 'autoprefixer' ) ;
6
7
const nested = require ( 'postcss-nested' ) ;
@@ -11,9 +12,9 @@ const mediaMinMax = require('postcss-media-minmax');
11
12
const customMedia = require ( 'postcss-custom-media' ) ;
12
13
const imports = require ( 'postcss-easy-import' ) ;
13
14
14
- const src = require ( './src' ) ;
15
15
const lh = require ( './lib/lh' ) ;
16
16
const typeScale = require ( './lib/type-scale' ) ;
17
+ const use = require ( './lib/use' )
17
18
18
19
const command = {
19
20
name : process . argv [ 2 ] ,
@@ -33,16 +34,16 @@ const compile = async src => await postcss()
33
34
. use ( autoprefixer ( ) )
34
35
. process ( src , { parser : scssSyntax , from : command . input } ) ;
35
36
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 => {
39
40
if ( err ) throw err
40
- console . log ( `File written: ${ command . output } \nFrom: ${ command . input } ` ) ;
41
+ console . log ( `File written: ${ output } \nFrom: ${ input } ` ) ;
41
42
} )
42
43
} ) ;
43
44
} ;
44
45
45
- const watch = async path => {
46
+ const watch = path => {
46
47
console . log ( `Currently watching for changes in: ${ path } ` ) ;
47
48
48
49
fs . watch ( path , { recursive : true } , ( eventType , filename ) => {
@@ -53,13 +54,12 @@ const watch = async path => {
53
54
54
55
switch ( command . name ) {
55
56
case 'compile' :
56
- build ( ) ;
57
-
57
+ build ( command . input , command . output ) ;
58
58
break
59
- case 'watch' :
60
- build ( ) ;
61
- watch ( src ) . catch ( console . error ) ;
62
59
60
+ case 'watch' :
61
+ build ( command . input , command . output ) ;
62
+ watch ( path . dirname ( command . input ) ) ;
63
63
break
64
64
65
65
default :
0 commit comments