embark/lib/ipfs.js

31 lines
921 B
JavaScript
Raw Normal View History

2016-10-02 21:04:22 +00:00
var colors = require('colors');
2016-10-02 21:04:22 +00:00
var IPFS = function(options) {
this.options = options;
this.buildDir = options.buildDir || 'dist/';
};
IPFS.prototype.deploy = function() {
var ipfs_bin = exec('which ipfs').output.split("\n")[0];
if (ipfs_bin==='ipfs not found'){
2016-10-02 21:04:22 +00:00
console.log('=== WARNING: IPFS not in an executable path. Guessing ~/go/bin/ipfs for path'.yellow);
ipfs_bin = "~/go/bin/ipfs";
}
2017-01-07 21:52:29 +00:00
var cmd = ipfs_bin + " add -r " + this.buildDir;
console.log(("=== adding " + this.buildDir + " to ipfs").green);
console.log(cmd.green);
2016-10-02 21:04:22 +00:00
var result = exec(cmd);
var rows = result.output.split("\n");
var dir_row = rows[rows.length - 2];
var dir_hash = dir_row.split(" ")[1];
2016-10-02 21:04:22 +00:00
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);
};
2016-10-02 21:04:22 +00:00
module.exports = IPFS;
2016-10-02 20:58:52 +00:00