mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-10 14:06:10 +00:00
Implemented PR review changes
* Removed config init from `cmd.js` for upload. * refactored `upload()` to use engine services instead of loading and using plugins directly. * now passing web3 directly to the `Swarm` constructor
This commit is contained in:
parent
c05915b0e9
commit
cc30ff390e
@ -181,11 +181,7 @@ class Cmd {
|
||||
.option('--loglevel [loglevel]', 'level of logging to display ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
||||
.description('Upload your dapp to a decentralized storage (e.g embark upload ipfs).')
|
||||
.action(function (platform, env, _options) {
|
||||
let environment = env || 'development';
|
||||
embark.initConfig(environment, {
|
||||
embarkConfig: 'embark.json', interceptLogs: false
|
||||
});
|
||||
_options.env = environment;
|
||||
_options.env = env || 'development';
|
||||
_options.logFile = _options.logfile; // fix casing
|
||||
_options.logLevel = _options.loglevel; // fix casing
|
||||
embark.upload(platform, _options);
|
||||
|
@ -67,7 +67,8 @@ class Engine {
|
||||
"webServer": this.webServerService,
|
||||
"ipfs": this.ipfsService,
|
||||
"web3": this.web3Service,
|
||||
"libraryManager": this.libraryManagerService
|
||||
"libraryManager": this.libraryManagerService,
|
||||
"swarm": this.swarmService
|
||||
};
|
||||
|
||||
let service = services[serviceName];
|
||||
@ -194,6 +195,16 @@ class Engine {
|
||||
});
|
||||
}
|
||||
|
||||
swarmService(_options) {
|
||||
this.registerModule('swarm', {
|
||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
||||
storageConfig: this.config.storageConfig,
|
||||
host: _options.host,
|
||||
port: _options.port,
|
||||
web3: _options.web3
|
||||
});
|
||||
}
|
||||
|
||||
web3Service(options) {
|
||||
let self = this;
|
||||
this.web3 = options.web3;
|
||||
|
62
lib/index.js
62
lib/index.js
@ -256,20 +256,6 @@ class Embark {
|
||||
}
|
||||
|
||||
upload(platform, options) {
|
||||
|
||||
// populate options that were instantiated with initConfig to pass around
|
||||
options.buildDir = 'dist/';
|
||||
options.storageConfig = this.config.storageConfig;
|
||||
options.events = this.events;
|
||||
options.logger = this.logger;
|
||||
options.config = this.config;
|
||||
|
||||
// load plugins
|
||||
this.plugins.loadInternalPlugin('ipfs', options);
|
||||
this.plugins.loadInternalPlugin('swarm', options);
|
||||
|
||||
// upddate our options with loaded plugins
|
||||
options.plugins = this.plugins;
|
||||
|
||||
let engine = new Engine({
|
||||
env: options.env,
|
||||
@ -286,11 +272,27 @@ class Embark {
|
||||
engine.init();
|
||||
|
||||
let cmdPlugin;
|
||||
let self = this;
|
||||
async.waterfall([
|
||||
|
||||
function startServices(callback) {
|
||||
|
||||
engine.startService("libraryManager");
|
||||
engine.startService("web3");
|
||||
engine.startService("pipeline");
|
||||
engine.startService("codeGenerator");
|
||||
engine.startService("deployment");
|
||||
engine.startService("ipfs");
|
||||
engine.startService("swarm", {buildDir:'dist/',web3: engine.web3});
|
||||
callback();
|
||||
},
|
||||
function setupStoragePlugin(callback){
|
||||
let pluginList = engine.plugins.listPlugins();
|
||||
if (pluginList.length > 0) {
|
||||
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
||||
}
|
||||
|
||||
// check use has input existing storage plugin
|
||||
let cmdPlugins = self.plugins.getPluginsFor('uploadCmds');
|
||||
let cmdPlugins = engine.plugins.getPluginsFor('uploadCmds');
|
||||
|
||||
if (cmdPlugins.length > 0) {
|
||||
cmdPlugin = cmdPlugins.find((pluginCmd) => {
|
||||
@ -298,30 +300,16 @@ class Embark {
|
||||
});
|
||||
}
|
||||
if (!cmdPlugin) {
|
||||
self.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||
engine.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||
callback({message: 'unknown platform: ' + platform});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
function startServices(callback) {
|
||||
let pluginList = engine.plugins.listPlugins();
|
||||
if (pluginList.length > 0) {
|
||||
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
||||
}
|
||||
|
||||
engine.startService("libraryManager");
|
||||
engine.startService("web3");
|
||||
engine.startService("pipeline");
|
||||
engine.startService("codeGenerator");
|
||||
engine.startService("deployment");
|
||||
engine.startService("ipfs");
|
||||
callback();
|
||||
},
|
||||
function deploy(callback) {
|
||||
// 2. upload to storage (outputDone event triggered after webpack finished)
|
||||
self.events.on('outputDone', function () {
|
||||
cmdPlugin.uploadCmds[0].cb({web3: engine.web3})
|
||||
engine.events.on('outputDone', function () {
|
||||
cmdPlugin.uploadCmds[0].cb()
|
||||
.then((success) => {
|
||||
callback(null, success);
|
||||
})
|
||||
@ -329,7 +317,7 @@ class Embark {
|
||||
});
|
||||
// 1. build the contracts and dapp webpack
|
||||
engine.deployManager.deployContracts(function (err) {
|
||||
engine.logger.info("finished building".underline);
|
||||
engine.logger.info("finished deploying".underline);
|
||||
if(err){
|
||||
callback(err);
|
||||
}
|
||||
@ -337,10 +325,10 @@ class Embark {
|
||||
}
|
||||
], function (err, _result) {
|
||||
if (err) {
|
||||
self.logger.error(err.message);
|
||||
self.logger.debug(err.stack);
|
||||
engine.logger.error(err.message);
|
||||
engine.logger.debug(err.stack);
|
||||
} else {
|
||||
self.logger.info("finished building dapp and deploying to " + platform.underline);
|
||||
engine.logger.info(`finished building DApp and deploying to ${platform}`.underline);
|
||||
}
|
||||
|
||||
// needed due to child processes
|
||||
|
@ -7,7 +7,8 @@ class Swarm {
|
||||
|
||||
this.upload_swarm = new UploadSwarm({
|
||||
buildDir: options.buildDir || 'dist/',
|
||||
storageConfig: options.storageConfig
|
||||
storageConfig: options.storageConfig,
|
||||
web3: options.web3
|
||||
});
|
||||
|
||||
embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm));
|
||||
|
@ -5,21 +5,18 @@ class Swarm {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.buildDir = options.buildDir || 'dist/';
|
||||
this.web3 = options.web3;
|
||||
this.storageConfig = options.storageConfig;
|
||||
}
|
||||
|
||||
deploy(deployOptions) {
|
||||
deploy() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("deploying to swarm!");
|
||||
let self = this;
|
||||
let web3 = (deployOptions || {}).web3;
|
||||
let web3 = this.web3;
|
||||
async.waterfall([
|
||||
function findWeb3(callback){
|
||||
if(!web3){
|
||||
callback('web3 must be passed in to the swarm deploy() method');
|
||||
}else callback();
|
||||
},
|
||||
function setProvider(callback){
|
||||
web3.bzz.setProvider(`http://${self.options.storageConfig.host}:${self.options.storageConfig.port}`);
|
||||
web3.bzz.setProvider(`http://${self.storageConfig.host}:${self.storageConfig.port}`);
|
||||
callback();
|
||||
},
|
||||
function runCommand(callback) {
|
||||
@ -35,7 +32,7 @@ class Swarm {
|
||||
.catch(callback);
|
||||
},
|
||||
function printUrls(dir_hash, callback) {
|
||||
console.log((`=== DApp available at ${self.options.storageConfig.getUrl}${dir_hash}/`).green);
|
||||
console.log((`=== DApp available at ${self.storageConfig.getUrl}${dir_hash}/`).green);
|
||||
|
||||
callback();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user