mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 22:34:24 +00:00
refactor building web3 obj
This commit is contained in:
parent
a174b94702
commit
c160ac616f
@ -56,28 +56,8 @@ class Pipeline {
|
|||||||
fs.writeFileSync(filePath, contractCode);
|
fs.writeFileSync(filePath, contractCode);
|
||||||
importsList[request] = filePath;
|
importsList[request] = filePath;
|
||||||
} else if (request === "Embark/web3") {
|
} else if (request === "Embark/web3") {
|
||||||
console.log("--> web3");
|
return self.buildWeb3JS(function() {
|
||||||
return self.events.request('provider-code', function(providerCode) {
|
importsList[request] = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js');
|
||||||
let code = "";
|
|
||||||
code += "\nimport Web3 from '" + utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")) + "'\n";
|
|
||||||
//code += "\nvar __mainContext = __mainContext || this;\n";
|
|
||||||
|
|
||||||
code += "\n if (typeof web3 !== 'undefined') {";
|
|
||||||
//code += "\n__mainContext.web3 = web3;\n";
|
|
||||||
code += "\n } else {";
|
|
||||||
code += "\n var web3 = new Web3();\n";
|
|
||||||
code += "\n }";
|
|
||||||
|
|
||||||
code += providerCode;
|
|
||||||
code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n";
|
|
||||||
code += "\nconsole.log('web3');\n";
|
|
||||||
code += "\nconsole.log(web3);\n";
|
|
||||||
//code += "\nwindow.web3 = __mainContext.web3;\n";
|
|
||||||
code += "\nwindow.web3 = web3;\n";
|
|
||||||
code += "\nexport default web3;\n";
|
|
||||||
let filePath = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js');
|
|
||||||
fs.writeFileSync(filePath, code);
|
|
||||||
importsList[request] = filePath;
|
|
||||||
callback(null, "amd " + Math.random());
|
callback(null, "amd " + Math.random());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -453,6 +433,33 @@ class Pipeline {
|
|||||||
|
|
||||||
return contractCode;
|
return contractCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildWeb3JS(cb) {
|
||||||
|
console.log("--> web3");
|
||||||
|
this.events.request('provider-code', function(providerCode) {
|
||||||
|
let code = "";
|
||||||
|
code += "\nimport Web3 from '" + utils.joinPath(fs.embarkPath("js/web3-1.0.min.js")) + "'\n";
|
||||||
|
//code += "\nvar __mainContext = __mainContext || this;\n";
|
||||||
|
|
||||||
|
code += "\n if (typeof web3 !== 'undefined') {";
|
||||||
|
//code += "\n__mainContext.web3 = web3;\n";
|
||||||
|
code += "\n } else {";
|
||||||
|
code += "\n var web3 = new Web3();\n";
|
||||||
|
code += "\n }";
|
||||||
|
|
||||||
|
code += providerCode;
|
||||||
|
code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n";
|
||||||
|
code += "\nconsole.log('web3');\n";
|
||||||
|
code += "\nconsole.log(web3);\n";
|
||||||
|
//code += "\nwindow.web3 = __mainContext.web3;\n";
|
||||||
|
code += "\nwindow.web3 = web3;\n";
|
||||||
|
code += "\nexport default web3;\n";
|
||||||
|
let filePath = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js');
|
||||||
|
fs.writeFileSync(filePath, code);
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Pipeline;
|
module.exports = Pipeline;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user