mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-23 12:11:16 +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;
|
||||
if (provider === '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();
|
||||
} else if (provider === 'orbit') {
|
||||
this.currentMessages = EmbarkJS.Messages.Orbit;
|
||||
|
@ -2,6 +2,7 @@
|
||||
var ABIGenerator = function(options) {
|
||||
this.blockchainConfig = options.blockchainConfig || {};
|
||||
this.storageConfig = options.storageConfig || {};
|
||||
this.communicationConfig = options.communicationConfig || {};
|
||||
this.contractsManager = options.contractsManager;
|
||||
this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost;
|
||||
this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort;
|
||||
@ -13,6 +14,10 @@ ABIGenerator.prototype.generateProvider = function() {
|
||||
var result = "";
|
||||
var providerPlugins;
|
||||
|
||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (this.plugins) {
|
||||
providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider');
|
||||
}
|
||||
@ -38,6 +43,10 @@ ABIGenerator.prototype.generateContracts = function(useEmbarkJS) {
|
||||
var result = "\n";
|
||||
var contractsPlugins;
|
||||
|
||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (this.plugins) {
|
||||
contractsPlugins = this.plugins.getPluginsFor('contractGeneration');
|
||||
}
|
||||
@ -70,7 +79,7 @@ ABIGenerator.prototype.generateStorageInitialization = function(useEmbarkJS) {
|
||||
var self = this;
|
||||
var result = "\n";
|
||||
|
||||
if (!useEmbarkJS || self.storageConfig === {}) return;
|
||||
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 + "'});";
|
||||
@ -83,7 +92,7 @@ ABIGenerator.prototype.generateCommunicationInitialization = function(useEmbarkJ
|
||||
var self = this;
|
||||
var result = "\n";
|
||||
|
||||
if (!useEmbarkJS || self.communicationConfig === {}) return;
|
||||
if (!useEmbarkJS || self.communicationConfig === {}) return "";
|
||||
|
||||
if (self.communicationConfig.provider === 'ipfs' && self.communicationConfig.enabled === true) {
|
||||
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();
|
||||
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) {
|
||||
if (err) {
|
||||
self.logger.error(err.message);
|
||||
@ -136,6 +148,18 @@ var Embark = {
|
||||
callback();
|
||||
},
|
||||
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) {
|
||||
self.logger.setStatus("Watching for changes");
|
||||
var watch = new Watch({logger: self.logger});
|
||||
@ -285,6 +309,11 @@ var Embark = {
|
||||
buildDeployGenerate: function(done) {
|
||||
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);
|
||||
async.waterfall([
|
||||
function deployAndBuildContractsManager(callback) {
|
||||
@ -296,26 +325,14 @@ var Embark = {
|
||||
});
|
||||
},
|
||||
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});
|
||||
Embark.console.runCode(consoleABI);
|
||||
callback(null, contractsManager);
|
||||
},
|
||||
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}));
|
||||
},
|
||||
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) {
|
||||
if (err) {
|
||||
@ -325,7 +342,7 @@ var Embark = {
|
||||
} else {
|
||||
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": {
|
||||
"enabled": false,
|
||||
"networkType": "custom",
|
||||
"genesisBlock": "config/development/genesis.json",
|
||||
"datadir": ".embark/development/datadir",
|
||||
|
@ -4,9 +4,11 @@
|
||||
"css/app.css": ["app/css/**"],
|
||||
"images/": ["app/images/**"],
|
||||
"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",
|
||||
"index.html": "app/index.html",
|
||||
"test.html": "app/test.html"
|
||||
"test.html": "app/test.html",
|
||||
"test2.html": "app/test2.html"
|
||||
},
|
||||
"buildDir": "dist/",
|
||||
"config": "config/",
|
||||
|
Loading…
x
Reference in New Issue
Block a user