@@ -30,8 +30,14 @@ var argv = require("yargs")
3030 . describe ( 's' , 'Alternative input syntax parser' )
3131 . alias ( 'p' , 'parser' )
3232 . describe ( 'p' , 'Alternative CSS parser' )
33+ . option ( 'poll' , {
34+ describe : 'Use polling to monitor for changes.' ,
35+ default : false ,
36+ } )
3337 . alias ( 't' , 'stringifier' )
3438 . describe ( 't' , 'Alternative output stringifier' )
39+ . alias ( 'l' , 'log' )
40+ . describe ( 'l' , 'Log when file is written' )
3541 . alias ( 'w' , 'watch' )
3642 . describe ( 'w' , 'auto-recompile when detecting source changes' )
3743 . requiresArg ( [ 'u' , 'c' , 'i' , 'o' , 'd' , 's' , 'p' , 't' ] )
@@ -40,14 +46,11 @@ var argv = require("yargs")
4046 'postcss version' ,
4147 require ( './node_modules/postcss/package.json' ) . version
4248 ] . join ( ' ' ) ;
43- } , 'v' )
49+ } )
4450 . alias ( 'v' , 'version' )
4551 . help ( 'h' )
4652 . alias ( 'h' , 'help' )
4753 . check ( function ( argv ) {
48- if ( ! argv . use ) {
49- throw 'Please specify at least one plugin name.' ;
50- }
5154 if ( argv . _ . length && argv . input ) {
5255 throw 'Both positional arguments and --input option used for `input file`: please only use one of them.' ;
5356 }
@@ -100,8 +103,13 @@ var plugins = argv.use.map(function(name) {
100103 if ( local ) {
101104 var resolved = resolve . sync ( name , { basedir : process . cwd ( ) } ) ;
102105 plugin = require ( resolved ) ;
103- } else {
106+ } else if ( name ) {
104107 plugin = require ( name ) ;
108+ } else {
109+ return null ;
110+ }
111+ if ( plugin . default && typeof plugin . default === 'function' ) {
112+ plugin = plugin . default ;
105113 }
106114 if ( name in argv ) {
107115 plugin = plugin ( argv [ name ] ) ;
@@ -132,7 +140,7 @@ var path = require('path');
132140var readFile = require ( 'read-file-stdin' ) ;
133141var path = require ( 'path' ) ;
134142var postcss = require ( 'postcss' ) ;
135- var processor = postcss ( plugins ) ;
143+ var processor = plugins [ 0 ] ? postcss ( plugins ) : postcss ( ) ;
136144var mkdirp = require ( 'mkdirp' ) ;
137145
138146// hook for dynamically updating the list of watched files
@@ -146,8 +154,16 @@ async.forEach(inputFiles, compile, onError);
146154function fsWatcher ( entryPoints ) {
147155 var watchedFiles = entryPoints ;
148156 var index = { } ; // source files by entry point
157+ var opts = { } ;
149158
150- var watcher = require ( 'chokidar' ) . watch ( watchedFiles ) ;
159+ if ( argv . poll ) {
160+ opts . usePolling = true ;
161+ }
162+ if ( typeof argv . poll === 'number' ) {
163+ opts . interval = argv . poll ;
164+ }
165+
166+ var watcher = require ( 'chokidar' ) . watch ( watchedFiles , opts ) ;
151167 // recompile if any watched file is modified
152168 // TODO: only recompile relevant entry point
153169 watcher . on ( 'change' , function ( ) {
@@ -255,6 +271,10 @@ function writeFile(name, content, fn) {
255271 fn ( err ) ;
256272 } else {
257273 fs . writeFile ( name , content , fn ) ;
274+
275+ if ( argv . log ) {
276+ console . log ( 'Generated file: ' + name ) ;
277+ }
258278 }
259279 } ) ;
260280}
0 commit comments