@@ -139,7 +139,7 @@ function getEmitter() {
139139 */
140140
141141function getOptions ( args , options ) {
142- options . src = options . watch ? options . watch : args [ 0 ] ;
142+ options . src = args [ 0 ] || options . watch ;
143143
144144 if ( args [ 1 ] ) {
145145 options . dest = path . resolve ( process . cwd ( ) , args [ 1 ] ) ;
@@ -161,25 +161,30 @@ function getOptions(args, options) {
161161 */
162162
163163function watch ( options , emitter ) {
164- var dir = options . watch ;
165- var gaze = new Gaze ( ) ;
164+ var watchDir = isSassFile ( options . watch ) ? path . dirname ( path . resolve ( options . watch ) ) : options . watch ,
165+ glob = options . recursive ? '**/*.{sass,scss}' : '*.{sass,scss}' ,
166+ gaze = new Gaze ( ) ,
167+ dir ;
166168
167- if ( dir === true ) {
169+ if ( watchDir === true ) {
168170 dir = [ ] ;
169- } else if ( ! Array . isArray ( dir ) ) {
170- dir = [ dir ] ;
171+ } else if ( ! Array . isArray ( watchDir ) ) {
172+ dir = [ watchDir ] ;
171173 }
172174
173- dir . push ( options . src ) ;
175+ // only add the src file if it is not already
176+ // in the array as the watch path
177+ if ( options . watch !== options . src ) {
178+ dir . push ( options . src ) ;
179+ }
174180 dir = dir . map ( function ( d ) {
175- var glob = options . recursive ? '**/*.{sass,scss}' : '*.{sass,scss}' ;
176181 return isSassFile ( d ) ? d : path . join ( d , glob ) ;
177182 } ) ;
178183
179184 gaze . add ( dir ) ;
180185 gaze . on ( 'error' , emitter . emit . bind ( emitter , 'error' ) ) ;
181186
182- var graph = grapher . parseDir ( options . src , { loadPaths : options . includePath } ) ;
187+ var graph = grapher . parseDir ( watchDir , { loadPaths : options . includePath } ) ;
183188
184189 gaze . on ( 'changed' , function ( file ) {
185190 var files = [ file ] ;
0 commit comments