mirror of https://github.com/embarklabs/embark.git
fix web3 versioning
This commit is contained in:
parent
7a5e5947ee
commit
59642b4160
|
@ -1,3 +1,4 @@
|
|||
let async = require('async');
|
||||
let fs = require('../core/fs.js');
|
||||
var utils = require('../utils/utils.js');
|
||||
|
||||
|
@ -271,28 +272,50 @@ class CodeGenerator {
|
|||
return contracts;
|
||||
}
|
||||
|
||||
buildEmbarkJS() {
|
||||
buildEmbarkJS(cb) {
|
||||
const self = this;
|
||||
let embarkjsCode = fs.readFileSync(fs.embarkPath('js/embark.js')).toString();
|
||||
let code = "";
|
||||
|
||||
code += "\nimport Web3 from '" + utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")) + "';\n";
|
||||
code += "\nimport web3 from 'Embark/web3';\n";
|
||||
async.waterfall([
|
||||
function getWeb3Location(next) {
|
||||
self.events.request("version:get:web3", function(web3Version) {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
return next(null, utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")));
|
||||
} else {
|
||||
self.events.request("version:getPackageLocation", "web3", web3Version, function(err, location) {
|
||||
return next(null, utils.joinPath(process.env.PWD, location));
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
function getImports(web3Location, next) {
|
||||
code += "\nimport Web3 from '" + web3Location + "';\n";
|
||||
code += "\nimport web3 from 'Embark/web3';\n";
|
||||
next();
|
||||
},
|
||||
function getJSCode(next) {
|
||||
code += "\n" + embarkjsCode + "\n";
|
||||
let pluginsWithCode = self.plugins.getPluginsFor('embarkjsCode');
|
||||
for (let plugin of pluginsWithCode) {
|
||||
code += plugin.embarkjs_code.join('\n');
|
||||
}
|
||||
|
||||
code += "\n" + embarkjsCode + "\n";
|
||||
//code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/orbit.js')).toString();
|
||||
|
||||
let pluginsWithCode = this.plugins.getPluginsFor('embarkjsCode');
|
||||
for (let plugin of pluginsWithCode) {
|
||||
code += plugin.embarkjs_code.join('\n');
|
||||
}
|
||||
|
||||
//code += "\n" + fs.readFileSync(fs.embarkPath('js/embarkjs/orbit.js')).toString();
|
||||
|
||||
code += this.generateCommunicationInitialization(true);
|
||||
code += this.generateStorageInitialization(true);
|
||||
|
||||
let filePath = utils.joinPath(fs.dappPath(), ".embark", 'embark.js');
|
||||
fs.mkdirpSync(utils.joinPath(fs.dappPath(), ".embark"));
|
||||
fs.writeFileSync(filePath, code);
|
||||
code += self.generateCommunicationInitialization(true);
|
||||
code += self.generateStorageInitialization(true);
|
||||
next();
|
||||
},
|
||||
function writeFile(next) {
|
||||
let filePath = utils.joinPath(fs.dappPath(), ".embark", 'embark.js');
|
||||
fs.mkdirpSync(utils.joinPath(fs.dappPath(), ".embark"));
|
||||
fs.writeFileSync(filePath, code);
|
||||
next();
|
||||
}
|
||||
], function(_err, _result) {
|
||||
cb();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -121,9 +121,9 @@ class Engine {
|
|||
events: self.events
|
||||
});
|
||||
codeGenerator.listenToCommands();
|
||||
codeGenerator.buildEmbarkJS();
|
||||
|
||||
self.events.emit('code-generator-ready');
|
||||
codeGenerator.buildEmbarkJS(function() {
|
||||
self.events.emit('code-generator-ready');
|
||||
});
|
||||
};
|
||||
this.events.on('contractsDeployed', generateCode);
|
||||
this.events.on('blockchainDisabled', generateCode);
|
||||
|
|
|
@ -38,6 +38,9 @@ class Pipeline {
|
|||
//importsList["Embark/EmbarkJS"] = fs.embarkPath("js/embark.js");
|
||||
importsList["Embark/EmbarkJS"] = utils.joinPath(fs.dappPath(), ".embark", 'embark.js');
|
||||
importsList["Embark/web3"] = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js');
|
||||
|
||||
//importsList["ipfs-api"] = utils.joinPath(fs.dappPath(), ".embark", 'ipfs_api.js');
|
||||
|
||||
//importsList["Embark/libs/IpfsApi"] = fs.embarkPath('js/ipfs.js');
|
||||
|
||||
async.waterfall([
|
||||
|
@ -80,11 +83,11 @@ class Pipeline {
|
|||
alias: importsList
|
||||
},
|
||||
externals: function(context, request, callback) {
|
||||
if (request === "Embark/contracts/all") {
|
||||
return callback(null, fs.readFileSync(utils.joinPath(fs.dappPath(), '.embark', 'embark.js')));
|
||||
// should be .toString() ?
|
||||
}
|
||||
callback();
|
||||
if (request === "Embark/contracts/all") {
|
||||
return callback(null, fs.readFileSync(utils.joinPath(fs.dappPath(), '.embark', 'embark.js')));
|
||||
// should be .toString() ?
|
||||
}
|
||||
callback();
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
|
@ -196,22 +199,44 @@ class Pipeline {
|
|||
}
|
||||
|
||||
buildWeb3JS(cb) {
|
||||
this.events.request('provider-code', function(providerCode) {
|
||||
let code = "";
|
||||
code += "\nimport Web3 from '" + utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")) + "'\n";
|
||||
const self = this;
|
||||
let code = "";
|
||||
|
||||
code += "\n if (typeof web3 !== 'undefined') {";
|
||||
code += "\n } else {";
|
||||
code += "\n var web3 = new Web3();\n";
|
||||
code += "\n }";
|
||||
async.waterfall([
|
||||
function getWeb3Location(next) {
|
||||
self.events.request("version:get:web3", function(web3Version) {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
return next(null, utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")));
|
||||
} else {
|
||||
self.events.request("version:getPackageLocation", "web3", web3Version, function(err, location) {
|
||||
return next(null, utils.joinPath(process.env.PWD, location));
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
function getImports(web3Location, next) {
|
||||
code += "\nimport Web3 from '" + web3Location + "';\n";
|
||||
|
||||
code += providerCode;
|
||||
code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n";
|
||||
code += "\nwindow.web3 = web3;\n";
|
||||
code += "\nexport default web3;\n";
|
||||
let filePath = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js');
|
||||
fs.mkdirpSync(utils.joinPath(fs.dappPath(), ".embark"));
|
||||
fs.writeFileSync(filePath, code);
|
||||
code += "\n if (typeof web3 !== 'undefined') {";
|
||||
code += "\n } else {";
|
||||
code += "\n var web3 = new Web3();\n";
|
||||
code += "\n }";
|
||||
|
||||
self.events.request('provider-code', function(providerCode) {
|
||||
code += providerCode;
|
||||
code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n";
|
||||
code += "\nwindow.web3 = web3;\n";
|
||||
code += "\nexport default web3;\n";
|
||||
next();
|
||||
});
|
||||
},
|
||||
function writeFile(next) {
|
||||
let filePath = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js');
|
||||
fs.mkdirpSync(utils.joinPath(fs.dappPath(), ".embark"));
|
||||
fs.writeFileSync(filePath, code);
|
||||
next();
|
||||
}
|
||||
], function(_err, _result) {
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"default": {
|
||||
"versions": {
|
||||
"web3.js": "1.0.0-beta",
|
||||
"web3.js": "1.0.0-beta.27",
|
||||
"solc": "0.4.17"
|
||||
},
|
||||
"deployment": {
|
||||
|
|
Loading…
Reference in New Issue