diff --git a/lib/core/config.js b/lib/core/config.js index 44cecab1c..1f31300a9 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -115,6 +115,9 @@ Config.prototype.loadContractsConfigFile = function() { Config.prototype.loadStorageConfigFile = function() { var configObject = { "default": { + "versions": { + "ipfs-api": "17.2.4" + }, "enabled": true, "available_providers": ["ipfs"], "ipfs_bin": "ipfs", diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 871fbf614..c1be1a9f4 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -21,6 +21,7 @@ var Plugin = function(options) { this.serviceChecks = []; this.pluginTypes = []; this.uploadCmds = []; + this.imports = []; this.embarkjs_code = []; this.embarkjs_init_code = {}; this.logger = options.logger; @@ -158,6 +159,11 @@ Plugin.prototype.addProviderInit = function(providerType, code, initCondition) { this.pluginTypes.push('initCode'); }; +Plugin.prototype.registerImportFile = function(importName, importLocation) { + this.imports.push([importName, importLocation]); + this.pluginTypes.push('imports'); +}; + Plugin.prototype.runFilePipeline = function() { var self = this; diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index f4be19ed8..2a09d03c1 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -66,6 +66,7 @@ class IPFS { } addIPFSToEmbarkJS() { + const self = this; // TODO: make this a shouldAdd condition if (this.storageConfig === {}) { return; @@ -75,6 +76,15 @@ class IPFS { return; } + self.events.request("version:get:ipfs-api", function(ipfsApiVersion) { + let currentIpfsApiVersion = require('../../../package.json').dependencies["ipfs-api"]; + if (ipfsApiVersion !== currentIpfsApiVersion) { + self.events.request("version:getPackageLocation", "ipfs-api", ipfsApiVersion, function(err, location) { + self.embark.registerImportFile("ipfs-api", utils.joinPath(process.env.PWD, location)); + }); + } + }); + let code = ""; code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString(); code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);"; diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 559a1a4c8..5c6111662 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -39,9 +39,10 @@ class Pipeline { importsList["Embark/EmbarkJS"] = utils.joinPath(fs.dappPath(), ".embark", 'embark.js'); importsList["Embark/web3"] = utils.joinPath(fs.dappPath(), ".embark", 'web3_instance.js'); - //importsList["ipfs-api"] = utils.joinPath(fs.dappPath(), ".embark", 'ipfs_api.js'); - - //importsList["Embark/libs/IpfsApi"] = fs.embarkPath('js/ipfs.js'); + self.plugins.getPluginsProperty('imports', 'imports').forEach(function (importObject) { + let [importName, importLocation] = importObject; + importsList[importName] = importLocation; + }); async.waterfall([ function findImports(next) { diff --git a/lib/versions/library_manager.js b/lib/versions/library_manager.js index 9436eb019..cba75a8a4 100644 --- a/lib/versions/library_manager.js +++ b/lib/versions/library_manager.js @@ -6,6 +6,7 @@ class LibraryManager { this.plugins = options.plugins; this.config = options.config; this.contractsConfig = this.config.contractsConfig; + this.storageConfig = this.config.storageConfig; this.embark = this.plugins.createPlugin('libraryManager', {}); @@ -21,7 +22,7 @@ class LibraryManager { let solcVersionInConfig = this.contractsConfig.versions.solc; let web3VersionInConfig = this.contractsConfig.versions["web3.js"]; - let ipfsApiVersion = require('../../package.json').dependencies["ipfs-api"]; + let ipfsApiVersion = this.storageConfig.versions["ipfs-api"]; this.versions['solc'] = solcVersionInConfig; this.versions['web3'] = web3VersionInConfig; diff --git a/test_app/config/storage.json b/test_app/config/storage.json index 6faf0e1af..a21b4cdef 100644 --- a/test_app/config/storage.json +++ b/test_app/config/storage.json @@ -1,5 +1,8 @@ { "default": { + "versions": { + "ipfs-api": "17.2.6" + }, "enabled": true, "available_providers": ["ipfs"], "ipfs_bin": "ipfs",