base code for import parse
This commit is contained in:
parent
e1a9023bb2
commit
6c5415b27f
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue