mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-19 17:14:40 +00:00
move contracts generation from pipeline to code generator module
This commit is contained in:
parent
7271b00cf4
commit
6544c2a999
@ -100,6 +100,12 @@ class CodeGenerator {
|
|||||||
self.buildWeb3JS(cb);
|
self.buildWeb3JS(cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.events.setCommandHandler('code-generator:contract', (contractName, cb) => {
|
||||||
|
self.events.request('contracts:contract', contractName, (contractJSON) => {
|
||||||
|
self.buildContractJS(contractName, contractJSON.toString(), cb);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
generateContext() {
|
generateContext() {
|
||||||
@ -323,6 +329,22 @@ class CodeGenerator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildContractJS(contractName, contractJSON, cb) {
|
||||||
|
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" + contractName + ".options.from = web3.eth.defaultAccount;\n";
|
||||||
|
contractCode += "\n});\n";
|
||||||
|
|
||||||
|
contractCode += "export default " + contractName + ";\n";
|
||||||
|
cb(null, contractCode);
|
||||||
|
}
|
||||||
|
|
||||||
buildWeb3JS(cb) {
|
buildWeb3JS(cb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
let code = "";
|
let code = "";
|
||||||
|
@ -176,7 +176,7 @@ class Pipeline {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildContracts(contractsJSON, callback) {
|
buildContracts(contractsJSON, JSON, callback) {
|
||||||
fs.mkdirp(fs.dappPath(this.buildDir, 'contracts'), (err) => {
|
fs.mkdirp(fs.dappPath(this.buildDir, 'contracts'), (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -189,25 +189,10 @@ class Pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildContractJS(contractName, callback) {
|
buildContractJS(contractName, callback) {
|
||||||
fs.readFile(fs.dappPath(this.buildDir, 'contracts', contractName + '.json'), (err, contractJSON) => {
|
const self = this;
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
contractJSON = contractJSON.toString();
|
|
||||||
|
|
||||||
let contractCode = "";
|
self.events.request('code-generator:contract', contractName, (code) => {
|
||||||
contractCode += "import web3 from 'Embark/web3';\n";
|
callback(null, code);
|
||||||
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" + contractName + ".options.from = web3.eth.defaultAccount;\n";
|
|
||||||
contractCode += "\n});\n";
|
|
||||||
|
|
||||||
contractCode += "export default " + contractName + ";\n";
|
|
||||||
callback(null, contractCode);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user