From dee49ec5edc591e45f0128e6a3c1e1bfcd43b0c0 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 30 Dec 2017 15:52:51 -0500 Subject: [PATCH] add createPlugin; move cmds to library managers --- lib/core/engine.js | 12 ++++++++++- lib/core/plugin.js | 3 +++ lib/core/plugins.js | 9 ++++++++ lib/dashboard/console.js | 13 ------------ lib/index.js | 3 +++ lib/versions/library_manager.js | 37 +++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 lib/versions/library_manager.js diff --git a/lib/core/engine.js b/lib/core/engine.js index 7cbc199a3..fb648f2cc 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -7,6 +7,7 @@ let CodeGenerator = require('../contracts/code_generator.js'); let ServicesMonitor = require('./services_monitor.js'); let Pipeline = require('../pipeline/pipeline.js'); let Watch = require('../pipeline/watch.js'); +let LibraryManager = require('../versions/library_manager.js'); class Engine { constructor(options) { @@ -61,7 +62,8 @@ class Engine { "fileWatcher": this.fileWatchService, "webServer": this.webServerService, "ipfs": this.ipfsService, - "web3": this.web3Service + "web3": this.web3Service, + "libraryManager": this.libraryManagerService }; let service = services[serviceName]; @@ -206,6 +208,14 @@ class Engine { web3: this.web3 }); } + + libraryManagerService(options) { + let libraryManager = new LibraryManager({ + plugins: this.plugins, + config: this.config + }); + } + } module.exports = Engine; diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 7950706f0..871fbf614 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -44,6 +44,9 @@ Plugin.prototype.loadPluginFile = function(filename) { }; Plugin.prototype.pathToFile = function(filename) { + if (!this.pluginPath) { + throw new Error('pluginPath not defined for plugin: ' + this.name); + } return utils.joinPath(this.pluginPath, filename); }; diff --git a/lib/core/plugins.js b/lib/core/plugins.js index 6258de50a..bffd2d5d5 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -27,6 +27,15 @@ Plugins.prototype.listPlugins = function() { return list; }; +// for services that act as a plugin but have core functionality +Plugins.prototype.createPlugin = function(pluginName, pluginConfig) { + let plugin = {}; + let pluginPath = undefined; + var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config, isInternal: true}); + this.plugins.push(pluginWrapper); + return pluginWrapper; +}; + Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) { var pluginPath = utils.joinPath('../modules/', pluginName, 'index.js'); var plugin = require(pluginPath); diff --git a/lib/dashboard/console.js b/lib/dashboard/console.js index 22b3fe789..a1b6aa95c 100644 --- a/lib/dashboard/console.js +++ b/lib/dashboard/console.js @@ -28,19 +28,6 @@ class Console { 'The web3 object and the interfaces for the deployed contracts and their methods are also available' ]; return helpText.join('\n'); - } else if (cmd === 'versions') { - let solcVersionInConfig = this.contractsConfig.versions.solc; - let web3VersionInConfig = this.contractsConfig.versions["web3.js"]; - let ipfsApiVersion = require('../../package.json').dependencies["ipfs-api"]; - - let text = [ - 'versions in use:', - 'solc: ' + solcVersionInConfig, - 'web3.js: ' + web3VersionInConfig, - 'ipfs-api: ' + ipfsApiVersion - ]; - - return text.join('\n'); } else if (['quit', 'exit', 'sair', 'sortir'].indexOf(cmd) >= 0) { utils.exit(); } diff --git a/lib/index.js b/lib/index.js index 9e922ff98..b2f0e00f1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -98,6 +98,7 @@ class Embark { } engine.startMonitor(); + engine.startService("libraryManager"); engine.startService("web3"); engine.startService("pipeline"); engine.startService("codeGenerator"); @@ -158,10 +159,12 @@ class Embark { engine.logger.info("loaded plugins: " + pluginList.join(", ")); } + engine.startService("libraryManager"); engine.startService("web3"); engine.startService("pipeline"); engine.startService("codeGenerator"); engine.startService("deployment"); + engine.startService("ipfs"); callback(); }, function deploy(callback) { diff --git a/lib/versions/library_manager.js b/lib/versions/library_manager.js new file mode 100644 index 000000000..507ba3231 --- /dev/null +++ b/lib/versions/library_manager.js @@ -0,0 +1,37 @@ + +class LibraryManager { + + constructor(options) { + this.plugins = options.plugins; + this.config = options.config; + this.contractsConfig = this.config.contractsConfig; + + this.embark = this.plugins.createPlugin('libraryManager', {}); + + this.registerCommands(); + } + + registerCommands() { + const self = this; + this.embark.registerConsoleCommand((cmd, _options) => { + if (cmd === "versions") { + let solcVersionInConfig = self.contractsConfig.versions.solc; + let web3VersionInConfig = self.contractsConfig.versions["web3.js"]; + let ipfsApiVersion = require('../../package.json').dependencies["ipfs-api"]; + + let text = [ + 'versions in use:', + 'solc: ' + solcVersionInConfig, + 'web3.js: ' + web3VersionInConfig, + 'ipfs-api: ' + ipfsApiVersion + ]; + + return text.join('\n'); + } + return false; + }); + } + +} + +module.exports = LibraryManager;