diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index c3b31bc3e..e5c24be7e 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -56,28 +56,8 @@ class Pipeline { fs.writeFileSync(filePath, contractCode); importsList[request] = filePath; } else if (request === "Embark/web3") { - console.log("--> web3"); - return self.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); - importsList[request] = filePath; + return self.buildWeb3JS(function() { + importsList[request] = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js'); callback(null, "amd " + Math.random()); }); } @@ -453,6 +433,33 @@ class Pipeline { 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;