Merge branch 'develop' of github.com:iurimatias/embark-framework into develop
This commit is contained in:
commit
cff999def8
|
@ -148,7 +148,7 @@ class Cmd {
|
|||
upload() {
|
||||
program
|
||||
.command('upload [platform] [environment]')
|
||||
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
||||
.description('upload your dapp to a decentralized storage (e.g embark upload ipfs)')
|
||||
.action(function (platform, env, _options) {
|
||||
// TODO: get env in cmd line as well
|
||||
embark.initConfig(env || 'development', {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
let Web3 = require('web3');
|
||||
let utils = require('../utils/utils.js');
|
||||
let Events = require('./events.js');
|
||||
let Logger = require('./logger.js');
|
||||
let Config = require('./config.js');
|
||||
|
@ -169,52 +168,11 @@ class Engine {
|
|||
}
|
||||
|
||||
ipfsService(_options) {
|
||||
let self = this;
|
||||
|
||||
let storageConfig = this.config.storageConfig;
|
||||
if (!storageConfig.enabled) {
|
||||
return;
|
||||
}
|
||||
if (storageConfig.provider !== 'ipfs' && storageConfig.available_providers.indexOf("ipfs") < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let host = _options.host || storageConfig.host;
|
||||
let port = _options.port || storageConfig.port;
|
||||
|
||||
self.events.on('check:backOnline:IPFS', function () {
|
||||
self.logger.info('IPFS node detected..');
|
||||
});
|
||||
|
||||
self.servicesMonitor.addCheck('IPFS', function (cb) {
|
||||
utils.checkIsAvailable('http://' + host + ':' + port, function (available) {
|
||||
if (available) {
|
||||
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
||||
//The URL should also be flexible to accept non-default IPFS url
|
||||
self.logger.trace("Checking IPFS version...");
|
||||
utils.httpGet('http://' + host + ':' + port + '/api/v0/version', function (err, body) {
|
||||
if (err) {
|
||||
self.logger.trace("Check IPFS version error: " + err);
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
try {
|
||||
let parsed = JSON.parse(body);
|
||||
if (parsed.Version) {
|
||||
return cb({name: ("IPFS " + parsed.Version), status: 'on'});
|
||||
}
|
||||
else {
|
||||
return cb({name: "IPFS ", status: 'on'});
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
});
|
||||
this.registerModule('ipfs', {
|
||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
||||
storageConfig: this.config.storageConfig,
|
||||
host: _options.host,
|
||||
port: _options.port
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ var Plugin = function(options) {
|
|||
this.compilers = [];
|
||||
this.serviceChecks = [];
|
||||
this.pluginTypes = [];
|
||||
this.uploadCmds = [];
|
||||
this.logger = options.logger;
|
||||
this.events = options.events;
|
||||
this.config = options.config;
|
||||
|
@ -136,6 +137,11 @@ Plugin.prototype.registerCompiler = function(extension, cb) {
|
|||
this.pluginTypes.push('compilers');
|
||||
};
|
||||
|
||||
Plugin.prototype.registerUploadCommand = function(cmd, cb) {
|
||||
this.uploadCmds.push({cmd: cmd, cb: cb});
|
||||
this.pluginTypes.push('uploadCmds');
|
||||
};
|
||||
|
||||
Plugin.prototype.runCommands = function(cmd, options) {
|
||||
return this.console.map(function(cb) {
|
||||
return cb.call(this, cmd, options);
|
||||
|
|
27
lib/index.js
27
lib/index.js
|
@ -6,9 +6,6 @@ require('colors');
|
|||
|
||||
let Engine = require('./core/engine.js');
|
||||
|
||||
let IPFS = require('./upload/ipfs.js');
|
||||
let Swarm = require('./upload/swarm.js');
|
||||
|
||||
let version = require('../package.json').version;
|
||||
|
||||
class Embark {
|
||||
|
@ -191,12 +188,24 @@ class Embark {
|
|||
|
||||
// TODO: should deploy if it hasn't already
|
||||
upload(platform) {
|
||||
if (platform === 'ipfs') {
|
||||
let ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
||||
ipfs.deploy();
|
||||
} else if (platform === 'swarm') {
|
||||
let swarm = new Swarm({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
||||
swarm.deploy();
|
||||
let options = {
|
||||
buildDir: 'dist/',
|
||||
storageConfig: this.config.storageConfig
|
||||
};
|
||||
|
||||
this.plugins.loadInternalPlugin('ipfs', options);
|
||||
this.plugins.loadInternalPlugin('swarm', options);
|
||||
|
||||
let cmdPlugins = this.plugins.getPluginsFor('uploadCmds');
|
||||
let cmdPlugin;
|
||||
if (cmdPlugins.length > 0) {
|
||||
cmdPlugin = cmdPlugins.find((pluginCmd) => {
|
||||
return pluginCmd.name == platform;
|
||||
});
|
||||
}
|
||||
|
||||
if (cmdPlugin) {
|
||||
cmdPlugin.uploadCmds[0].cb();
|
||||
} else {
|
||||
console.log(("unknown platform: " + platform).red);
|
||||
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
let UploadIPFS = require('./upload.js');
|
||||
let utils = require('../../utils/utils.js');
|
||||
|
||||
class IPFS {
|
||||
|
||||
constructor(embark, options) {
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.buildDir = options.buildDir;
|
||||
this.storageConfig = options.storageConfig;
|
||||
this.host = options.host || this.storageConfig.host;
|
||||
this.port = options.port || this.storageConfig.port;
|
||||
this.addCheck = options.addCheck;
|
||||
this.embark = embark;
|
||||
|
||||
this.commandlineDeploy();
|
||||
this.setServiceCheck();
|
||||
}
|
||||
|
||||
commandlineDeploy() {
|
||||
let upload_ipfs = new UploadIPFS({
|
||||
buildDir: this.buildDir || 'dist/',
|
||||
storageConfig: this.storageConfig,
|
||||
configIpfsBin: this.storageConfig.ipfs_bin || "ipfs"
|
||||
});
|
||||
|
||||
this.embark.registerUploadCommand('ipfs', upload_ipfs.deploy.bind(upload_ipfs));
|
||||
}
|
||||
|
||||
setServiceCheck() {
|
||||
let self = this;
|
||||
|
||||
let storageConfig = this.storageConfig;
|
||||
|
||||
if (!storageConfig.enabled) {
|
||||
return;
|
||||
}
|
||||
if (storageConfig.provider !== 'ipfs' && storageConfig.available_providers.indexOf("ipfs") < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.events.on('check:backOnline:IPFS', function () {
|
||||
self.logger.info('IPFS node detected..');
|
||||
});
|
||||
|
||||
self.events.on('check:wentOffline:IPFS', function () {
|
||||
self.logger.info('IPFS node is offline..');
|
||||
});
|
||||
|
||||
let server = 'http://' + this.host + ':' + this.port;
|
||||
self.logger.info(server);
|
||||
|
||||
this.addCheck('IPFS', function (cb) {
|
||||
utils.checkIsAvailable(server, function (available) {
|
||||
if (available) {
|
||||
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
||||
//The URL should also be flexible to accept non-default IPFS url
|
||||
self.logger.trace("Checking IPFS version...");
|
||||
utils.httpGet(server + '/api/v0/version', function (err, body) {
|
||||
if (err) {
|
||||
self.logger.trace("Check IPFS version error: " + err);
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
try {
|
||||
let parsed = JSON.parse(body);
|
||||
if (parsed.Version) {
|
||||
return cb({name: ("IPFS " + parsed.Version), status: 'on'});
|
||||
}
|
||||
else {
|
||||
return cb({name: "IPFS ", status: 'on'});
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = IPFS;
|
|
@ -7,12 +7,12 @@ class IPFS {
|
|||
constructor(options) {
|
||||
this.options = options;
|
||||
this.buildDir = options.buildDir || 'dist/';
|
||||
this.plugins = options.plugins;
|
||||
this.storageConfig = options.storageConfig;
|
||||
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
||||
}
|
||||
|
||||
deploy() {
|
||||
console.log("deploying!");
|
||||
let self = this;
|
||||
async.waterfall([
|
||||
function findBinary(callback) {
|
|
@ -0,0 +1,19 @@
|
|||
let UploadSwarm = require('./upload.js');
|
||||
|
||||
class Swarm {
|
||||
|
||||
constructor(embark, options) {
|
||||
this.logger = embark.logger;
|
||||
|
||||
this.upload_swarm = new UploadSwarm({
|
||||
buildDir: options.buildDir || 'dist/',
|
||||
storageConfig: options.storageConfig
|
||||
});
|
||||
|
||||
embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Swarm;
|
||||
|
Loading…
Reference in New Issue