mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
fix upload callback
This commit is contained in:
parent
f7ac654d92
commit
2780b4eb2f
@ -330,7 +330,7 @@ class Embark {
|
|||||||
},
|
},
|
||||||
function deploy(callback) {
|
function deploy(callback) {
|
||||||
engine.events.on('outputDone', function () {
|
engine.events.on('outputDone', function () {
|
||||||
embark.events.request("storage:upload", callback);
|
engine.events.request("storage:upload", callback);
|
||||||
});
|
});
|
||||||
engine.events.on('check:backOnline:Ethereum', function () {
|
engine.events.on('check:backOnline:Ethereum', function () {
|
||||||
engine.logger.info(__('Ethereum node detected') + '..');
|
engine.logger.info(__('Ethereum node detected') + '..');
|
||||||
|
@ -11,51 +11,49 @@ class IPFS {
|
|||||||
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
||||||
}
|
}
|
||||||
|
|
||||||
deploy() {
|
deploy(cb) {
|
||||||
return new Promise((resolve, reject) => {
|
console.log("deploying to ipfs!");
|
||||||
console.log("deploying to ipfs!");
|
let self = this;
|
||||||
let self = this;
|
async.waterfall([
|
||||||
async.waterfall([
|
function findBinary(callback) {
|
||||||
function findBinary(callback) {
|
let ipfs_bin = shelljs.which(self.configIpfsBin);
|
||||||
let ipfs_bin = shelljs.which(self.configIpfsBin);
|
|
||||||
|
|
||||||
if (ipfs_bin === 'ipfs not found' || !ipfs_bin) {
|
if (ipfs_bin === 'ipfs not found' || !ipfs_bin) {
|
||||||
console.log(('=== WARNING: ' + self.configIpfsBin + ' ' + __('not found or not in the path. Guessing %s for path', '~/go/bin/ipfs')).yellow);
|
console.log(('=== WARNING: ' + self.configIpfsBin + ' ' + __('not found or not in the path. Guessing %s for path', '~/go/bin/ipfs')).yellow);
|
||||||
ipfs_bin = "~/go/bin/ipfs";
|
ipfs_bin = "~/go/bin/ipfs";
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, ipfs_bin);
|
|
||||||
},
|
|
||||||
function runCommand(ipfs_bin, callback) {
|
|
||||||
let cmd = `"${ipfs_bin}" add -r ${self.buildDir}`;
|
|
||||||
console.log(("=== " + __("adding %s to ipfs", self.buildDir)).green);
|
|
||||||
console.debug(cmd);
|
|
||||||
shelljs.exec(cmd, {silent:true}, function(code, stdout, stderr){ // {silent:true}: don't echo cmd output so it can be controlled via logLevel
|
|
||||||
console.log(stdout.green);
|
|
||||||
callback(stderr, stdout);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function getHashFromOutput(result, callback) {
|
|
||||||
let rows = result.split("\n");
|
|
||||||
let dir_row = rows[rows.length - 2];
|
|
||||||
let dir_hash = dir_row.split(" ")[1];
|
|
||||||
|
|
||||||
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://ipfs.infura.io/ipfs/" + dir_hash + "/").green);
|
|
||||||
|
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
|
||||||
if (err) {
|
callback(null, ipfs_bin);
|
||||||
console.log(__("error uploading to ipfs").red);
|
},
|
||||||
console.log(err);
|
function runCommand(ipfs_bin, callback) {
|
||||||
reject(err);
|
let cmd = `"${ipfs_bin}" add -r ${self.buildDir}`;
|
||||||
}
|
console.log(("=== " + __("adding %s to ipfs", self.buildDir)).green);
|
||||||
else resolve(__('successfully uploaded to ipfs'));
|
console.debug(cmd);
|
||||||
});
|
shelljs.exec(cmd, {silent:true}, function(code, stdout, stderr){ // {silent:true}: don't echo cmd output so it can be controlled via logLevel
|
||||||
|
console.log(stdout.green);
|
||||||
|
callback(stderr, stdout);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function getHashFromOutput(result, callback) {
|
||||||
|
let rows = result.split("\n");
|
||||||
|
let dir_row = rows[rows.length - 2];
|
||||||
|
let dir_hash = dir_row.split(" ")[1];
|
||||||
|
|
||||||
|
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://ipfs.infura.io/ipfs/" + dir_hash + "/").green);
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
], function (err, _result) {
|
||||||
|
if (err) {
|
||||||
|
console.log(__("error uploading to ipfs").red);
|
||||||
|
console.log(err);
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
else cb(__('successfully uploaded to ipfs'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ class Storage {
|
|||||||
if (['swarm', 'ipfs'].indexOf(platform) === -1) {
|
if (['swarm', 'ipfs'].indexOf(platform) === -1) {
|
||||||
return cb({message: __('platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".', {platform: platform})});
|
return cb({message: __('platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".', {platform: platform})});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
embark.events.request("storage:upload:" + platform, cb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,41 +10,39 @@ class Swarm {
|
|||||||
this.getUrl = options.getUrl;
|
this.getUrl = options.getUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
deploy() {
|
deploy(cb) {
|
||||||
return new Promise((resolve, reject) => {
|
console.log(__("deploying to swarm!"));
|
||||||
console.log(__("deploying to swarm!"));
|
let self = this;
|
||||||
let self = this;
|
let bzz = this.bzz;
|
||||||
let bzz = this.bzz;
|
async.waterfall([
|
||||||
async.waterfall([
|
function runCommand(callback) {
|
||||||
function runCommand(callback) {
|
console.log(("=== " + __("adding %s to swarm", self.buildDir)).green);
|
||||||
console.log(("=== " + __("adding %s to swarm", self.buildDir)).green);
|
bzz.upload({
|
||||||
bzz.upload({
|
path: self.buildDir, // path to data / file / directory
|
||||||
path: self.buildDir, // path to data / file / directory
|
kind: "directory", // could also be "file" or "data"
|
||||||
kind: "directory", // could also be "file" or "data"
|
defaultFile: "index.html" // optional, and only for kind === "directory"
|
||||||
defaultFile: "index.html" // optional, and only for kind === "directory"
|
})
|
||||||
})
|
|
||||||
.then((success) => {
|
.then((success) => {
|
||||||
callback(null, success);
|
callback(null, success);
|
||||||
})
|
})
|
||||||
.catch(callback);
|
.catch(callback);
|
||||||
},
|
},
|
||||||
function printUrls(dir_hash, callback) {
|
function printUrls(dir_hash, callback) {
|
||||||
if (!dir_hash) {
|
if (!dir_hash) {
|
||||||
return callback('No directory hash was returned');
|
return callback('No directory hash was returned');
|
||||||
}
|
}
|
||||||
console.log(("=== " + __("DApp available at") + ` ${self.getUrl}${dir_hash}/`).green);
|
console.log(("=== " + __("DApp available at") + ` ${self.getUrl}${dir_hash}/`).green);
|
||||||
console.log(("=== " + __("DApp available at") + ` http://swarm-gateways.net/bzz:/${dir_hash}`).green);
|
console.log(("=== " + __("DApp available at") + ` http://swarm-gateways.net/bzz:/${dir_hash}`).green);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
], function (err, _result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(__("error uploading to swarm").red);
|
console.log(__("error uploading to swarm").red);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return reject(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
resolve(__('successfully uploaded to swarm'));
|
cb(null, __('successfully uploaded to swarm'));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user