diff --git a/lib/core/engine.js b/lib/core/engine.js index fb648f2c..53bb03b9 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -133,7 +133,6 @@ class Engine { let self = this; this.registerModule('solidity', { - solcVersion: self.config.contractsConfig.versions.solc, contractDirectories: self.config.contractDirectories }); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 0270214a..6860bab5 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -5,7 +5,7 @@ class Solidity { constructor(embark, options) { this.logger = embark.logger; - this.solcVersion = options.solcVersion; + this.events = embark.events; this.contractDirectories = options.contractDirectories; embark.registerCompiler(".sol", this.compile_solidity.bind(this)); @@ -37,7 +37,7 @@ class Solidity { }, function loadCompiler(callback) { // TODO: there ino need to load this twice - solcW = new SolcW({logger: self.logger, solcVersion: self.solcVersion}); + solcW = new SolcW({logger: self.logger, events: self.events}); if (solcW.isCompilerLoaded()) { return callback(); } diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index aecf6674..a7c1d6eb 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -7,11 +7,12 @@ let currentSolcVersion = require('../../../package.json').dependencies.solc; class SolcW { constructor(options) { - this.solcVersion = options.solcVersion; this.logger = options.logger; + this.events = options.events; } load_compiler(done) { + const self = this; if (compilerLoaded) { done(); } @@ -24,19 +25,21 @@ class SolcW { done(); }); - if (this.solcVersion === currentSolcVersion) { - solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'}); - } else { - let npm = new Npm({logger: this.logger}); - npm.getPackageVersion('solc', this.solcVersion, false, false, function(err, location) { - if (err) { - return done(err); - } - let requirePath = utils.joinPath(process.env.PWD, location); - solcProcess.send({action: 'loadCompiler', solcLocation: requirePath}); - }); - } - + this.events.request("version:get:solc", function(solcVersion) { + self.logger.info("detected version is " + solcVersion); + if (self.solcVersion === currentSolcVersion) { + solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'}); + } else { + let npm = new Npm({logger: self.logger}); + npm.getPackageVersion('solc', solcVersion, false, false, function(err, location) { + if (err) { + return done(err); + } + let requirePath = utils.joinPath(process.env.PWD, location); + solcProcess.send({action: 'loadCompiler', solcLocation: requirePath}); + }); + } + }); } isCompilerLoaded() { diff --git a/lib/versions/library_manager.js b/lib/versions/library_manager.js index 507ba323..ad6f6b23 100644 --- a/lib/versions/library_manager.js +++ b/lib/versions/library_manager.js @@ -8,30 +8,48 @@ class LibraryManager { this.embark = this.plugins.createPlugin('libraryManager', {}); + this.determineVersions(); + this.registerCommands(); + this.listenToCommands(); + } + + determineVersions() { + this.versions = {}; + + let solcVersionInConfig = this.contractsConfig.versions.solc; + let web3VersionInConfig = this.contractsConfig.versions["web3.js"]; + let ipfsApiVersion = require('../../package.json').dependencies["ipfs-api"]; + + this.versions['solc'] = solcVersionInConfig; + this.versions['web3'] = web3VersionInConfig; + this.versions['ipfs-api'] = ipfsApiVersion; } 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 - ]; - + let text = ['versions in use:']; + for (let lib in self.versions) { + text.push(lib + ": " + self.versions[lib]); + } return text.join('\n'); } return false; }); } + listenToCommands() { + const self = this; + for (let libName in this.versions) { + let lib = self.versions[libName]; + this.embark.events.setCommandHandler('version:get:' + libName, (cb) => { + cb(lib); + }); + } + } + } module.exports = LibraryManager;