support to download specified versions of web3

This commit is contained in:
Iuri Matias 2017-07-02 13:33:11 -04:00
parent 263fdb6d8b
commit 31ecaf0837
5 changed files with 48 additions and 2 deletions

View File

@ -1,6 +1,7 @@
var fs = require('./fs.js'); var fs = require('./fs.js');
var Plugins = require('./plugins.js'); var Plugins = require('./plugins.js');
var utils = require('../utils/utils.js'); var utils = require('../utils/utils.js');
var npm = require('../pipeline/npm.js');
// TODO: add wrapper for fs so it can also work in the browser // TODO: add wrapper for fs so it can also work in the browser
// can work with both read and save // can work with both read and save
@ -248,6 +249,13 @@ Config.prototype.loadFiles = function(files) {
readFiles.push({filename: 'embark.js', content: fs.readFileSync(fs.embarkPath("js/build/embark.bundle.js")).toString(), path: fs.embarkPath("js/build/embark.bundle.js")}); readFiles.push({filename: 'embark.js', content: fs.readFileSync(fs.embarkPath("js/build/embark.bundle.js")).toString(), path: fs.embarkPath("js/build/embark.bundle.js")});
} }
if (file.indexOf("web3-") == 0) {
let web3Version = file.split('web3-')[1].split(".js")[0];
npm.getPackageVersion('web3', web3Version, function(web3Content) {
self.logger.error('downloaded web3');
readFiles.push({filename: file, content: web3Content, path: fs.embarkPath("js/web3.js")});
});
}
}); });
// get plugins // get plugins
@ -280,6 +288,8 @@ Config.prototype.loadFiles = function(files) {
originalFiles.filter(function(file) { originalFiles.filter(function(file) {
if (file === 'embark.js') { if (file === 'embark.js') {
return; return;
} else if (file.indexOf("web3-") === 0) {
return;
} else if (file === 'abi.js') { } else if (file === 'abi.js') {
readFiles.push({filename: file, content: "", path: file}); readFiles.push({filename: file, content: "", path: file});
} else { } else {

34
lib/pipeline/npm.js Normal file
View File

@ -0,0 +1,34 @@
let utils = require('../utils/utils.js');
module.exports = {
// TODO: need to refactor to make it truly generalistic, perhaps by
// downloading the tarball itself
getPackageVersion: function(packageName, version, callback) {
let npmRegistry = "http://registry.npmjs.org/" + packageName + "/" + version;
utils.httpGet(npmRegistry, function (res) {
let body = '';
res.on('data', function (d) {
body += d;
});
res.on('end', function () {
let registryJSON = JSON.parse(body);
let gitHash = registryJSON.gitHead;
let repo = registryJSON.homepage.split("github.com/")[1];
let gitUrl = "http://raw.githubusercontent.com/" + repo + "/" + gitHash + "/dist/" + packageName + ".js"
utils.httpGet(gitUrl, function (res2) {
let body = '';
res2.on('data', function (d) {
body += d;
});
res2.on('end', function () {
callback(body);
});
});
});
});
}
};

View File

@ -2,7 +2,7 @@
let path = require('path'); let path = require('path');
let globule = require('globule'); let globule = require('globule');
let merge = require('merge'); let merge = require('merge');
let http = require('http'); let http = require('follow-redirects').http;
let shelljs = require('shelljs'); let shelljs = require('shelljs');
function joinPath() { function joinPath() {

View File

@ -24,6 +24,7 @@
"commander": "^2.8.1", "commander": "^2.8.1",
"ethereumjs-testrpc": "3.9.2", "ethereumjs-testrpc": "3.9.2",
"finalhandler": "^0.5.0", "finalhandler": "^0.5.0",
"follow-redirects": "^1.2.4",
"fs-extra": "^2.0.0", "fs-extra": "^2.0.0",
"globule": "^1.1.0", "globule": "^1.1.0",
"merge": "^1.2.0", "merge": "^1.2.0",

View File

@ -10,7 +10,8 @@
"js/mytoken.js": ["$MyToken", "app/js/token_test.js"], "js/mytoken.js": ["$MyToken", "app/js/token_test.js"],
"index.html": "app/index.html", "index.html": "app/index.html",
"test.html": "app/test.html", "test.html": "app/test.html",
"test2.html": "app/test2.html" "test2.html": "app/test2.html",
"js/myweb3.js": "web3-0.18.js"
}, },
"buildDir": "dist/", "buildDir": "dist/",
"config": "config/", "config": "config/",