Skip to content

Commit 60fb6b1

Browse files
committed
downlaod import files
1 parent 05b1f61 commit 60fb6b1

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

lib/core/file.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = /import "([a-zA-Z0-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);

test/contracts/simple_storage.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pragma solidity ^0.4.7;
22
contract SimpleStorage {
33
uint public storedData;
44
import "./ownable.sol";
5-
import "../../contracts/token.sol";
65

76
function SimpleStorage(uint initialValue) {
87
storedData = initialValue;

test/file.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ const fs = require('fs-extra');
44

55
describe('embark.File', function () {
66
describe('parseFileForImport', () => {
7-
it('should find all the imports', function () {
7+
it('should find all the imports', function (done) {
88
const contract = fs.readFileSync('./test/contracts/simple_storage.sol').toString();
9-
const file = new File({filename: 'simple_storage.sol',
9+
const file = new File({filename: '.embark/contracts/embark-framework/embark/master/test_app/app/contracts/simple_storage.sol',
1010
path: 'https://raw.githubusercontent.com/embark-framework/embark/develop/test_apps/test_app/app/contracts/simple_storage.sol'});
11-
file.parseFileForImport(contract);
11+
file.parseFileForImport(contract, () => {
12+
done();
13+
});
1214
});
1315
});
1416
});

0 commit comments

Comments
 (0)