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; 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; const self = this;
async.waterfall([ async.waterfall([
function makeTheDir(next) { function makeTheDir(next) {
@ -41,6 +53,11 @@ class File {
}, },
function readFile(next) { function readFile(next) {
fs.readFile(self.path, next); fs.readFile(self.path, next);
},
function parseForImports(content, next) {
self.parseFileForImport(content, (err) => {
next(err, content);
});
} }
], (err, content) => { ], (err, content) => {
if (err) { if (err) {

View File

@ -1,6 +1,8 @@
pragma solidity ^0.4.7; pragma solidity ^0.4.7;
contract SimpleStorage { contract SimpleStorage {
uint public storedData; uint public storedData;
import "ownable.sol";
import "ownable2.sol";
function SimpleStorage(uint initialValue) { function SimpleStorage(uint initialValue) {
storedData = 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);
});
});
});