Skip to content

Commit 31ecaf0

Browse files
committed
support to download specified versions of web3
1 parent 263fdb6 commit 31ecaf0

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

lib/core/config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var fs = require('./fs.js');
22
var Plugins = require('./plugins.js');
33
var utils = require('../utils/utils.js');
4+
var npm = require('../pipeline/npm.js');
45

56
// TODO: add wrapper for fs so it can also work in the browser
67
// can work with both read and save
@@ -248,6 +249,13 @@ Config.prototype.loadFiles = function(files) {
248249

249250
readFiles.push({filename: 'embark.js', content: fs.readFileSync(fs.embarkPath("js/build/embark.bundle.js")).toString(), path: fs.embarkPath("js/build/embark.bundle.js")});
250251
}
252+
if (file.indexOf("web3-") == 0) {
253+
let web3Version = file.split('web3-')[1].split(".js")[0];
254+
npm.getPackageVersion('web3', web3Version, function(web3Content) {
255+
self.logger.error('downloaded web3');
256+
readFiles.push({filename: file, content: web3Content, path: fs.embarkPath("js/web3.js")});
257+
});
258+
}
251259
});
252260

253261
// get plugins
@@ -280,6 +288,8 @@ Config.prototype.loadFiles = function(files) {
280288
originalFiles.filter(function(file) {
281289
if (file === 'embark.js') {
282290
return;
291+
} else if (file.indexOf("web3-") === 0) {
292+
return;
283293
} else if (file === 'abi.js') {
284294
readFiles.push({filename: file, content: "", path: file});
285295
} else {

lib/pipeline/npm.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
let utils = require('../utils/utils.js');
2+
3+
module.exports = {
4+
// TODO: need to refactor to make it truly generalistic, perhaps by
5+
// downloading the tarball itself
6+
getPackageVersion: function(packageName, version, callback) {
7+
let npmRegistry = "http://registry.npmjs.org/" + packageName + "/" + version;
8+
9+
utils.httpGet(npmRegistry, function (res) {
10+
11+
let body = '';
12+
res.on('data', function (d) {
13+
body += d;
14+
});
15+
res.on('end', function () {
16+
let registryJSON = JSON.parse(body);
17+
let gitHash = registryJSON.gitHead;
18+
let repo = registryJSON.homepage.split("github.com/")[1];
19+
20+
let gitUrl = "http://raw.githubusercontent.com/" + repo + "/" + gitHash + "/dist/" + packageName + ".js"
21+
utils.httpGet(gitUrl, function (res2) {
22+
let body = '';
23+
res2.on('data', function (d) {
24+
body += d;
25+
});
26+
res2.on('end', function () {
27+
callback(body);
28+
});
29+
});
30+
});
31+
});
32+
}
33+
};
34+

lib/utils/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
let path = require('path');
33
let globule = require('globule');
44
let merge = require('merge');
5-
let http = require('http');
5+
let http = require('follow-redirects').http;
66
let shelljs = require('shelljs');
77

88
function joinPath() {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"commander": "^2.8.1",
2525
"ethereumjs-testrpc": "3.9.2",
2626
"finalhandler": "^0.5.0",
27+
"follow-redirects": "^1.2.4",
2728
"fs-extra": "^2.0.0",
2829
"globule": "^1.1.0",
2930
"merge": "^1.2.0",

test_app/embark.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"js/mytoken.js": ["$MyToken", "app/js/token_test.js"],
1111
"index.html": "app/index.html",
1212
"test.html": "app/test.html",
13-
"test2.html": "app/test2.html"
13+
"test2.html": "app/test2.html",
14+
"js/myweb3.js": "web3-0.18.js"
1415
},
1516
"buildDir": "dist/",
1617
"config": "config/",

0 commit comments

Comments
 (0)