base code for import parse

This commit is contained in:
Jonathan Rainville 2018-04-18 16:32:51 -04:00
parent e1a9023bb2
commit 6c5415b27f
3 changed files with 33 additions and 1 deletions

View File

@ -13,7 +13,19 @@ class File {
this.resolver = options.resolver;
}
downloadFile (callback) {
parseFileForImport(content, callback) {
if (this.filename.indexOf('.sol') < 0) {
// Only supported in Solidity
return callback();
}
const regex = /import "([a-zA-Z0-9_\-.\\\/]+)";/g;
let matches;
while ((matches = regex.exec(content))) {
console.log('Need to download', matches[1]);
}
}
downloadFile (filename, callback) {
const self = this;
async.waterfall([
function makeTheDir(next) {
@ -41,6 +53,11 @@ class File {
},
function readFile(next) {
fs.readFile(self.path, next);
},
function parseForImports(content, next) {
self.parseFileForImport(content, (err) => {
next(err, content);
});
}
], (err, content) => {
if (err) {

View File

@ -1,6 +1,8 @@
pragma solidity ^0.4.7;
contract SimpleStorage {
uint public storedData;
import "ownable.sol";
import "ownable2.sol";
function SimpleStorage(uint initialValue) {
storedData = initialValue;

13
test/file.js Normal file
View File

@ -0,0 +1,13 @@
/*globals describe, it*/
const File = require('../lib/core/file');
const fs = require('fs-extra');
describe('embark.File', function () {
describe('parseFileForImport', () => {
it('should find all the imports', function () {
const contract = fs.readFileSync('./test/contracts/simple_storage.sol').toString();
const file = new File({filename: 'simple_storage.sol'});
file.parseFileForImport(contract);
});
});
});