From 3f20f400ddc406004f4d0291bd685a3caf815712 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 09:35:55 -0400 Subject: [PATCH] certify pluginTypes are uniques, to avoid issue with a plugin call being called twice or more --- lib/core/plugin.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 44345487..f5ad6624 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -1,6 +1,7 @@ const fs = require('./fs.js'); const utils = require('../utils/utils.js'); const constants = require('../constants'); +const _ = require('underscore') // TODO: pass other params like blockchainConfig, contract files, etc.. var Plugin = function(options) { @@ -120,43 +121,45 @@ Plugin.prototype.interceptLogs = function(context) { Plugin.prototype.registerClientWeb3Provider = function(cb) { this.clientWeb3Providers.push(cb); this.pluginTypes.push('clientWeb3Provider'); -}; - -Plugin.prototype.registerBeforeDeploy = function(cb) { - this.beforeDeploy.push(cb); - this.pluginTypes.push('beforeDeploy'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerContractsGeneration = function(cb) { this.contractsGenerators.push(cb); this.pluginTypes.push('contractGeneration'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerPipeline = function(matcthingFiles, cb) { // TODO: generate error for more than one pipeline per plugin this.pipeline.push({matcthingFiles: matcthingFiles, cb: cb}); this.pluginTypes.push('pipeline'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) { this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options}); this.pluginTypes.push('pipelineFiles'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addContractFile = function(file) { this.contractsFiles.push(file); this.pluginTypes.push('contractFiles'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerConsoleCommand = function(cb) { this.console.push(cb); this.pluginTypes.push('console'); + this.pluginTypes = _.uniq(this.pluginTypes); }; // TODO: this only works for services done on startup Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) { this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time}); this.pluginTypes.push('serviceChecks'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.has = function(pluginType) { @@ -178,32 +181,38 @@ Plugin.prototype.generateContracts = function(args) { Plugin.prototype.registerContractConfiguration = function(config) { this.contractsConfigs.push(config); this.pluginTypes.push('contractsConfig'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerCompiler = function(extension, cb) { this.compilers.push({extension: extension, cb: cb}); this.pluginTypes.push('compilers'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerUploadCommand = function(cmd, cb) { this.uploadCmds.push({cmd: cmd, cb: cb}); this.pluginTypes.push('uploadCmds'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addCodeToEmbarkJS = function(code) { this.embarkjs_code.push(code); this.pluginTypes.push('embarkjsCode'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addProviderInit = function(providerType, code, initCondition) { this.embarkjs_init_code[providerType] = this.embarkjs_init_code[providerType] || []; this.embarkjs_init_code[providerType].push([code, initCondition]); this.pluginTypes.push('initCode'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerImportFile = function(importName, importLocation) { this.imports.push([importName, importLocation]); this.pluginTypes.push('imports'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerActionForEvent = function(eventName, cb) { @@ -212,6 +221,7 @@ Plugin.prototype.registerActionForEvent = function(eventName, cb) { } this.eventActions[eventName].push(cb); this.pluginTypes.push('eventActions'); + this.pluginTypes = _.uniq(this.pluginTypes); } Plugin.prototype.runFilePipeline = function() {