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-04-30 05:56:43 +00:00
|
|
|
this.bzz = options.bzz;
|
2018-04-24 00:27:11 +00:00
|
|
|
this.storageConfig = options.storageConfig;
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 00:27:11 +00:00
|
|
|
deploy() {
|
2018-04-13 05:06:13 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2018-04-19 04:25:43 +00:00
|
|
|
console.log("deploying to swarm!");
|
2018-04-13 05:06:13 +00:00
|
|
|
let self = this;
|
2018-04-30 05:56:43 +00:00
|
|
|
let bzz = this.bzz;
|
2018-04-13 05:06:13 +00:00
|
|
|
async.waterfall([
|
2018-04-20 07:39:45 +00:00
|
|
|
function runCommand(callback) {
|
|
|
|
console.log(("=== adding " + self.buildDir + " to swarm").green);
|
2018-04-30 05:56:43 +00:00
|
|
|
bzz.upload({
|
2018-04-20 07:39:45 +00:00
|
|
|
path: self.buildDir, // path to data / file / directory
|
|
|
|
kind: "directory", // could also be "file" or "data"
|
|
|
|
defaultFile: "index.html" // optional, and only for kind === "directory"
|
|
|
|
})
|
|
|
|
.then((success) => {
|
|
|
|
callback(null, success);
|
|
|
|
})
|
|
|
|
.catch(callback);
|
2018-04-13 05:06:13 +00:00
|
|
|
},
|
|
|
|
function printUrls(dir_hash, callback) {
|
2018-05-01 14:20:27 +00:00
|
|
|
if (!dir_hash) {
|
|
|
|
return callback('No directory hash was returned');
|
|
|
|
}
|
2018-04-24 00:27:11 +00:00
|
|
|
console.log((`=== DApp available at ${self.storageConfig.getUrl}${dir_hash}/`).green);
|
2018-04-13 05:06:13 +00:00
|
|
|
|
2018-04-15 08:41:50 +00:00
|
|
|
callback();
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2018-04-13 05:06:13 +00:00
|
|
|
], function (err, _result) {
|
|
|
|
if (err) {
|
|
|
|
console.log("error uploading to swarm".red);
|
|
|
|
console.log(err);
|
2018-05-01 14:20:27 +00:00
|
|
|
return reject(err);
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2018-05-01 14:20:27 +00:00
|
|
|
resolve('successfully uploaded to swarm');
|
2018-04-13 05:06:13 +00:00
|
|
|
});
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-01-07 21:52:29 +00:00
|
|
|
|
|
|
|
module.exports = Swarm;
|