supporting uploading dapp to swarm
This commit is contained in:
parent
e8ef3ed8b7
commit
15b8d9b33e
12
lib/cmd.js
12
lib/cmd.js
|
@ -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){
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue