mirror of https://github.com/embarklabs/embark.git
refactor ipfs and swarm code
This commit is contained in:
parent
c53d92baa5
commit
26f2ad7407
28
lib/ipfs.js
28
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,17 +17,35 @@ IPFS.prototype.deploy = function() {
|
||||||
ipfs_bin = "~/go/bin/ipfs";
|
ipfs_bin = "~/go/bin/ipfs";
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd = ipfs_bin + " add -r " + this.buildDir;
|
return callback(null, ipfs_bin);
|
||||||
console.log(("=== adding " + this.buildDir + " 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);
|
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;
|
||||||
|
|
33
lib/swarm.js
33
lib/swarm.js
|
@ -1,4 +1,5 @@
|
||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
var Swarm = function(options) {
|
var Swarm = function(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -6,6 +7,9 @@ var Swarm = function(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Swarm.prototype.deploy = function() {
|
Swarm.prototype.deploy = function() {
|
||||||
|
var self = this;
|
||||||
|
async.waterfall([
|
||||||
|
function findBinary(callback) {
|
||||||
var swarm_bin = exec('which swarm').output.split("\n")[0];
|
var swarm_bin = exec('which swarm').output.split("\n")[0];
|
||||||
|
|
||||||
if (swarm_bin==='swarm not found' || swarm_bin === ''){
|
if (swarm_bin==='swarm not found' || swarm_bin === ''){
|
||||||
|
@ -13,17 +17,38 @@ Swarm.prototype.deploy = function() {
|
||||||
swarm_bin = "~/go/bin/swarm";
|
swarm_bin = "~/go/bin/swarm";
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd = swarm_bin + " --defaultpath " + this.buildDir + "index.html --recursive up " + this.buildDir;
|
return callback(null, swarm_bin);
|
||||||
console.log(("=== adding " + this.buildDir + " to swarm").green);
|
},
|
||||||
|
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);
|
console.log(cmd.green);
|
||||||
|
|
||||||
var result = exec(cmd);
|
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 rows = result.output.split("\n");
|
||||||
var dir_hash = rows.reverse()[1];
|
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);
|
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;
|
module.exports = Swarm;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue