From 90ea1f0c27fa9e4c6009362f2d4cdceef21d9441 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 30 Jul 2019 11:49:45 -0400 Subject: [PATCH] generate embarkjs storage artifact --- packages/embark-ipfs/src/index.js | 29 +++++++++++++++++++------- packages/embark/src/lib/core/engine.js | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/embark-ipfs/src/index.js b/packages/embark-ipfs/src/index.js index 3f030ade9..3dc74cca5 100644 --- a/packages/embark-ipfs/src/index.js +++ b/packages/embark-ipfs/src/index.js @@ -15,19 +15,14 @@ class IPFS { this.logger = embark.logger; this.events = embark.events; this.logger = embark.logger; - // this.buildDir = options.buildDir; this.embarkConfig = embark.config.embarkConfig; this.config = embark.config; - // this.namesystemConfig = embark.config.namesystemConfig; this.storageConfig = embark.config.storageConfig; this.blockchainConfig = embark.config.blockchainConfig; this.webServerConfig = embark.config.webServerConfig; this.embark = embark; this.fs = embark.fs; - // this.addedToConsole = false; this.storageProcessesLauncher = null; - // this.usingRunningNode = false; - // this.modulesPath = dappPath(embark.config.embarkConfig.generationDir, constants.dappArtifacts.symlinkDir); this.registered = false; this.events.request("runcode:whitelist", 'ipfs-api', () => { }); @@ -36,12 +31,14 @@ class IPFS { this.events.on("storage:started", this.registerIpfsObject.bind(this)); this.events.on("storage:started", this.connectEmbarkJSProvider.bind(this)); + let plugin = options.plugins.createPlugin('ipfsplugin', {}); + plugin.registerActionForEvent("pipeline:generateAll:before", this.addEmbarkJSIpfsArtifact.bind(this)); + this.events.request("storage:node:register", "ipfs", (readyCb) => { console.dir("--- ipfs readyCb") console.dir('--- registering ipfs node') this.events.request('processes:register', 'storage', { launchFn: (cb) => { - // this.startProcess(readyCb); this.startProcess(cb); }, stopFn: (cb) => { this.stopProcess(cb); } @@ -67,10 +64,26 @@ class IPFS { } // TODO: - // ipfs plugin - // * register upload command // * generate embarkjs storage artifact + async addEmbarkJSIpfsArtifact(params, cb) { + const code = ` + var EmbarkJS; + if (typeof EmbarkJS === 'undefined') { + EmbarkJS = require('embarkjs'); + } + const __embarkIPFS = require('embarkjs-ipfs'); + EmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS); + EmbarkJS.Storage.setProviders(${JSON.stringify(this.embark.config.storageConfig.dappConnection || [])}, {web3}); + `; + this.events.request("pipeline:register", { + path: [this.embarkConfig.generationDir, 'storage'], + file: 'init.js', + format: 'js', + content: code + }, cb); + } + async registerIpfsObject() { const { host, port } = this._getNodeUrlConfig(); let ipfs = IpfsApi(host, port); diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index 69661e0c4..94bba6f9c 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -193,7 +193,7 @@ class Engine { storageComponent() { this.registerModulePackage('embark-storage', {plugins: this.plugins}); - this.registerModulePackage('embark-ipfs'); + this.registerModulePackage('embark-ipfs', {plugins: this.plugins}); } startService(serviceName, _options) {