File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,19 @@ class File {
1313 this . resolver = options . resolver ;
1414 }
1515
16- downloadFile ( callback ) {
16+ parseFileForImport ( content , callback ) {
17+ if ( this . filename . indexOf ( '.sol' ) < 0 ) {
18+ // Only supported in Solidity
19+ return callback ( ) ;
20+ }
21+ const regex = / i m p o r t " ( [ a - z A - Z 0 - 9 _ \- . \\ \/ ] + ) " ; / g;
22+ let matches ;
23+ while ( ( matches = regex . exec ( content ) ) ) {
24+ console . log ( 'Need to download' , matches [ 1 ] ) ;
25+ }
26+ }
27+
28+ downloadFile ( filename , callback ) {
1729 const self = this ;
1830 async . waterfall ( [
1931 function makeTheDir ( next ) {
@@ -41,6 +53,11 @@ class File {
4153 } ,
4254 function readFile ( next ) {
4355 fs . readFile ( self . path , next ) ;
56+ } ,
57+ function parseForImports ( content , next ) {
58+ self . parseFileForImport ( content , ( err ) => {
59+ next ( err , content ) ;
60+ } ) ;
4461 }
4562 ] , ( err , content ) => {
4663 if ( err ) {
Original file line number Diff line number Diff line change 11pragma solidity ^ 0.4.7 ;
22contract SimpleStorage {
33 uint public storedData;
4+ import "ownable.sol " ;
5+ import "ownable2.sol " ;
46
57 function SimpleStorage (uint initialValue ) {
68 storedData = initialValue;
Original file line number Diff line number Diff line change 1+ /*globals describe, it*/
2+ const File = require ( '../lib/core/file' ) ;
3+ const fs = require ( 'fs-extra' ) ;
4+
5+ describe ( 'embark.File' , function ( ) {
6+ describe ( 'parseFileForImport' , ( ) => {
7+ it ( 'should find all the imports' , function ( ) {
8+ const contract = fs . readFileSync ( './test/contracts/simple_storage.sol' ) . toString ( ) ;
9+ const file = new File ( { filename : 'simple_storage.sol' } ) ;
10+ file . parseFileForImport ( contract ) ;
11+ } ) ;
12+ } ) ;
13+ } ) ;
You can’t perform that action at this time.
0 commit comments