@@ -6,7 +6,6 @@ var MetadataContainer = require('./metadata-container');
66var Git = require ( './git' ) ;
77var Utils = require ( './utils' ) ;
88var path = require ( 'path' ) ;
9- var miss = require ( 'mississippi' ) ;
109
1110var Diff = module . exports = function ( data ) {
1211 this . data = data ;
@@ -56,52 +55,44 @@ Diff.prototype.getMetadataContainers = function(opts) {
5655 } ;
5756} ;
5857
59- Diff . stream = function ( opts ) {
58+ Diff . parse = function ( diff , opts ) {
6059 var git = new Git ( process . cwd ( ) ) ;
6160 var unpackagedPath = path . join ( process . cwd ( ) , 'src' ) ;
6261 opts = opts || { } ;
63-
64- return miss . through . obj ( function ( diff , enc , cb ) {
65- var files = parseDiff ( diff . toString ( ) ) ;
66-
67- if ( files . length <= 0 ) return cb ( ) ;
68-
69- var containerFrom = new MetadataContainer ( ) ;
70- var containerTo = new MetadataContainer ( ) ;
71- files . forEach ( function ( file ) {
72- if ( Utils . isValidFilename ( file . from ) || Utils . isValidFilename ( file . to ) || Utils . isValidMetaFilename ( file . from ) || Utils . isValidMetaFilename ( file . to ) ) {
73- var fileFrom = MetadataFileFactory . createInstance ( {
74- path : file . from === '/dev/null' ? file . from : path . relative ( unpackagedPath , file . from ) ,
75- contents : Buffer . from ( "" ) ,
76- ignoreWhitespace : opts . ignoreWhitespace ,
77- fileFrom : true
78- } ) ;
79- var fileTo = MetadataFileFactory . createInstance ( {
80- path : file . to === '/dev/null' ? file . to : path . relative ( unpackagedPath , file . to ) ,
81- contents : Buffer . from ( "" ) ,
82- ignoreWhitespace : opts . ignoreWhitespace ,
83- fileTo : true
84- } ) ;
85- if ( file . index && file . index . length ) {
86- // retrieve file using git
87- var parts = file . index [ 0 ] . split ( '..' ) ;
88- if ( ! file . new ) {
89- fileFrom . contents = git . show ( parts [ 0 ] ) ;
90- }
91- if ( ! file . deleted ) {
92- fileTo . contents = git . show ( parts [ 1 ] ) ;
93- }
62+ var files = parseDiff ( diff . toString ( ) ) ;
63+ var containerFrom = new MetadataContainer ( ) ;
64+ var containerTo = new MetadataContainer ( ) ;
65+ files . forEach ( function ( file ) {
66+ if ( Utils . isValidFilename ( file . from ) || Utils . isValidFilename ( file . to ) || Utils . isValidMetaFilename ( file . from ) || Utils . isValidMetaFilename ( file . to ) ) {
67+ var fileFrom = MetadataFileFactory . createInstance ( {
68+ path : file . from === '/dev/null' ? file . from : path . relative ( unpackagedPath , file . from ) ,
69+ contents : Buffer . from ( "" ) ,
70+ ignoreWhitespace : opts . ignoreWhitespace ,
71+ fileFrom : true
72+ } ) ;
73+ var fileTo = MetadataFileFactory . createInstance ( {
74+ path : file . to === '/dev/null' ? file . to : path . relative ( unpackagedPath , file . to ) ,
75+ contents : Buffer . from ( "" ) ,
76+ ignoreWhitespace : opts . ignoreWhitespace ,
77+ fileTo : true
78+ } ) ;
79+ if ( file . index && file . index . length ) {
80+ // retrieve file using git
81+ var parts = file . index [ 0 ] . split ( '..' ) ;
82+ if ( ! file . new ) {
83+ fileFrom . contents = git . show ( parts [ 0 ] ) ;
84+ }
85+ if ( ! file . deleted ) {
86+ fileTo . contents = git . show ( parts [ 1 ] ) ;
9487 }
95- containerFrom . add ( fileFrom , [ ] ) ;
96- containerTo . add ( fileTo , [ ] ) ;
97-
9888 }
99- } ) ;
100-
101- cb ( null , {
102- source : containerFrom ,
103- target : containerTo
104- } ) ;
105-
89+ containerFrom . add ( fileFrom , [ ] ) ;
90+ containerTo . add ( fileTo , [ ] ) ;
91+ }
10692 } ) ;
93+
94+ return {
95+ source : containerFrom ,
96+ target : containerTo
97+ } ;
10798}
0 commit comments