supporting uploading dapp to swarm

This commit is contained in:
Iuri Matias 2017-01-07 16:52:29 -05:00
parent e8ef3ed8b7
commit 15b8d9b33e
4 changed files with 51 additions and 2 deletions

View File

@ -15,6 +15,7 @@ Cmd.prototype.process = function(args) {
this.simulator();
this.test();
this.ipfs();
this.swarm();
this.otherCommands();
program.parse(args);
};
@ -137,6 +138,7 @@ Cmd.prototype.test = function() {
});
};
// TODO: replace both of this with a deploy/upload command
Cmd.prototype.ipfs = function() {
var self = this;
program
@ -147,6 +149,16 @@ Cmd.prototype.ipfs = function() {
});
};
Cmd.prototype.swarm = function() {
var self = this;
program
.command('swarm')
.description('deploy to SWARM')
.action(function() {
self.Embark.swarm();
});
};
Cmd.prototype.otherCommands = function() {
program
.action(function(env){

View File

@ -23,6 +23,7 @@ var Monitor = require('./monitor.js');
var ServicesMonitor = require('./services.js');
var Console = require('./console.js');
var IPFS = require('./ipfs.js');
var Swarm = require('./swarm.js');
var Embark = {
@ -304,6 +305,12 @@ var Embark = {
ipfs: function() {
var ipfs = new IPFS({buildDir: 'dist/'});
ipfs.deploy();
},
// TODO: should deploy if it hasn't already
swarm: function() {
var swarm = new Swarm({buildDir: 'dist/'});
swarm.deploy();
}
};

View File

@ -13,8 +13,9 @@ IPFS.prototype.deploy = function() {
ipfs_bin = "~/go/bin/ipfs";
}
var cmd = ipfs_bin + " add -r " + build_dir;
console.log(("=== adding " + cmd + " to ipfs").green);
var cmd = ipfs_bin + " add -r " + this.buildDir;
console.log(("=== adding " + this.buildDir + " to ipfs").green);
console.log(cmd.green);
var result = exec(cmd);
var rows = result.output.split("\n");

29
lib/swarm.js Normal file
View File

@ -0,0 +1,29 @@
var colors = require('colors');
var Swarm = function(options) {
this.options = options;
this.buildDir = options.buildDir || 'dist/';
};
Swarm.prototype.deploy = function() {
var swarm_bin = exec('which swarm').output.split("\n")[0];
if (swarm_bin==='swarm not found' || swarm_bin === ''){
console.log('=== WARNING: Swarm not in an executable path. Guessing ~/go/bin/swarm for path'.yellow);
swarm_bin = "~/go/bin/swarm";
}
var cmd = swarm_bin + " --defaultpath " + this.buildDir + "index.html --recursive up " + this.buildDir;
console.log(("=== adding " + this.buildDir + " to swarm").green);
console.log(cmd.green);
var result = exec(cmd);
var rows = result.output.split("\n");
var dir_hash = rows.reverse()[1];
console.log(("=== DApp available at http://localhost:8500/bzz:/" + dir_hash + "/").green);
};
module.exports = Swarm;