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'});
} else {
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);
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.js', type: 'custom', resolver: function(callback) {
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);
});
}}));

View File

@ -12,7 +12,8 @@ class Npm {
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 npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version;
@ -25,6 +26,7 @@ class Npm {
res.on('end', function () {
let registryJSON = JSON.parse(body);
console.log(JSON.stringify(registryJSON));
let tarball = registryJSON.dist.tarball;
var download = function(url, dest, cb) {
@ -40,8 +42,43 @@ 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";
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) {
if (returnContent) {
let distFile = packageDirectory + packageName + ".js";
callback(fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
}
} else {
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 {
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
if (fs.existsSync(packageDirectory + "/downloaded_package.tgz")) {
if (returnContent) {
let distFile = packageDirectory + returnContent;
@ -68,7 +105,7 @@ class Npm {
})
);
});
}
}
});

View File

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