add command event to add a contract file; fix internal plugin Path

This commit is contained in:
Iuri Matias 2018-06-18 11:25:43 -04:00
parent f9e62b9f49
commit e0e3887aaf
3 changed files with 12 additions and 1 deletions

View File

@ -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;

View File

@ -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');
};

View File

@ -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,