@@ -14,26 +14,32 @@ class File {
1414 }
1515
1616 parseFileForImport ( content , callback ) {
17- if ( this . filename . indexOf ( '.sol' ) < 0 ) {
17+ const self = this ;
18+ if ( self . filename . indexOf ( '.sol' ) < 0 ) {
1819 // Only supported in Solidity
1920 return callback ( ) ;
2021 }
2122 const regex = / i m p o r t " ( [ a - z A - Z 0 - 9 _ \- . \\ \/ ] + ) " ; / g;
2223 let matches ;
2324 const filesToDownload = [ ] ;
24- const pathWithoutFile = path . dirname ( this . path ) ;
25+ const pathWithoutFile = path . dirname ( self . path ) ;
2526 while ( ( matches = regex . exec ( content ) ) ) {
26- console . log ( 'Need to download' , matches [ 1 ] ) ;
2727 filesToDownload . push ( {
28- fileRelativePath : matches [ 1 ] ,
29- url : path . join ( pathWithoutFile , matches [ 1 ] )
28+ fileRelativePath : path . join ( path . dirname ( self . filename ) , matches [ 1 ] ) ,
29+ url : ` ${ pathWithoutFile } / ${ matches [ 1 ] } `
3030 } ) ;
3131 }
32- //async.each(filesToDownload, (file))
32+
33+ async . each ( filesToDownload , ( ( fileObj , eachCb ) => {
34+ self . downloadFile ( fileObj . fileRelativePath , fileObj . url , ( _content ) => {
35+ eachCb ( ) ;
36+ } ) ;
37+ } ) , callback ) ;
3338 }
3439
3540 downloadFile ( filename , url , callback ) {
36- // const self = this;
41+ console . log ( 'Downloading:' , filename , 'form' , url ) ;
42+ const self = this ;
3743 async . waterfall ( [
3844 function makeTheDir ( next ) {
3945 fs . mkdirp ( path . dirname ( filename ) , ( err ) => {
@@ -56,12 +62,12 @@ class File {
5662 } ,
5763 function readFile ( next ) {
5864 fs . readFile ( filename , next ) ;
59- } // ,
60- /* function parseForImports(content, next) {
65+ } ,
66+ function parseForImports ( content , next ) {
6167 self . parseFileForImport ( content , ( err ) => {
6268 next ( err , content ) ;
6369 } ) ;
64- }*/
70+ }
6571 ] , ( err , content ) => {
6672 if ( err ) {
6773 console . error ( 'Error while downloading the file' , err ) ;
0 commit comments