mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-10 22:16:20 +00:00
refactor: get versions from module instead of config
This commit is contained in:
parent
dee49ec5ed
commit
11af38268b
@ -133,7 +133,6 @@ class Engine {
|
|||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
this.registerModule('solidity', {
|
this.registerModule('solidity', {
|
||||||
solcVersion: self.config.contractsConfig.versions.solc,
|
|
||||||
contractDirectories: self.config.contractDirectories
|
contractDirectories: self.config.contractDirectories
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ class Solidity {
|
|||||||
|
|
||||||
constructor(embark, options) {
|
constructor(embark, options) {
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.solcVersion = options.solcVersion;
|
this.events = embark.events;
|
||||||
this.contractDirectories = options.contractDirectories;
|
this.contractDirectories = options.contractDirectories;
|
||||||
|
|
||||||
embark.registerCompiler(".sol", this.compile_solidity.bind(this));
|
embark.registerCompiler(".sol", this.compile_solidity.bind(this));
|
||||||
@ -37,7 +37,7 @@ class Solidity {
|
|||||||
},
|
},
|
||||||
function loadCompiler(callback) {
|
function loadCompiler(callback) {
|
||||||
// TODO: there ino need to load this twice
|
// 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()) {
|
if (solcW.isCompilerLoaded()) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,12 @@ let currentSolcVersion = require('../../../package.json').dependencies.solc;
|
|||||||
class SolcW {
|
class SolcW {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.solcVersion = options.solcVersion;
|
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
|
this.events = options.events;
|
||||||
}
|
}
|
||||||
|
|
||||||
load_compiler(done) {
|
load_compiler(done) {
|
||||||
|
const self = this;
|
||||||
if (compilerLoaded) {
|
if (compilerLoaded) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@ -24,11 +25,13 @@ class SolcW {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.solcVersion === currentSolcVersion) {
|
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'});
|
solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'});
|
||||||
} else {
|
} else {
|
||||||
let npm = new Npm({logger: this.logger});
|
let npm = new Npm({logger: self.logger});
|
||||||
npm.getPackageVersion('solc', this.solcVersion, false, false, function(err, location) {
|
npm.getPackageVersion('solc', solcVersion, false, false, function(err, location) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
@ -36,7 +39,7 @@ class SolcW {
|
|||||||
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
|
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
isCompilerLoaded() {
|
isCompilerLoaded() {
|
||||||
|
@ -8,30 +8,48 @@ class LibraryManager {
|
|||||||
|
|
||||||
this.embark = this.plugins.createPlugin('libraryManager', {});
|
this.embark = this.plugins.createPlugin('libraryManager', {});
|
||||||
|
|
||||||
|
this.determineVersions();
|
||||||
|
|
||||||
this.registerCommands();
|
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() {
|
registerCommands() {
|
||||||
const self = this;
|
const self = this;
|
||||||
this.embark.registerConsoleCommand((cmd, _options) => {
|
this.embark.registerConsoleCommand((cmd, _options) => {
|
||||||
if (cmd === "versions") {
|
if (cmd === "versions") {
|
||||||
let solcVersionInConfig = self.contractsConfig.versions.solc;
|
let text = ['versions in use:'];
|
||||||
let web3VersionInConfig = self.contractsConfig.versions["web3.js"];
|
for (let lib in self.versions) {
|
||||||
let ipfsApiVersion = require('../../package.json').dependencies["ipfs-api"];
|
text.push(lib + ": " + self.versions[lib]);
|
||||||
|
}
|
||||||
let text = [
|
|
||||||
'versions in use:',
|
|
||||||
'solc: ' + solcVersionInConfig,
|
|
||||||
'web3.js: ' + web3VersionInConfig,
|
|
||||||
'ipfs-api: ' + ipfsApiVersion
|
|
||||||
];
|
|
||||||
|
|
||||||
return text.join('\n');
|
return text.join('\n');
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
module.exports = LibraryManager;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user