fix(@embark/code-generator): use plugins for contract generation

`contractGeneration` plugins were only used in the Embark console
Now they are used to generate the Dapp artifacts too
This commit is contained in:
Jonathan Rainville 2019-07-04 16:35:41 -04:00 committed by Michael Bradley
parent 536a4029ba
commit c87d7da4cc
1 changed files with 18 additions and 2 deletions

View File

@ -56,7 +56,7 @@ class CodeGenerator {
this.events.setCommandHandler('code-generator:contract', (contractName, cb) => {
this.events.request('contracts:contract', contractName, (contract) => {
this.buildContractJS(contractName, this.generateContractJSON(contract, contract), cb);
this.buildContractJS(contract, cb);
});
});
@ -457,7 +457,23 @@ class CodeGenerator {
}, "");
}
buildContractJS(contractName, contractJSON, cb) {
buildContractJS(contract, cb) {
const contractName = contract.className;
if (this.plugins) {
const contractsPlugins = this.plugins.getPluginsFor('contractGeneration');
if (contractsPlugins.length > 0) {
let result = '';
contractsPlugins.forEach(function (plugin) {
result += plugin.generateContracts({contracts: {[contractName]: contract}});
});
return this.generateArtifact(result, contractName + '.js', constants.dappArtifacts.contractsJs, (err, path, _updated) => {
cb(err, path);
});
}
}
const contractJSON = this.generateContractJSON(contractName, contract);
const contractCode = `
"use strict";