refactor: get versions from module instead of config

This commit is contained in:
Iuri Matias 2017-12-30 16:48:53 -05:00
parent dee49ec5ed
commit 11af38268b
4 changed files with 48 additions and 28 deletions

View File

@ -133,7 +133,6 @@ class Engine {
let self = this;
this.registerModule('solidity', {
solcVersion: self.config.contractsConfig.versions.solc,
contractDirectories: self.config.contractDirectories
});

View File

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

View File

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

View File

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