From e0e3887aaf35504a01fb02962f4bd5af4bd62c2d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 18 Jun 2018 11:25:43 -0400 Subject: [PATCH 1/3] add command event to add a contract file; fix internal plugin Path --- lib/core/config.js | 7 +++++++ lib/core/plugin.js | 3 +++ lib/core/plugins.js | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/core/config.js b/lib/core/config.js index 8b8e36c54..14b622da6 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -31,6 +31,12 @@ var Config = function(options) { self.events.setCommandHandler("config:contractsFiles", (cb) => { cb(self.contractsFiles); }); + + self.events.setCommandHandler("config:contractsFiles:add", (filename) => { + self.contractsFiles.push(new File({filename: filename, type: File.types.custom, path: filename, resolver: function(callback) { + callback(fs.readFileSync(filename).toString()); + }})); + }); }; Config.prototype.loadConfigFiles = function(options) { @@ -376,6 +382,7 @@ Config.prototype.loadFiles = function(files) { return readFiles; }; +// NOTE: this doesn't work for internal modules Config.prototype.loadPluginContractFiles = function() { var self = this; diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 296f52b5d..991c8ceca 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -139,6 +139,9 @@ Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) { }; Plugin.prototype.addContractFile = function(file) { + if (this.isInternal) { + throw new Error("this API cannot work for internal modules. please use an event command instead: config:contractsFiles:add"); + } this.contractsFiles.push(file); this.addPluginType('contractFiles'); }; diff --git a/lib/core/plugins.js b/lib/core/plugins.js index fe42c472e..7ad0b7d53 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -1,6 +1,7 @@ const async = require('async'); var Plugin = require('./plugin.js'); var utils = require('../utils/utils.js'); +var fs = require('../core/fs.js'); var Plugins = function(options) { this.pluginList = options.plugins || []; @@ -61,7 +62,7 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) { pluginModule: plugin, pluginConfig: pluginConfig || {}, logger: this.logger, - pluginPath: pluginPath, + pluginPath: fs.embarkPath('lib/modules/' + pluginName), interceptLogs: this.interceptLogs, events: this.events, config: this.config, From b34ddf32cf8dcee0ed0d5d60ef419d2aa984b4fa Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 18 Jun 2018 11:27:29 -0400 Subject: [PATCH 2/3] refactor pluginPath --- lib/core/plugins.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/plugins.js b/lib/core/plugins.js index 7ad0b7d53..bbf717c26 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -54,7 +54,7 @@ Plugins.prototype.createPlugin = function(pluginName, pluginConfig) { }; Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) { - var pluginPath = utils.joinPath('../modules/', pluginName, 'index.js'); + var pluginPath = fs.embarkPath('lib/modules/' + pluginName); var plugin = require(pluginPath); var pluginWrapper = new Plugin({ @@ -62,7 +62,7 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) { pluginModule: plugin, pluginConfig: pluginConfig || {}, logger: this.logger, - pluginPath: fs.embarkPath('lib/modules/' + pluginName), + pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config, From 231e48cecb7357b4b636f6c3566b6ec9f0ac05a9 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 18 Jun 2018 11:37:23 -0400 Subject: [PATCH 3/3] add todo --- lib/core/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/core/config.js b/lib/core/config.js index 14b622da6..608d1f580 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -32,6 +32,7 @@ var Config = function(options) { cb(self.contractsFiles); }); + // TODO: refactor this so reading the file can be done with a normal resolver or something that takes advantage of the plugin api self.events.setCommandHandler("config:contractsFiles:add", (filename) => { self.contractsFiles.push(new File({filename: filename, type: File.types.custom, path: filename, resolver: function(callback) { callback(fs.readFileSync(filename).toString());