mirror of https://github.com/embarklabs/embark.git
Merge branch 'swarm' into develop
This commit is contained in:
commit
d1cb5266ca
16
lib/cmd.js
16
lib/cmd.js
|
@ -14,7 +14,7 @@ Cmd.prototype.process = function(args) {
|
||||||
this.blockchain();
|
this.blockchain();
|
||||||
this.simulator();
|
this.simulator();
|
||||||
this.test();
|
this.test();
|
||||||
this.ipfs();
|
this.upload();
|
||||||
this.otherCommands();
|
this.otherCommands();
|
||||||
program.parse(args);
|
program.parse(args);
|
||||||
};
|
};
|
||||||
|
@ -137,13 +137,17 @@ Cmd.prototype.test = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.ipfs = function() {
|
Cmd.prototype.upload = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
program
|
program
|
||||||
.command('ipfs')
|
.command('upload [platform]')
|
||||||
.description('deploy to IPFS')
|
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
||||||
.action(function() {
|
.action(function(platform ,options) {
|
||||||
self.Embark.ipfs();
|
// TODO: get env in cmd line as well
|
||||||
|
self.Embark.initConfig('development', {
|
||||||
|
embarkConfig: 'embark.json'
|
||||||
|
});
|
||||||
|
self.Embark.upload(platform);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
11
lib/index.js
11
lib/index.js
|
@ -23,6 +23,7 @@ var Monitor = require('./monitor.js');
|
||||||
var ServicesMonitor = require('./services.js');
|
var ServicesMonitor = require('./services.js');
|
||||||
var Console = require('./console.js');
|
var Console = require('./console.js');
|
||||||
var IPFS = require('./ipfs.js');
|
var IPFS = require('./ipfs.js');
|
||||||
|
var Swarm = require('./swarm.js');
|
||||||
|
|
||||||
var Embark = {
|
var Embark = {
|
||||||
|
|
||||||
|
@ -301,10 +302,18 @@ var Embark = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: should deploy if it hasn't already
|
// TODO: should deploy if it hasn't already
|
||||||
ipfs: function() {
|
upload: function(platform) {
|
||||||
|
if (platform === 'ipfs') {
|
||||||
var ipfs = new IPFS({buildDir: 'dist/'});
|
var ipfs = new IPFS({buildDir: 'dist/'});
|
||||||
ipfs.deploy();
|
ipfs.deploy();
|
||||||
|
} else if (platform === 'swarm') {
|
||||||
|
var swarm = new Swarm({buildDir: 'dist/'});
|
||||||
|
swarm.deploy();
|
||||||
|
} else {
|
||||||
|
console.log(("unknown platform: " + platform).red);
|
||||||
|
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
29
lib/ipfs.js
29
lib/ipfs.js
|
@ -1,4 +1,5 @@
|
||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
var IPFS = function(options) {
|
var IPFS = function(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -6,6 +7,9 @@ var IPFS = function(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
IPFS.prototype.deploy = function() {
|
IPFS.prototype.deploy = function() {
|
||||||
|
var self = this;
|
||||||
|
async.waterfall([
|
||||||
|
function findBinary(callback) {
|
||||||
var ipfs_bin = exec('which ipfs').output.split("\n")[0];
|
var ipfs_bin = exec('which ipfs').output.split("\n")[0];
|
||||||
|
|
||||||
if (ipfs_bin==='ipfs not found'){
|
if (ipfs_bin==='ipfs not found'){
|
||||||
|
@ -13,16 +17,35 @@ IPFS.prototype.deploy = function() {
|
||||||
ipfs_bin = "~/go/bin/ipfs";
|
ipfs_bin = "~/go/bin/ipfs";
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd = ipfs_bin + " add -r " + build_dir;
|
return callback(null, ipfs_bin);
|
||||||
console.log(("=== adding " + cmd + " to ipfs").green);
|
},
|
||||||
|
function runCommand(ipfs_bin, callback) {
|
||||||
|
var cmd = ipfs_bin + " add -r " + self.buildDir;
|
||||||
|
console.log(("=== adding " + self.buildDir + " to ipfs").green);
|
||||||
|
console.log(cmd.green);
|
||||||
var result = exec(cmd);
|
var result = exec(cmd);
|
||||||
|
|
||||||
|
return callback(null, result);
|
||||||
|
},
|
||||||
|
function getHashFromOutput(result, callback) {
|
||||||
var rows = result.output.split("\n");
|
var rows = result.output.split("\n");
|
||||||
var dir_row = rows[rows.length - 2];
|
var dir_row = rows[rows.length - 2];
|
||||||
var dir_hash = dir_row.split(" ")[1];
|
var dir_hash = dir_row.split(" ")[1];
|
||||||
|
|
||||||
|
return callback(null, dir_hash);
|
||||||
|
},
|
||||||
|
function printUrls(dir_hash, callback) {
|
||||||
console.log(("=== DApp available at http://localhost:8080/ipfs/" + dir_hash + "/").green);
|
console.log(("=== DApp available at http://localhost:8080/ipfs/" + dir_hash + "/").green);
|
||||||
console.log(("=== DApp available at http://gateway.ipfs.io/ipfs/" + dir_hash + "/").green);
|
console.log(("=== DApp available at http://gateway.ipfs.io/ipfs/" + dir_hash + "/").green);
|
||||||
|
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
], function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
console.log("error uploading to ipfs".red);
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = IPFS;
|
module.exports = IPFS;
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
var colors = require('colors');
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
var Swarm = function(options) {
|
||||||
|
this.options = options;
|
||||||
|
this.buildDir = options.buildDir || 'dist/';
|
||||||
|
};
|
||||||
|
|
||||||
|
Swarm.prototype.deploy = function() {
|
||||||
|
var self = this;
|
||||||
|
async.waterfall([
|
||||||
|
function findBinary(callback) {
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(null, swarm_bin);
|
||||||
|
},
|
||||||
|
function runCommand(swarm_bin, callback) {
|
||||||
|
var cmd = swarm_bin + " --defaultpath " + self.buildDir + "index.html --recursive up " + self.buildDir;
|
||||||
|
console.log(("=== adding " + self.buildDir + " to swarm").green);
|
||||||
|
console.log(cmd.green);
|
||||||
|
var result = exec(cmd);
|
||||||
|
|
||||||
|
return callback(null, result);
|
||||||
|
},
|
||||||
|
function getHashFromOutput(result, callback) {
|
||||||
|
if (result.code !== 0) {
|
||||||
|
return callback("couldn't upload, is the swarm daemon running?");
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows = result.output.split("\n");
|
||||||
|
var dir_hash = rows.reverse()[1];
|
||||||
|
|
||||||
|
return callback(null, dir_hash);
|
||||||
|
},
|
||||||
|
function printUrls(dir_hash, callback) {
|
||||||
|
console.log(("=== DApp available at http://localhost:8500/bzz:/" + dir_hash + "/").green);
|
||||||
|
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
], function(err, result) {
|
||||||
|
if (err) {
|
||||||
|
console.log("error uploading to swarm".red);
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Swarm;
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
"serve-static": "^1.11.1",
|
"serve-static": "^1.11.1",
|
||||||
"shelljs": "^0.5.0",
|
"shelljs": "^0.5.0",
|
||||||
"toposort": "^0.2.10",
|
"toposort": "^0.2.10",
|
||||||
"web3": "^0.15.0",
|
"web3": "^0.18.0",
|
||||||
"wrench": "^1.5.8"
|
"wrench": "^1.5.8"
|
||||||
},
|
},
|
||||||
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
||||||
|
|
Loading…
Reference in New Issue