certify pluginTypes are uniques, to avoid issue with a plugin call being called twice or more

This commit is contained in:
Iuri Matias 2018-05-29 09:35:55 -04:00
parent 71cd523f30
commit 3f20f400dd
1 changed files with 15 additions and 5 deletions

View File

@ -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() {