From c87d7da4cc6f0878c087889bb6d0164d33f82c74 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 4 Jul 2019 16:35:41 -0400 Subject: [PATCH] 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 --- packages/embark-code-generator/src/index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/embark-code-generator/src/index.js b/packages/embark-code-generator/src/index.js index c6e369fd9..92f24b049 100644 --- a/packages/embark-code-generator/src/index.js +++ b/packages/embark-code-generator/src/index.js @@ -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";