async buildContractJs

This commit is contained in:
Jonathan Rainville 2018-05-08 09:41:19 -04:00
parent 4ec7fbb9db
commit a03777dc65
1 changed files with 22 additions and 17 deletions

View File

@ -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) {