genereate components config files

This commit is contained in:
Iuri Matias 2019-07-17 17:52:17 -04:00
parent 78775afd1c
commit dd0cfbc2dc
5 changed files with 80 additions and 22 deletions

View File

@ -124,11 +124,13 @@ class IPFS {
// TODO: should be done in embarkjs-ipfs
// TODO: check config, etc..
registerAndSetIpfs() {
// TODO: this should be at the start
const code = `
const __embarkIPFS = require('embarkjs-ipfs');
EmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);
`;
// TODO: this should be done when a connection is detected
this.events.request('runcode:eval', code, (err) => {
let providerCode = `\nEmbarkJS.Storage.setProviders(${JSON.stringify(this.embark.config.storageConfig.dappConnection || [])}, {web3});`;
this.events.request('runcode:eval', providerCode, (err) => {

View File

@ -4,31 +4,30 @@ import * as async from 'async';
class Storage {
constructor(embark, options){
this.embark = embark;
this.embarkConfig = embark.config.embarkConfig;
this.events = this.embark.events;
this.storageConfig = embark.config.storageConfig;
this.plugins = options.plugins;
this.ready = false;
let plugin = this.plugins.createPlugin('storageplugin', {});
this.embark.events.setCommandHandler("module:storage:onReady", (cb) => {
if (this.ready) {
return cb();
}
this.embark.events.once("module:storage:ready", cb);
});
// this.handleUploadCommand();
// this.addSetProviders(() => {});
plugin.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this));
this.embark.events.setCommandHandler("module:storageJS:reset", (cb) => {
if (!this.isEnabled()) {
return cb();
}
this.ready = false;
this.addSetProviders(cb);
});
// TODO: register xyz (e.g ipfs) to check for dappConnectionConfig
}
if (!this.isEnabled()) {
this.ready = true;
return;
}
addArtifactFile(_params, cb) {
let config = {
dappConnection: this.storageConfig.dappConnection
};
this.handleUploadCommand();
this.addSetProviders(() => {});
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'config'],
file: 'communication.json',
format: 'json',
content: config
}, cb);
}
isEnabled() {

View File

@ -13,11 +13,13 @@ class Whisper {
this.events = embark.events;
this.fs = embark.fs;
this.communicationConfig = embark.config.communicationConfig;
this.embarkConfig = embark.config.embarkConfig;
this.web3 = new Web3();
this.embark = embark;
this.web3Ready = false;
this.webSocketsChannels = {};
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir, constants.dappArtifacts.symlinkDir);
this.plugins = options.plugins;
if (embark.currentContext.includes('test') && options.node &&options.node === 'vm') {
this.logger.info(__('Whisper disabled in the tests'));
@ -48,6 +50,9 @@ class Whisper {
this.registerAndSetWhisper();
});
let plugin = this.plugins.createPlugin('whisperplugin', {});
plugin.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this));
// ===============================
// this.connectToProvider();
@ -73,6 +78,21 @@ class Whisper {
// this.events.request('processes:launch', 'whisper');
}
// TODO: should load the latest config
addArtifactFile(_params, cb) {
let config = {
// TODO: for consistency we should change this to be dappConnection or connection
connection: this.communicationConfig.connection
};
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'config'],
file: 'storage.json',
format: 'json',
content: config
}, cb);
}
connectToProvider() {
let {host, port} = this.communicationConfig.connection;
let web3Endpoint = 'ws://' + host + ':' + port;

View File

@ -277,9 +277,9 @@ class Engine {
}
storageService(_options) {
this.registerModulePackage('embark-storage', {plugins: this.plugins});
this.registerModulePackage('embark-ipfs');
// this.registerModulePackage('embark-swarm');
// this.registerModulePackage('embark-storage', {plugins: this.plugins});
// this.events.setCommandHandler("module:storage:reset", (cb) => {
// async.parallel([
@ -298,6 +298,7 @@ class Engine {
web3Service(options) {
this.registerModulePackage('embark-web3');
this.registerModule('blockchain', { plugins: this.plugins });
this.registerModulePackage('embark-blockchain-process', {
client: this.client,
@ -314,7 +315,7 @@ class Engine {
wait: options.wait
});
this.registerModulePackage('embark-whisper');
this.registerModulePackage('embark-whisper', { plugins: this.plugins });
this.registerModule('web3', { plugins: this.plugins });
}

View File

@ -0,0 +1,36 @@
class Blockchain {
constructor(embark, options) {
this.embarkConfig = embark.config.embarkConfig;
this.logger = embark.logger;
this.events = embark.events;
this.blockchainConfig = embark.config.blockchainConfig;
this.contractConfig = embark.config.contractConfig;
this.plugins = options.plugins;
let plugin = this.plugins.createPlugin('web3plugin', {});
plugin.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this));
}
addArtifactFile(_params, cb) {
this.events.request("config:contractsConfig", (contractsConfig) => {
let config = {
dappConnection: contractsConfig.dappConnection,
dappAutoEnable: contractsConfig.dappAutoEnable,
warnIfMetamask: this.blockchainConfig.isDev,
blockchainClient: this.blockchainConfig.client
};
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'config'],
file: 'blockchain.json',
format: 'json',
content: config
}, cb);
});
}
}
module.exports = Blockchain;