mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
add more support for the console
This commit is contained in:
parent
70c9a1d9c5
commit
2f9c0a2996
18
lib/abi.js
18
lib/abi.js
@ -19,7 +19,7 @@ ABIGenerator.prototype.generateProvider = function() {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
ABIGenerator.prototype.generateContracts = function() {
|
ABIGenerator.prototype.generateContracts = function(useEmbarkJS) {
|
||||||
var result = "\n";
|
var result = "\n";
|
||||||
|
|
||||||
for(var className in this.contractsManager.contracts) {
|
for(var className in this.contractsManager.contracts) {
|
||||||
@ -27,23 +27,23 @@ ABIGenerator.prototype.generateContracts = function() {
|
|||||||
|
|
||||||
var abi = JSON.stringify(contract.abiDefinition);
|
var abi = JSON.stringify(contract.abiDefinition);
|
||||||
|
|
||||||
//console.log('address is ' + contract.deployedAddress);
|
if (useEmbarkJS) {
|
||||||
|
|
||||||
//result += "\n" + className + "Abi = " + abi + ";";
|
|
||||||
//result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
|
|
||||||
//result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
|
|
||||||
|
|
||||||
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "'});";
|
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "'});";
|
||||||
|
} else {
|
||||||
|
result += "\n" + className + "Abi = " + abi + ";";
|
||||||
|
result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
|
||||||
|
result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
ABIGenerator.prototype.generateABI = function() {
|
ABIGenerator.prototype.generateABI = function(options) {
|
||||||
var result = "";
|
var result = "";
|
||||||
|
|
||||||
result += this.generateProvider();
|
result += this.generateProvider();
|
||||||
result += this.generateContracts();
|
result += this.generateContracts(options.useEmbarkJS);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
35
lib/console.js
Normal file
35
lib/console.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
var Web3 = require('web3');
|
||||||
|
|
||||||
|
var Console = function(options) {
|
||||||
|
};
|
||||||
|
|
||||||
|
Console.prototype.runCode = function(code) {
|
||||||
|
eval(code);
|
||||||
|
};
|
||||||
|
|
||||||
|
Console.prototype.executeCmd = function(cmd, callback) {
|
||||||
|
if (cmd === 'help') {
|
||||||
|
var helpText = [
|
||||||
|
'Welcome to Embark 2',
|
||||||
|
'',
|
||||||
|
'possible commands are:',
|
||||||
|
'quit - to immediatly exit',
|
||||||
|
'',
|
||||||
|
'The web3 object and the interfaces for the deployed contrats and their methods are also available'
|
||||||
|
];
|
||||||
|
return callback(helpText.join('\n'));
|
||||||
|
} else if (cmd === 'quit') {
|
||||||
|
exit();
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
var result = eval(cmd);
|
||||||
|
return callback(result);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
return callback(e.message.red);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Console;
|
||||||
|
|
40
lib/index.js
40
lib/index.js
@ -21,6 +21,7 @@ var Logger = require('./logger.js');
|
|||||||
var Config = require('./config.js');
|
var Config = require('./config.js');
|
||||||
var Monitor = require('./monitor.js');
|
var Monitor = require('./monitor.js');
|
||||||
var ServicesMonitor = require('./services.js');
|
var ServicesMonitor = require('./services.js');
|
||||||
|
var Console = require('./console.js');
|
||||||
|
|
||||||
var Embark = {
|
var Embark = {
|
||||||
|
|
||||||
@ -47,8 +48,12 @@ var Embark = {
|
|||||||
run: function(env) {
|
run: function(env) {
|
||||||
var self = this;
|
var self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
function startConsole(callback) {
|
||||||
|
Embark.console = new Console();
|
||||||
|
callback();
|
||||||
|
},
|
||||||
function startMonitor(callback) {
|
function startMonitor(callback) {
|
||||||
Embark.monitor = new Monitor({env: env});
|
Embark.monitor = new Monitor({env: env, console: Embark.console});
|
||||||
Embark.monitor.setStatus("Starting");
|
Embark.monitor.setStatus("Starting");
|
||||||
self.logger.logFunction = Embark.monitor.logEntry;
|
self.logger.logFunction = Embark.monitor.logEntry;
|
||||||
self.logger.contractsState = Embark.monitor.setContracts;
|
self.logger.contractsState = Embark.monitor.setContracts;
|
||||||
@ -63,12 +68,22 @@ var Embark = {
|
|||||||
Embark.servicesMonitor.startMonitor();
|
Embark.servicesMonitor.startMonitor();
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function deployAndGenerateABI(callback) {
|
function deployAndBuildContractsManager(callback) {
|
||||||
Embark.monitor.setStatus("Deploying Contracts");
|
Embark.monitor.setStatus("Deploying Contracts");
|
||||||
Embark.deploy(function(abi) {
|
Embark.buildAndDeploy(function(contractsManager) {
|
||||||
callback(null, abi);
|
callback(null, contractsManager);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
function generateConsoleABI(contractsManager, callback) {
|
||||||
|
var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager);
|
||||||
|
var consoleABI = abiGenerator.generateABI({useEmbarkJS: false});
|
||||||
|
Embark.console.runCode(consoleABI);
|
||||||
|
callback(null, contractsManager);
|
||||||
|
},
|
||||||
|
function generateABI(contractsManager, callback) {
|
||||||
|
var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager);
|
||||||
|
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
||||||
|
},
|
||||||
function buildPipeline(abi, callback) {
|
function buildPipeline(abi, callback) {
|
||||||
Embark.monitor.setStatus("Building Assets");
|
Embark.monitor.setStatus("Building Assets");
|
||||||
var pipeline = new Pipeline({
|
var pipeline = new Pipeline({
|
||||||
@ -119,7 +134,7 @@ var Embark = {
|
|||||||
blockchain.run({env: env});
|
blockchain.run({env: env});
|
||||||
},
|
},
|
||||||
|
|
||||||
deploy: function(done) {
|
buildAndDeploy: function(done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function buildContracts(callback) {
|
function buildContracts(callback) {
|
||||||
@ -144,10 +159,23 @@ var Embark = {
|
|||||||
deploy.deployAll(function() {
|
deploy.deployAll(function() {
|
||||||
callback(null, contractsManager);
|
callback(null, contractsManager);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
], function(err, result) {
|
||||||
|
done(result);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
deploy: function(done) {
|
||||||
|
var self = this;
|
||||||
|
async.waterfall([
|
||||||
|
function buildAndDeploy(callback) {
|
||||||
|
Embark.buildAndDeploy(function(contractsManager) {
|
||||||
|
callback(null, contractsManager);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function generateABI(contractsManager, callback) {
|
function generateABI(contractsManager, callback) {
|
||||||
var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager);
|
var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager);
|
||||||
callback(null, abiGenerator.generateABI());
|
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
|
||||||
},
|
},
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
done(result);
|
done(result);
|
||||||
|
@ -10,6 +10,7 @@ var blessed = require("blessed");
|
|||||||
function Dashboard(options) {
|
function Dashboard(options) {
|
||||||
var title = options && options.title || "Embark 2.0";
|
var title = options && options.title || "Embark 2.0";
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
|
this.console = options.console;
|
||||||
|
|
||||||
this.color = options && options.color || "green";
|
this.color = options && options.color || "green";
|
||||||
this.minimal = options && options.minimal || false;
|
this.minimal = options && options.minimal || false;
|
||||||
@ -318,10 +319,10 @@ Dashboard.prototype.layoutCmd = function() {
|
|||||||
this.input.on('submit', function(data) {
|
this.input.on('submit', function(data) {
|
||||||
if (data !== '') {
|
if (data !== '') {
|
||||||
self.logText.log('console> ' + data);
|
self.logText.log('console> ' + data);
|
||||||
|
self.console.executeCmd(data, function(result) {
|
||||||
|
self.logText.log(result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (data === 'quit') {
|
|
||||||
exit();
|
|
||||||
};
|
|
||||||
self.input.clearValue();
|
self.input.clearValue();
|
||||||
self.input.focus();
|
self.input.focus();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user