move storageUtils

This commit is contained in:
Iuri Matias 2018-07-20 17:54:02 +03:00
parent a47d09b763
commit feda245b3e
4 changed files with 11 additions and 32 deletions

View File

@ -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();

View File

@ -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));
}

View File

@ -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;

View File

@ -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() {