mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-03-01 15:40:45 +00:00
support disabling blockchain stack; tolerate lack of web3 object
This commit is contained in:
parent
d1701c4031
commit
cf0ea4299e
@ -204,6 +204,13 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
|
|||||||
var ipfs;
|
var ipfs;
|
||||||
if (provider === 'whisper') {
|
if (provider === 'whisper') {
|
||||||
this.currentMessages = EmbarkJS.Messages.Whisper;
|
this.currentMessages = EmbarkJS.Messages.Whisper;
|
||||||
|
if (web3 === undefined) {
|
||||||
|
if (options === undefined) {
|
||||||
|
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
||||||
|
} else {
|
||||||
|
web3 = new Web3(new Web3.providers.HttpProvider("http://" + options.server + ':' + options.port));
|
||||||
|
}
|
||||||
|
}
|
||||||
this.currentMessages.identity = web3.shh.newIdentity();
|
this.currentMessages.identity = web3.shh.newIdentity();
|
||||||
} else if (provider === 'orbit') {
|
} else if (provider === 'orbit') {
|
||||||
this.currentMessages = EmbarkJS.Messages.Orbit;
|
this.currentMessages = EmbarkJS.Messages.Orbit;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
var ABIGenerator = function(options) {
|
var ABIGenerator = function(options) {
|
||||||
this.blockchainConfig = options.blockchainConfig || {};
|
this.blockchainConfig = options.blockchainConfig || {};
|
||||||
this.storageConfig = options.storageConfig || {};
|
this.storageConfig = options.storageConfig || {};
|
||||||
|
this.communicationConfig = options.communicationConfig || {};
|
||||||
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;
|
||||||
@ -13,6 +14,10 @@ ABIGenerator.prototype.generateProvider = function() {
|
|||||||
var result = "";
|
var result = "";
|
||||||
var providerPlugins;
|
var providerPlugins;
|
||||||
|
|
||||||
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (this.plugins) {
|
if (this.plugins) {
|
||||||
providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider');
|
providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider');
|
||||||
}
|
}
|
||||||
@ -38,6 +43,10 @@ ABIGenerator.prototype.generateContracts = function(useEmbarkJS) {
|
|||||||
var result = "\n";
|
var result = "\n";
|
||||||
var contractsPlugins;
|
var contractsPlugins;
|
||||||
|
|
||||||
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (this.plugins) {
|
if (this.plugins) {
|
||||||
contractsPlugins = this.plugins.getPluginsFor('contractGeneration');
|
contractsPlugins = this.plugins.getPluginsFor('contractGeneration');
|
||||||
}
|
}
|
||||||
@ -70,7 +79,7 @@ ABIGenerator.prototype.generateStorageInitialization = function(useEmbarkJS) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var result = "\n";
|
var result = "\n";
|
||||||
|
|
||||||
if (!useEmbarkJS || self.storageConfig === {}) return;
|
if (!useEmbarkJS || self.storageConfig === {}) return "";
|
||||||
|
|
||||||
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
|
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 + "'});";
|
result += "\n" + "EmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "'});";
|
||||||
@ -83,7 +92,7 @@ ABIGenerator.prototype.generateCommunicationInitialization = function(useEmbarkJ
|
|||||||
var self = this;
|
var self = this;
|
||||||
var result = "\n";
|
var result = "\n";
|
||||||
|
|
||||||
if (!useEmbarkJS || self.communicationConfig === {}) return;
|
if (!useEmbarkJS || self.communicationConfig === {}) return "";
|
||||||
|
|
||||||
if (self.communicationConfig.provider === 'ipfs' && self.communicationConfig.enabled === true) {
|
if (self.communicationConfig.provider === 'ipfs' && self.communicationConfig.enabled === true) {
|
||||||
result += "\n" + "EmbarkJS.Storage.setProvider('" + self.communicationConfig.provider + "');";
|
result += "\n" + "EmbarkJS.Storage.setProvider('" + self.communicationConfig.provider + "');";
|
||||||
|
49
lib/index.js
49
lib/index.js
@ -68,7 +68,19 @@ var Embark = {
|
|||||||
self.config.reloadConfig();
|
self.config.reloadConfig();
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
self.buildDeployGenerate.bind(self)
|
self.buildDeployGenerate.bind(self),
|
||||||
|
function buildPipeline(abi, callback) {
|
||||||
|
self.logger.setStatus("Building Assets");
|
||||||
|
var pipeline = new Pipeline({
|
||||||
|
buildDir: self.config.buildDir,
|
||||||
|
contractsFiles: self.config.contractsFiles,
|
||||||
|
assetFiles: self.config.assetFiles,
|
||||||
|
logger: self.logger,
|
||||||
|
plugins: self.plugins
|
||||||
|
});
|
||||||
|
pipeline.build(abi);
|
||||||
|
callback();
|
||||||
|
}
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.error(err.message);
|
self.logger.error(err.message);
|
||||||
@ -136,6 +148,18 @@ var Embark = {
|
|||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
self.buildDeployGenerate.bind(self),
|
self.buildDeployGenerate.bind(self),
|
||||||
|
function buildPipeline(abi, callback) {
|
||||||
|
self.logger.setStatus("Building Assets");
|
||||||
|
var pipeline = new Pipeline({
|
||||||
|
buildDir: self.config.buildDir,
|
||||||
|
contractsFiles: self.config.contractsFiles,
|
||||||
|
assetFiles: self.config.assetFiles,
|
||||||
|
logger: self.logger,
|
||||||
|
plugins: self.plugins
|
||||||
|
});
|
||||||
|
pipeline.build(abi);
|
||||||
|
callback();
|
||||||
|
},
|
||||||
function watchFilesForChanges(callback) {
|
function watchFilesForChanges(callback) {
|
||||||
self.logger.setStatus("Watching for changes");
|
self.logger.setStatus("Watching for changes");
|
||||||
var watch = new Watch({logger: self.logger});
|
var watch = new Watch({logger: self.logger});
|
||||||
@ -285,6 +309,11 @@ var Embark = {
|
|||||||
buildDeployGenerate: function(done) {
|
buildDeployGenerate: function(done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
if (self.config.blockchainConfig.enabled === false) {
|
||||||
|
self.logger.info('== blockchain is disabled in this environment in config/blockchain.json'.underline);
|
||||||
|
return done(null, "");
|
||||||
|
}
|
||||||
|
|
||||||
self.logger.setStatus("Deploying...".magenta.underline);
|
self.logger.setStatus("Deploying...".magenta.underline);
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function deployAndBuildContractsManager(callback) {
|
function deployAndBuildContractsManager(callback) {
|
||||||
@ -296,26 +325,14 @@ var Embark = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function generateConsoleABI(contractsManager, callback) {
|
function generateConsoleABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig});
|
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
|
||||||
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, storageConfig: self.config.storageConfig});
|
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
|
||||||
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
||||||
},
|
|
||||||
function buildPipeline(abi, callback) {
|
|
||||||
self.logger.setStatus("Building Assets");
|
|
||||||
var pipeline = new Pipeline({
|
|
||||||
buildDir: self.config.buildDir,
|
|
||||||
contractsFiles: self.config.contractsFiles,
|
|
||||||
assetFiles: self.config.assetFiles,
|
|
||||||
logger: self.logger,
|
|
||||||
plugins: self.plugins
|
|
||||||
});
|
|
||||||
pipeline.build(abi);
|
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -325,7 +342,7 @@ var Embark = {
|
|||||||
} else {
|
} else {
|
||||||
self.logger.setStatus("Ready".green);
|
self.logger.setStatus("Ready".green);
|
||||||
}
|
}
|
||||||
done(result);
|
done(null, result);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
12
test_app/app/test2.html
Normal file
12
test_app/app/test2.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Embark - TestApp</title>
|
||||||
|
<link rel="stylesheet" href="css/app.css">
|
||||||
|
<script src="js/embark.js"></script>
|
||||||
|
</head>
|
||||||
|
<body class="container">
|
||||||
|
|
||||||
|
<div id="tests"></div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"development": {
|
"development": {
|
||||||
|
"enabled": false,
|
||||||
"networkType": "custom",
|
"networkType": "custom",
|
||||||
"genesisBlock": "config/development/genesis.json",
|
"genesisBlock": "config/development/genesis.json",
|
||||||
"datadir": ".embark/development/datadir",
|
"datadir": ".embark/development/datadir",
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
"css/app.css": ["app/css/**"],
|
"css/app.css": ["app/css/**"],
|
||||||
"images/": ["app/images/**"],
|
"images/": ["app/images/**"],
|
||||||
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"],
|
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"],
|
||||||
|
"js/embark.js": ["embark.js"],
|
||||||
"js/abi.js": "abi.js",
|
"js/abi.js": "abi.js",
|
||||||
"index.html": "app/index.html",
|
"index.html": "app/index.html",
|
||||||
"test.html": "app/test.html"
|
"test.html": "app/test.html",
|
||||||
|
"test2.html": "app/test2.html"
|
||||||
},
|
},
|
||||||
"buildDir": "dist/",
|
"buildDir": "dist/",
|
||||||
"config": "config/",
|
"config": "config/",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user