downlaod import files
This commit is contained in:
parent
05b1f61c9b
commit
60fb6b14d4
|
@ -14,26 +14,32 @@ class File {
|
|||
}
|
||||
|
||||
parseFileForImport(content, callback) {
|
||||
if (this.filename.indexOf('.sol') < 0) {
|
||||
const self = this;
|
||||
if (self.filename.indexOf('.sol') < 0) {
|
||||
// Only supported in Solidity
|
||||
return callback();
|
||||
}
|
||||
const regex = /import "([a-zA-Z0-9_\-.\\\/]+)";/g;
|
||||
let matches;
|
||||
const filesToDownload = [];
|
||||
const pathWithoutFile = path.dirname(this.path);
|
||||
const pathWithoutFile = path.dirname(self.path);
|
||||
while ((matches = regex.exec(content))) {
|
||||
console.log('Need to download', matches[1]);
|
||||
filesToDownload.push({
|
||||
fileRelativePath: matches[1],
|
||||
url: path.join(pathWithoutFile, matches[1])
|
||||
fileRelativePath: path.join(path.dirname(self.filename), matches[1]),
|
||||
url: `${pathWithoutFile}/${matches[1]}`
|
||||
});
|
||||
}
|
||||
//async.each(filesToDownload, (file))
|
||||
|
||||
async.each(filesToDownload, ((fileObj, eachCb) => {
|
||||
self.downloadFile(fileObj.fileRelativePath, fileObj.url, (_content) => {
|
||||
eachCb();
|
||||
});
|
||||
}), callback);
|
||||
}
|
||||
|
||||
downloadFile (filename, url, callback) {
|
||||
// const self = this;
|
||||
console.log('Downloading:', filename, 'form', url);
|
||||
const self = this;
|
||||
async.waterfall([
|
||||
function makeTheDir(next) {
|
||||
fs.mkdirp(path.dirname(filename), (err) => {
|
||||
|
@ -56,12 +62,12 @@ class File {
|
|||
},
|
||||
function readFile(next) {
|
||||
fs.readFile(filename, next);
|
||||
}// ,
|
||||
/*function parseForImports(content, next) {
|
||||
},
|
||||
function parseForImports(content, next) {
|
||||
self.parseFileForImport(content, (err) => {
|
||||
next(err, content);
|
||||
});
|
||||
}*/
|
||||
}
|
||||
], (err, content) => {
|
||||
if (err) {
|
||||
console.error('Error while downloading the file', err);
|
||||
|
|
|
@ -2,7 +2,6 @@ pragma solidity ^0.4.7;
|
|||
contract SimpleStorage {
|
||||
uint public storedData;
|
||||
import "./ownable.sol";
|
||||
import "../../contracts/token.sol";
|
||||
|
||||
function SimpleStorage(uint initialValue) {
|
||||
storedData = initialValue;
|
||||
|
|
|
@ -4,11 +4,13 @@ const fs = require('fs-extra');
|
|||
|
||||
describe('embark.File', function () {
|
||||
describe('parseFileForImport', () => {
|
||||
it('should find all the imports', function () {
|
||||
it('should find all the imports', function (done) {
|
||||
const contract = fs.readFileSync('./test/contracts/simple_storage.sol').toString();
|
||||
const file = new File({filename: 'simple_storage.sol',
|
||||
const file = new File({filename: '.embark/contracts/embark-framework/embark/master/test_app/app/contracts/simple_storage.sol',
|
||||
path: 'https://raw.githubusercontent.com/embark-framework/embark/develop/test_apps/test_app/app/contracts/simple_storage.sol'});
|
||||
file.parseFileForImport(contract);
|
||||
file.parseFileForImport(contract, () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue