@@ -71,7 +71,8 @@ var Promise = require('bluebird'),
7171 characterdevice : [ ] ,
7272 symboliclink : [ ] ,
7373 fifo : [ ] ,
74- socket : [ ]
74+ socket : [ ] ,
75+ ignore : { } ,
7576 } ,
7677
7778 _types = [
@@ -278,11 +279,36 @@ var Promise = require('bluebird'),
278279 return
279280 }
280281 // otherwise every type of file counts.
281- ( index === files . length - 1 ) && ( child . lasts [ parent . level ] = true ) ;
282+ var isLast = index === files . length - 1 ;
283+ isLast && ( child . lasts [ child . level - 1 ] = true ) ;
284+ if ( _testIgnore ( child , _ignores ) ) {
285+ child . ignore = true ;
286+ if ( isLast ) {
287+ var prevIndex = index - 1 ;
288+ while ( prevIndex >= 0 ) {
289+ var prevNode = parent . children [ prevIndex ] ;
290+ if ( prevNode . ignore ) {
291+ prevIndex -- ;
292+ }
293+ else {
294+ prevNode . lasts [ child . level - 1 ] = true ;
295+ break ;
296+ }
297+ }
298+ }
299+ }
282300 parent . children . push ( child ) ;
283301 // for statistics.
284- _stats . all . push ( child ) ;
285- _stats [ type ] . push ( child ) ;
302+ if ( ! child . ignore ) {
303+ _stats . all . push ( child ) ;
304+ _stats [ type ] . push ( child ) ;
305+ }
306+ else {
307+ if ( ! _stats . ignore [ type ] ) {
308+ _stats . ignore [ type ] = [ ] ;
309+ }
310+ _stats . ignore [ type ] . push ( child ) ;
311+ }
286312 if ( type === 'directory' ) {
287313 return appendChildNodes ( child ) ;
288314 }
@@ -350,6 +376,9 @@ var Promise = require('bluebird'),
350376 _normalizeIgnoreFlag ( ignoreFlag [ i ] ) ;
351377 }
352378 }
379+ else if ( flagType ) {
380+ _ignores . push ( ignoreFlag ) ;
381+ }
353382 } ,
354383
355384 // test if parent includes sub
@@ -400,7 +429,7 @@ var Promise = require('bluebird'),
400429 // }
401430 // return al;
402431 // };
403- if ( _testIgnore ( node , _ignores ) ) {
432+ if ( node . ignore ) {
404433 return '' ;
405434 }
406435 if ( node . type === 'symboliclink' && ! _flags . link ) {
@@ -414,20 +443,21 @@ var Promise = require('bluebird'),
414443 } else {
415444 str += _marks . pre_file ;
416445 }
446+ str += ( _flags . fullpath ? node . path : node . name ) ;
417447 if ( node . type !== 'file' ) {
418448 str += _marks [ 'pre_' + node . type ] ;
419449 }
420- str += ( _flags . fullpath ? node . path : node . name ) +
421- _marks . eol ;
450+ str += _marks . eol ;
422451 if ( ! children ) {
423452 return str ;
424453 }
425454 for ( var i = 0 , l = children . length ; i < l ; i ++ ) {
426- ( i === l - 1 ) && ( lastChild = true ) ;
427- str += _stringifyTreeNode ( children [ i ] , lastChild ) ;
455+ // (i === l - 1) && (lastChild = true);
456+ var child = children [ i ] ;
457+ ( child . lasts [ child . level - 1 ] === true ) && ( lastChild = true ) ;
458+ str += _stringifyTreeNode ( child , lastChild ) ;
428459 }
429460 return str ;
430-
431461 } ,
432462
433463 stringifyTree = function ( tree ) {
@@ -455,11 +485,19 @@ var Promise = require('bluebird'),
455485 . then ( function ( ) {
456486 _debug ( 'generated tree:' , JSON . stringify ( _tree , null , 2 ) ) ;
457487 _report = stringifyTree ( _tree ) + _marks . eol ;
488+ var ignoreReport = 'ignored: ' ;
458489 for ( var i = 0 , l = _types . length ; i < l ; i ++ ) {
459- if ( _stats [ _types [ i ] ] && _stats [ _types [ i ] ] . length ) {
460- _report += _types [ i ] + ': ' + _stats [ _types [ i ] ] . length + ' ' ;
490+ var type = _types [ i ] ;
491+ if ( _stats [ type ] && _stats [ type ] . length ) {
492+ _report += type + ': ' + _stats [ type ] . length + ' ' ;
493+ }
494+ var ignores = _stats . ignore [ type ] ;
495+ if ( ignores && ignores . length ) {
496+ ignoreReport += type + ' (' + ignores . length + '), ' ;
461497 }
462498 }
499+ _report = _report . slice ( 0 , - 1 ) + '\n\n' ;
500+ _report += ignoreReport . slice ( 0 , - 2 ) + '\n' ;
463501
464502 if ( ! _flags . noreport && withCli ) {
465503 console . log ( '\n' + _output ( _report ) + '\n' ) ;
0 commit comments