From db35d7f5735d0727b27a088ce0d1835dd56b93b9 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 22 Nov 2018 10:45:49 +0000 Subject: [PATCH] feat: add new event before build --- src/lib/core/engine.js | 2 +- src/lib/core/plugins.js | 4 ++++ src/lib/modules/contracts_manager/index.js | 6 ++++++ src/test/contracts.js | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/core/engine.js b/src/lib/core/engine.js index 219ed463c..6fa7f2cdf 100644 --- a/src/lib/core/engine.js +++ b/src/lib/core/engine.js @@ -212,7 +212,7 @@ class Engine { this.registerModule('compiler', {plugins: this.plugins, disableOptimizations: options.disableOptimizations}); this.registerModule('solidity', {ipc: this.ipc, useDashboard: this.useDashboard}); this.registerModule('vyper'); - this.registerModule('contracts_manager', {compileOnceOnly: options.compileOnceOnly}); + this.registerModule('contracts_manager', {plugins: this.plugins, compileOnceOnly: options.compileOnceOnly}); } deploymentService(options) { diff --git a/src/lib/core/plugins.js b/src/lib/core/plugins.js index fde401b79..5477fbba6 100644 --- a/src/lib/core/plugins.js +++ b/src/lib/core/plugins.js @@ -57,6 +57,10 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) { var plugin; try { plugin = require(pluginPath); + + if (plugin.default) { + plugin = plugin.default; + } } catch(_e) { pluginPath = fs.embarkPath('modules/' + pluginName); plugin = require(pluginPath); diff --git a/src/lib/modules/contracts_manager/index.js b/src/lib/modules/contracts_manager/index.js index f56b9118e..72b9c95aa 100644 --- a/src/lib/modules/contracts_manager/index.js +++ b/src/lib/modules/contracts_manager/index.js @@ -13,6 +13,7 @@ class ContractsManager { const self = this; this.logger = embark.logger; this.events = embark.events; + this.plugins = options.plugins; this.contracts = {}; this.contractDependencies = {}; @@ -226,6 +227,11 @@ class ContractsManager { if(resetContracts) self.contracts = {}; async.waterfall([ + function beforeBuild(callback) { + self.plugins.emitAndRunActionsForEvent("build:beforeAll", () => { + callback(); + }); + }, function loadContractFiles(callback) { self.events.request("config:contractsFiles", (contractsFiles) => { self.contractsFiles = contractsFiles; diff --git a/src/test/contracts.js b/src/test/contracts.js index 8f2b9c5fe..a47c6572c 100644 --- a/src/test/contracts.js +++ b/src/test/contracts.js @@ -114,6 +114,7 @@ describe('embark.Contracts', function() { }; let contractsManager = new ContractsManager(embarkObj, { + plugins: plugins, contractDirectories: ['app/contracts'] }); @@ -239,6 +240,7 @@ describe('embark.Contracts', function() { } let contractsManager = new ContractsManager(embarkObj, { + plugins: plugins, contractDirectories: ['app/contracts'] });