mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-17 09:46:37 +00:00
read storage and communication config files; use & initialize storage depending on config
This commit is contained in:
parent
629b9aa2a6
commit
6984c13ac6
5
boilerplate/config/communication.json
Normal file
5
boilerplate/config/communication.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"provider": "whisper"
|
||||||
|
}
|
||||||
|
}
|
15
boilerplate/config/storage.json
Normal file
15
boilerplate/config/storage.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"enabled": true,
|
||||||
|
"ipfs_bin": "ipfs",
|
||||||
|
"provider": "ipfs",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5001
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"enabled": true,
|
||||||
|
"provider": "ipfs",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5001
|
||||||
|
}
|
||||||
|
}
|
5
demo/config/communication.json
Normal file
5
demo/config/communication.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"provider": "whisper"
|
||||||
|
}
|
||||||
|
}
|
15
demo/config/storage.json
Normal file
15
demo/config/storage.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"enabled": true,
|
||||||
|
"ipfs_bin": "ipfs",
|
||||||
|
"provider": "ipfs",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5001
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"enabled": true,
|
||||||
|
"provider": "ipfs",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5001
|
||||||
|
}
|
||||||
|
}
|
16
lib/abi.js
16
lib/abi.js
@ -2,6 +2,7 @@ var Plugins = require('./plugins.js');
|
|||||||
|
|
||||||
var ABIGenerator = function(options) {
|
var ABIGenerator = function(options) {
|
||||||
this.blockchainConfig = options.blockchainConfig || {};
|
this.blockchainConfig = options.blockchainConfig || {};
|
||||||
|
this.storageConfig = options.storageConfig || {};
|
||||||
this.contractsManager = options.contractsManager;
|
this.contractsManager = options.contractsManager;
|
||||||
this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost;
|
this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost;
|
||||||
this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort;
|
this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort;
|
||||||
@ -60,11 +61,26 @@ ABIGenerator.prototype.generateContracts = function(useEmbarkJS) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ABIGenerator.prototype.generateStorageInitialiation = function(useEmbarkJS) {
|
||||||
|
var self = this;
|
||||||
|
var result = "\n";
|
||||||
|
|
||||||
|
if (!useEmbarkJS || self.storageConfig === {}) return;
|
||||||
|
|
||||||
|
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
|
||||||
|
result += "\n" + "EmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "'});";
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ABIGenerator.prototype.generateABI = function(options) {
|
ABIGenerator.prototype.generateABI = function(options) {
|
||||||
var result = "";
|
var result = "";
|
||||||
|
|
||||||
result += this.generateProvider();
|
result += this.generateProvider();
|
||||||
result += this.generateContracts(options.useEmbarkJS);
|
result += this.generateContracts(options.useEmbarkJS);
|
||||||
|
result += this.generateStorageInitialiation(options.useEmbarkJS);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
@ -119,12 +119,12 @@ Cmd.prototype.test = function() {
|
|||||||
Cmd.prototype.upload = function() {
|
Cmd.prototype.upload = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
program
|
program
|
||||||
.command('upload [platform]')
|
.command('upload [platform] [environment]')
|
||||||
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
||||||
.action(function(platform ,options) {
|
.action(function(platform, env, options) {
|
||||||
// TODO: get env in cmd line as well
|
// TODO: get env in cmd line as well
|
||||||
self.Embark.initConfig('development', {
|
self.Embark.initConfig(env || 'development', {
|
||||||
embarkConfig: 'embark.json'
|
embarkConfig: 'embark.json', interceptLogs: false
|
||||||
});
|
});
|
||||||
self.Embark.upload(platform);
|
self.Embark.upload(platform);
|
||||||
});
|
});
|
||||||
|
@ -33,6 +33,8 @@ Config.prototype.loadConfigFiles = function(options) {
|
|||||||
|
|
||||||
this.loadPipelineConfigFile();
|
this.loadPipelineConfigFile();
|
||||||
this.loadBlockchainConfigFile();
|
this.loadBlockchainConfigFile();
|
||||||
|
this.loadStorageConfigFile();
|
||||||
|
this.loadCommunicationConfigFile();
|
||||||
|
|
||||||
this.loadContractsConfigFile();
|
this.loadContractsConfigFile();
|
||||||
this.loadChainTrackerFile();
|
this.loadChainTrackerFile();
|
||||||
@ -42,6 +44,8 @@ Config.prototype.loadConfigFiles = function(options) {
|
|||||||
Config.prototype.reloadConfig = function() {
|
Config.prototype.reloadConfig = function() {
|
||||||
this.loadPipelineConfigFile();
|
this.loadPipelineConfigFile();
|
||||||
this.loadBlockchainConfigFile();
|
this.loadBlockchainConfigFile();
|
||||||
|
this.loadStorageConfigFile();
|
||||||
|
this.loadCommunicationConfigFile();
|
||||||
this.loadContractsConfigFile();
|
this.loadContractsConfigFile();
|
||||||
this.loadChainTrackerFile();
|
this.loadChainTrackerFile();
|
||||||
};
|
};
|
||||||
@ -73,6 +77,49 @@ Config.prototype.loadContractsConfigFile = function() {
|
|||||||
this.contractsConfig = mergedConfig;
|
this.contractsConfig = mergedConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Config.prototype.loadStorageConfigFile = function() {
|
||||||
|
var configObject = {};
|
||||||
|
|
||||||
|
//var configPlugins = this.plugins.getPluginsFor('storageConfig');
|
||||||
|
//if (configPlugins.length > 0) {
|
||||||
|
// configPlugins.forEach(function(plugin) {
|
||||||
|
// plugin.contractsConfigs.forEach(function(pluginConfig) {
|
||||||
|
// configObject = merge.recursive(configObject, pluginConfig);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
|
var storageConfig = JSON.parse(fs.readFileSync(this.configDir + "storage.json"));
|
||||||
|
configObject = merge.recursive(configObject, storageConfig);
|
||||||
|
var defaultStorageConfig = configObject['default'];
|
||||||
|
var envStorageConfig = configObject[this.env];
|
||||||
|
|
||||||
|
var mergedConfig = merge.recursive(defaultStorageConfig, envStorageConfig);
|
||||||
|
this.storageConfig = mergedConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
Config.prototype.loadCommunicationConfigFile = function() {
|
||||||
|
var configObject = {};
|
||||||
|
|
||||||
|
//var configPlugins = this.plugins.getPluginsFor('communicationConfig');
|
||||||
|
//if (configPlugins.length > 0) {
|
||||||
|
// configPlugins.forEach(function(plugin) {
|
||||||
|
// plugin.contractsConfigs.forEach(function(pluginConfig) {
|
||||||
|
// configObject = merge.recursive(configObject, pluginConfig);
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
|
var communicationConfig = JSON.parse(fs.readFileSync(this.configDir + "communication.json"));
|
||||||
|
configObject = merge.recursive(configObject, communicationConfig);
|
||||||
|
var defaultCommunicationConfig = configObject['default'];
|
||||||
|
var envCommunicationConfig = configObject[this.env];
|
||||||
|
|
||||||
|
var mergedConfig = merge.recursive(defaultCommunicationConfig, envCommunicationConfig);
|
||||||
|
this.communicationConfig = mergedConfig;
|
||||||
|
};
|
||||||
|
|
||||||
Config.prototype.loadPipelineConfigFile = function() {
|
Config.prototype.loadPipelineConfigFile = function() {
|
||||||
var contracts = this.embarkConfig.contracts;
|
var contracts = this.embarkConfig.contracts;
|
||||||
this.contractsFiles = this.loadFiles(contracts);
|
this.contractsFiles = this.loadFiles(contracts);
|
||||||
|
10
lib/index.js
10
lib/index.js
@ -259,7 +259,7 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function generateABI(contractsManager, callback) {
|
function generateABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins});
|
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig});
|
||||||
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
@ -285,13 +285,13 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function generateConsoleABI(contractsManager, callback) {
|
function generateConsoleABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager});
|
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig});
|
||||||
var consoleABI = abiGenerator.generateABI({useEmbarkJS: false});
|
var consoleABI = abiGenerator.generateABI({useEmbarkJS: false});
|
||||||
Embark.console.runCode(consoleABI);
|
Embark.console.runCode(consoleABI);
|
||||||
callback(null, contractsManager);
|
callback(null, contractsManager);
|
||||||
},
|
},
|
||||||
function generateABI(contractsManager, callback) {
|
function generateABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins});
|
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig});
|
||||||
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
||||||
},
|
},
|
||||||
function buildPipeline(abi, callback) {
|
function buildPipeline(abi, callback) {
|
||||||
@ -325,10 +325,10 @@ var Embark = {
|
|||||||
// TODO: should deploy if it hasn't already
|
// TODO: should deploy if it hasn't already
|
||||||
upload: function(platform) {
|
upload: function(platform) {
|
||||||
if (platform === 'ipfs') {
|
if (platform === 'ipfs') {
|
||||||
var ipfs = new IPFS({buildDir: 'dist/'});
|
var ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
||||||
ipfs.deploy();
|
ipfs.deploy();
|
||||||
} else if (platform === 'swarm') {
|
} else if (platform === 'swarm') {
|
||||||
var swarm = new Swarm({buildDir: 'dist/'});
|
var swarm = new Swarm({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
||||||
swarm.deploy();
|
swarm.deploy();
|
||||||
} else {
|
} else {
|
||||||
console.log(("unknown platform: " + platform).red);
|
console.log(("unknown platform: " + platform).red);
|
||||||
|
@ -4,16 +4,19 @@ var async = require('async');
|
|||||||
var IPFS = function(options) {
|
var IPFS = function(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.buildDir = options.buildDir || 'dist/';
|
this.buildDir = options.buildDir || 'dist/';
|
||||||
|
this.plugins = options.plugins;
|
||||||
|
this.storageConfig = options.storageConfig;
|
||||||
|
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
||||||
};
|
};
|
||||||
|
|
||||||
IPFS.prototype.deploy = function() {
|
IPFS.prototype.deploy = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function findBinary(callback) {
|
function findBinary(callback) {
|
||||||
var ipfs_bin = exec('which ipfs').output.split("\n")[0];
|
var ipfs_bin = exec('which ' + self.configIpfsBin).output.split("\n")[0];
|
||||||
|
|
||||||
if (ipfs_bin==='ipfs not found'){
|
if (ipfs_bin === 'ipfs not found' || ipfs_bin === ''){
|
||||||
console.log('=== WARNING: IPFS not in an executable path. Guessing ~/go/bin/ipfs for path'.yellow);
|
console.log(('=== WARNING: ' + self.configIpfsBin + ' not found or not in the path. Guessing ~/go/bin/ipfs for path').yellow);
|
||||||
ipfs_bin = "~/go/bin/ipfs";
|
ipfs_bin = "~/go/bin/ipfs";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
test_app/config/communication.json
Normal file
5
test_app/config/communication.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"provider": "whisper"
|
||||||
|
}
|
||||||
|
}
|
15
test_app/config/storage.json
Normal file
15
test_app/config/storage.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"enabled": true,
|
||||||
|
"ipfs_bin": "ipfs",
|
||||||
|
"provider": "ipfs",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5001
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"enabled": true,
|
||||||
|
"provider": "ipfs",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 5001
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user