2017-12-05 23:14:46 +00:00
|
|
|
require('colors');
|
2017-03-29 17:50:05 +00:00
|
|
|
let async = require('async');
|
2017-01-07 21:52:29 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
class Swarm {
|
|
|
|
constructor(options) {
|
|
|
|
this.options = options;
|
|
|
|
this.buildDir = options.buildDir || 'dist/';
|
2018-08-16 10:41:18 +00:00
|
|
|
this.swarm = options.swarm;
|
2018-09-10 06:27:19 +00:00
|
|
|
this.providerUrl = options.providerUrl;
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 21:02:46 +00:00
|
|
|
deploy(cb) {
|
|
|
|
console.log(__("deploying to swarm!"));
|
2018-08-16 10:41:18 +00:00
|
|
|
const self = this;
|
|
|
|
const swarm = this.swarm;
|
2018-07-07 21:02:46 +00:00
|
|
|
async.waterfall([
|
|
|
|
function runCommand(callback) {
|
|
|
|
console.log(("=== " + __("adding %s to swarm", self.buildDir)).green);
|
2018-09-10 06:36:30 +00:00
|
|
|
swarm.uploadDirectory(self.buildDir, 'index.html', callback);
|
2018-07-07 21:02:46 +00:00
|
|
|
},
|
|
|
|
function printUrls(dir_hash, callback) {
|
|
|
|
if (!dir_hash) {
|
|
|
|
return callback('No directory hash was returned');
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2018-09-10 06:36:30 +00:00
|
|
|
console.log(("=== " + __("DApp available at") + ` ${self.providerUrl}/bzz:/${dir_hash}/index.html`).green);
|
|
|
|
console.log(("=== " + __("DApp available at") + ` https://swarm-gateways.net/bzz:/${dir_hash}/index.html`).green);
|
2018-09-10 06:27:19 +00:00
|
|
|
console.log(("=== " + __("NOTE: A blockchain node must be running for the dApp to work correctly (ie 'embark run' or 'embark blockchain')").yellow));
|
2018-07-07 21:02:46 +00:00
|
|
|
|
2018-07-30 15:57:00 +00:00
|
|
|
callback(null, dir_hash);
|
2018-07-07 21:02:46 +00:00
|
|
|
}
|
2018-07-30 15:57:00 +00:00
|
|
|
], function (err, dir_hash) {
|
2018-07-07 21:02:46 +00:00
|
|
|
if (err) {
|
|
|
|
console.log(__("error uploading to swarm").red);
|
|
|
|
console.log(err);
|
|
|
|
return cb(err);
|
|
|
|
}
|
2018-07-30 15:57:00 +00:00
|
|
|
cb(null, dir_hash);
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-01-07 21:52:29 +00:00
|
|
|
|
|
|
|
module.exports = Swarm;
|