2017-12-30 23:25:59 +00:00
|
|
|
var Npm = require('./npm.js');
|
2017-12-30 20:52:51 +00:00
|
|
|
|
|
|
|
class LibraryManager {
|
|
|
|
|
|
|
|
constructor(options) {
|
|
|
|
this.plugins = options.plugins;
|
|
|
|
this.config = options.config;
|
|
|
|
this.contractsConfig = this.config.contractsConfig;
|
2018-01-10 16:15:32 +00:00
|
|
|
this.storageConfig = this.config.storageConfig;
|
2017-12-30 20:52:51 +00:00
|
|
|
|
|
|
|
this.embark = this.plugins.createPlugin('libraryManager', {});
|
|
|
|
|
2017-12-30 21:48:53 +00:00
|
|
|
this.determineVersions();
|
|
|
|
|
2017-12-30 20:52:51 +00:00
|
|
|
this.registerCommands();
|
2017-12-30 23:12:16 +00:00
|
|
|
this.listenToCommandsToGetVersions();
|
|
|
|
this.listenToCommandsToGetLibrary();
|
2017-12-30 21:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
determineVersions() {
|
|
|
|
this.versions = {};
|
|
|
|
|
|
|
|
let solcVersionInConfig = this.contractsConfig.versions.solc;
|
|
|
|
let web3VersionInConfig = this.contractsConfig.versions["web3.js"];
|
2018-01-10 16:15:32 +00:00
|
|
|
let ipfsApiVersion = this.storageConfig.versions["ipfs-api"];
|
2017-12-30 21:48:53 +00:00
|
|
|
|
|
|
|
this.versions['solc'] = solcVersionInConfig;
|
|
|
|
this.versions['web3'] = web3VersionInConfig;
|
|
|
|
this.versions['ipfs-api'] = ipfsApiVersion;
|
2017-12-30 20:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
registerCommands() {
|
|
|
|
const self = this;
|
|
|
|
this.embark.registerConsoleCommand((cmd, _options) => {
|
|
|
|
if (cmd === "versions") {
|
2017-12-30 21:48:53 +00:00
|
|
|
let text = ['versions in use:'];
|
|
|
|
for (let lib in self.versions) {
|
|
|
|
text.push(lib + ": " + self.versions[lib]);
|
|
|
|
}
|
2017-12-30 20:52:51 +00:00
|
|
|
return text.join('\n');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-30 23:12:16 +00:00
|
|
|
listenToCommandsToGetVersions() {
|
2017-12-30 21:48:53 +00:00
|
|
|
const self = this;
|
|
|
|
for (let libName in this.versions) {
|
|
|
|
let lib = self.versions[libName];
|
|
|
|
this.embark.events.setCommandHandler('version:get:' + libName, (cb) => {
|
|
|
|
cb(lib);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-30 23:12:16 +00:00
|
|
|
listenToCommandsToGetLibrary() {
|
|
|
|
let npm = new Npm({logger: this.embark.logger});
|
2017-12-31 00:34:15 +00:00
|
|
|
this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => {
|
2017-12-30 23:25:59 +00:00
|
|
|
npm.getPackageVersion(libName, version, false, false, cb);
|
|
|
|
});
|
2017-12-31 00:34:15 +00:00
|
|
|
this.embark.events.setCommandHandler('version:getPackageContent', (libName, version, cb) => {
|
2017-12-30 23:25:59 +00:00
|
|
|
npm.getPackageVersion(libName, version, false, true, cb);
|
2017-12-30 23:12:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-30 20:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = LibraryManager;
|