fix support for 1.0 versions of web3

This commit is contained in:
Iuri Matias 2017-10-06 07:30:34 -04:00
parent f41702634f
commit a78d8b00bf
4 changed files with 64 additions and 27 deletions

View File

@ -29,7 +29,7 @@ class SolcW {
solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'}); solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'});
} else { } else {
let npm = new Npm({logger: this.logger}); let npm = new Npm({logger: this.logger});
npm.getPackageVersion('solc', this.solcVersion, false, function(location) { npm.getPackageVersion('solc', this.solcVersion, false, false, function(location) {
let requirePath = path.join(process.env.PWD, location); let requirePath = path.join(process.env.PWD, location);
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath}); solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
}); });

View File

@ -257,7 +257,7 @@ Config.prototype.loadFiles = function(files) {
//readFiles.push(new File({filename: 'web3-' + web3Version + '.js', type: 'custom', resolver: function(callback) { //readFiles.push(new File({filename: 'web3-' + web3Version + '.js', type: 'custom', resolver: function(callback) {
readFiles.push(new File({filename: 'web3.js', type: 'custom', resolver: function(callback) { readFiles.push(new File({filename: 'web3.js', type: 'custom', resolver: function(callback) {
let npm = new Npm({logger: self.logger}); let npm = new Npm({logger: self.logger});
npm.getPackageVersion('web3', web3Version, 'dist/web3.js', function(web3Content) { npm.getPackageVersion('web3', web3Version, 'dist/web3.min.js', true, function(web3Content) {
callback(web3Content); callback(web3Content);
}); });
}})); }}));

View File

@ -12,7 +12,8 @@ class Npm {
this.logger = options.logger; this.logger = options.logger;
} }
getPackageVersion(packageName, version, returnContent, callback) { // TODO: callback should accept an error
getPackageVersion(packageName, version, returnContent, getFromGit, callback) {
let self = this; let self = this;
let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version; let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version;
@ -25,6 +26,7 @@ class Npm {
res.on('end', function () { res.on('end', function () {
let registryJSON = JSON.parse(body); let registryJSON = JSON.parse(body);
console.log(JSON.stringify(registryJSON));
let tarball = registryJSON.dist.tarball; let tarball = registryJSON.dist.tarball;
var download = function(url, dest, cb) { var download = function(url, dest, cb) {
@ -40,35 +42,70 @@ class Npm {
}); });
}; };
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; if (getFromGit) {
let repoName = registryJSON.repository.url.replace("git+https://github.com/", "").replace(".git","");
let gitHead = registryJSON.gitHead;
let fileLocation = "https://raw.githubusercontent.com/" + repoName + "/" + gitHead + "/dist/web3.min.js";
if (fs.existsSync(packageDirectory + "/downloaded_package.tgz")) { let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
if (returnContent) { if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) {
let distFile = packageDirectory + returnContent; if (returnContent) {
callback(fs.readFileSync(distFile).toString()); let distFile = packageDirectory + packageName + ".js";
callback(fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
}
} else { } else {
callback(packageDirectory); fs.mkdirpSync(packageDirectory);
self.logger.info("downloading " + packageName + " " + version + "....");
download(tarball, packageDirectory + "/" + packageName + ".js", function() {
o_fs.createReadStream(packageDirectory + "/" + packageName + ".js").pipe(
tar.x({
strip: 1,
C: packageDirectory
}).on('end', function() {
if (returnContent) {
let distFile = packageDirectory + packageName + ".js";
callback(fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
}
})
);
});
} }
} else { } else {
fs.mkdirpSync(packageDirectory);
self.logger.info("downloading " + packageName + " " + version + "....");
download(tarball, packageDirectory + "/downloaded_package.tgz", function() { let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe( if (fs.existsSync(packageDirectory + "/downloaded_package.tgz")) {
tar.x({ if (returnContent) {
strip: 1, let distFile = packageDirectory + returnContent;
C: packageDirectory callback(fs.readFileSync(distFile).toString());
}).on('end', function() { } else {
if (returnContent) { callback(packageDirectory);
let distFile = packageDirectory + returnContent; }
callback(fs.readFileSync(distFile).toString()); } else {
} else { fs.mkdirpSync(packageDirectory);
callback(packageDirectory); self.logger.info("downloading " + packageName + " " + version + "....");
}
})
);
});
download(tarball, packageDirectory + "/downloaded_package.tgz", function() {
o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe(
tar.x({
strip: 1,
C: packageDirectory
}).on('end', function() {
if (returnContent) {
let distFile = packageDirectory + returnContent;
callback(fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
}
})
);
});
}
} }
}); });

View File

@ -1,7 +1,7 @@
{ {
"default": { "default": {
"versions": { "versions": {
"web3.js": "0.20.0", "web3.js": "1.0.0-beta.18",
"solc": "0.4.11" "solc": "0.4.11"
}, },
"deployment": { "deployment": {