-
Notifications
You must be signed in to change notification settings - Fork 490
swarm deploy refactored to use web3.bzz instead of command line #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c05915b
cc30ff3
f59a187
4c39a3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,38 @@ | ||
| require('colors'); | ||
| let async = require('async'); | ||
| let shelljs = require('shelljs'); | ||
|
|
||
| class Swarm { | ||
| constructor(options) { | ||
| this.options = options; | ||
| this.buildDir = options.buildDir || 'dist/'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correction/addition, it should actually be in swarm/index.js (which is the actual module initialization), then the module can pass the params to upload
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
| this.web3 = options.web3; | ||
| this.storageConfig = options.storageConfig; | ||
| } | ||
|
|
||
| deploy() { | ||
| return new Promise((resolve, reject) => { | ||
| console.log("deploying to swarm!"); | ||
| let self = this; | ||
| let web3 = this.web3; | ||
| async.waterfall([ | ||
| function findBinary(callback) { | ||
| let swarm_bin = shelljs.which('swarm'); | ||
|
|
||
| if (swarm_bin === 'swarm not found' || !swarm_bin) { | ||
| console.log('=== WARNING: Swarm not in an executable path. Guessing ~/go/bin/swarm for path'.yellow); | ||
| swarm_bin = "~/go/bin/swarm"; | ||
| } | ||
|
|
||
| callback(null, swarm_bin); | ||
| function setProvider(callback){ | ||
| web3.bzz.setProvider(`http://${self.storageConfig.host}:${self.storageConfig.port}`); | ||
| callback(); | ||
| }, | ||
| function runCommand(swarm_bin, callback) { | ||
| let cmd = `"${swarm_bin}" --defaultpath ${self.buildDir} index.html --recursive up ${self.buildDir}`; | ||
| function runCommand(callback) { | ||
| console.log(("=== adding " + self.buildDir + " to swarm").green); | ||
| console.trace(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, {code: code, output: stdout}); | ||
| }); | ||
| }, | ||
| function getHashFromOutput(result, callback) { | ||
| if (result.code !== 0) { | ||
| callback("couldn't upload, is the swarm daemon running?"); | ||
| } | ||
| else{ | ||
| let rows = result.output.split("\n"); | ||
| let dir_hash = rows.reverse()[1]; | ||
|
|
||
| callback(null, dir_hash); | ||
| } | ||
| web3.bzz.upload({ | ||
| 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); | ||
| }, | ||
| function printUrls(dir_hash, callback) { | ||
| console.log(("=== DApp available at http://localhost:8500/bzz:/" + dir_hash + "/").green); | ||
| console.log((`=== DApp available at ${self.storageConfig.getUrl}${dir_hash}/`).green); | ||
|
|
||
| callback(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove the initConfig? in fact I don't quite understand how
this.config.storageConfigwould work later without thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instantiations of
Events/Logger/Configobjects are done in bothEmbark.initConfig()and inEngine.init(). In this case,Embark.uploadmethod added anEngine.init()and therefore no longer need to runEmbark.initConfig()as it was duplicating effort.You'll also notice in the
Embark.uploadafter theEngineis instantiated, the Engine's events/logger/config properties are used instead of those local to Embark as initConfig is no longer called.