From a1fa4ed30d7a9ed5f9025c2c1acab26936e491b6 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 20 Jul 2018 17:54:02 +0300 Subject: [PATCH] move storageUtils --- lib/processes/storageProcesses/ipfs.js | 3 +-- .../storageProcessesLauncher.js | 12 ++++++--- .../storageProcesses/storageUtils.js | 25 ------------------- lib/processes/storageProcesses/swarm.js | 3 +-- 4 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 lib/processes/storageProcesses/storageUtils.js diff --git a/lib/processes/storageProcesses/ipfs.js b/lib/processes/storageProcesses/ipfs.js index 00488a64..724a4772 100644 --- a/lib/processes/storageProcesses/ipfs.js +++ b/lib/processes/storageProcesses/ipfs.js @@ -1,7 +1,6 @@ const child_process = require('child_process'); const ProcessWrapper = require('../processWrapper'); const constants = require('../../constants'); -const StorageUtils = require('./storageUtils'); let ipfsProcess; // eslint-disable-line no-unused-vars @@ -10,7 +9,7 @@ class IPFSProcess extends ProcessWrapper { super(); this.cors = options.cors; - this.command = StorageUtils.getCommand('ipfs', options); + this.command = 'ipfs'; this.checkIPFSVersion(); this.startIPFSDaemon(); diff --git a/lib/processes/storageProcesses/storageProcessesLauncher.js b/lib/processes/storageProcesses/storageProcessesLauncher.js index 0e1cc1c9..6e7b2359 100644 --- a/lib/processes/storageProcesses/storageProcessesLauncher.js +++ b/lib/processes/storageProcesses/storageProcessesLauncher.js @@ -3,9 +3,13 @@ const shellJs = require('shelljs'); const utils = require('../../utils/utils'); const ProcessLauncher = require('../processLauncher'); const constants = require('../../constants'); -const StorageUtils = require('./storageUtils'); const {canonicalHost} = require('../../utils/host'); +let References = { + ipfs: 'https://ipfs.io/docs/install/', + swarm: 'http://swarm-guide.readthedocs.io/en/latest/installation.html' +} + class StorageProcessesLauncher { constructor(options) { this.logger = options.logger; @@ -89,10 +93,12 @@ class StorageProcessesLauncher { return callback(__('No process file for this storage type (%s) exists. Please start the process locally.', storageName)); } - const program = shellJs.which(StorageUtils.getCommand(storageName, self.storageConfig)); + let cmd = (storageName === 'swarm' ? (self.storageConfig.swarmPath || 'swarm') : 'ipfs'); + + const program = shellJs.which(cmd); if (!program) { self.logger.warn(__('{{storageName}} is not installed or your configuration is not right', {storageName}).yellow); - self.logger.info(__('You can install and get more information here: ').yellow + StorageUtils.getStorageInstallationSite(storageName).underline); + self.logger.info(__('You can install and get more information here: ').yellow + References[storageName].underline); return callback(__('%s not installed', storageName)); } diff --git a/lib/processes/storageProcesses/storageUtils.js b/lib/processes/storageProcesses/storageUtils.js deleted file mode 100644 index d701d2b7..00000000 --- a/lib/processes/storageProcesses/storageUtils.js +++ /dev/null @@ -1,25 +0,0 @@ -const IPFS = 'ipfs'; -const SWARM = 'swarm'; - -class StorageUtils { - static getCommand(storageName, config) { - if (storageName === IPFS) { - return IPFS; - } - if (storageName === SWARM) { - return config.swarmPath || SWARM; - } - return null; - } - - static getStorageInstallationSite(storageName) { - if (storageName === IPFS) { - return 'https://ipfs.io/docs/install/'; - } - if (storageName === SWARM) { - return 'http://swarm-guide.readthedocs.io/en/latest/installation.html'; - } - } -} - -module.exports = StorageUtils; diff --git a/lib/processes/storageProcesses/swarm.js b/lib/processes/storageProcesses/swarm.js index a5236f36..ac0ca9bb 100644 --- a/lib/processes/storageProcesses/swarm.js +++ b/lib/processes/storageProcesses/swarm.js @@ -2,7 +2,6 @@ const child_process = require('child_process'); const ProcessWrapper = require('../processWrapper'); const constants = require('../../constants'); const fs = require('../../core/fs'); -const StorageUtils = require('./storageUtils'); let swarmProcess; @@ -11,7 +10,7 @@ class SwarmProcess extends ProcessWrapper { super(); this.storageConfig = options.storageConfig; this.cors = options.cors; - this.command = StorageUtils.getCommand('swarm', this.storageConfig); + this.command = this.storageConfig.swarmPath || 'swarm'; } startSwarmDaemon() {