diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 6807c4149..9b7d064d2 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -75,10 +75,11 @@ class Pipeline { }, function writeContracts(next) { async.each(Object.keys(contractsJSON), (contractName, eachCb) => { - let contractCode = self.buildContractJS(contractName); - let filePath = fs.dappPath(".embark", contractName + '.js'); - importsList["Embark/contracts/" + contractName] = filePath; - fs.writeFile(filePath, contractCode, eachCb); + self.buildContractJS(contractName, (err, contractCode) => { + let filePath = fs.dappPath(".embark", contractName + '.js'); + importsList["Embark/contracts/" + contractName] = filePath; + fs.writeFile(filePath, contractCode, eachCb); + }); }, next); }, function assetFileWrite(next) { @@ -310,22 +311,26 @@ class Pipeline { }); } - buildContractJS(contractName) { - let contractJSON = fs.readFileSync(fs.dappPath(this.buildDir, 'contracts', contractName + '.json')).toString(); + buildContractJS(contractName, callback) { + fs.readFile(fs.dappPath(this.buildDir, 'contracts', contractName + '.json'), (err, contractJSON) => { + if (err) { + return callback(err); + } + contractJSON = contractJSON.toString(); - let contractCode = ""; - contractCode += "import web3 from 'Embark/web3';\n"; - contractCode += "import EmbarkJS from 'Embark/EmbarkJS';\n"; - contractCode += "let " + contractName + "JSONConfig = " + contractJSON + ";\n"; - contractCode += "let " + contractName + " = new EmbarkJS.Contract(" + contractName + "JSONConfig);\n"; + let contractCode = ""; + contractCode += "import web3 from 'Embark/web3';\n"; + contractCode += "import EmbarkJS from 'Embark/EmbarkJS';\n"; + contractCode += "let " + contractName + "JSONConfig = " + contractJSON + ";\n"; + contractCode += "let " + contractName + " = new EmbarkJS.Contract(" + contractName + "JSONConfig);\n"; - contractCode += "\n__embarkContext.execWhenReady(function() {\n"; - contractCode += "\n" + contractName + ".setProvider(web3.currentProvider);\n"; - contractCode += "\n});\n"; + contractCode += "\n__embarkContext.execWhenReady(function() {\n"; + contractCode += "\n" + contractName + ".setProvider(web3.currentProvider);\n"; + contractCode += "\n});\n"; - contractCode += "export default " + contractName + ";\n"; - - return contractCode; + contractCode += "export default " + contractName + ";\n"; + callback(null, contractCode); + }); } buildWeb3JS(cb) {