mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-24 14:18:57 +00:00
Merge pull request #636 from embark-framework/feature/command-console
Add console command
This commit is contained in:
commit
0a795c2c5d
21
lib/cmd.js
21
lib/cmd.js
@ -13,6 +13,7 @@ class Cmd {
|
|||||||
this.demo();
|
this.demo();
|
||||||
this.build();
|
this.build();
|
||||||
this.run();
|
this.run();
|
||||||
|
this.console();
|
||||||
this.blockchain();
|
this.blockchain();
|
||||||
this.simulator();
|
this.simulator();
|
||||||
this.test();
|
this.test();
|
||||||
@ -138,6 +139,26 @@ class Cmd {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console() {
|
||||||
|
program
|
||||||
|
.command('console [environment]')
|
||||||
|
.option('-c, --client [client]', __('Use a specific ethereum client or simulator (supported: %s)', 'geth, testrpc'))
|
||||||
|
.option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none'))
|
||||||
|
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
||||||
|
.option('--locale [locale]', __('language to use (default: en)'))
|
||||||
|
.description(__('Start the Embark console'))
|
||||||
|
.action(function (env, options) {
|
||||||
|
i18n.setOrDetectLocale(options.locale);
|
||||||
|
embark.console({
|
||||||
|
env: env || 'development',
|
||||||
|
client: options.client || 'geth',
|
||||||
|
locale: options.locale,
|
||||||
|
logFile: options.logfile,
|
||||||
|
logLevel: options.loglevel
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
blockchain() {
|
blockchain() {
|
||||||
program
|
program
|
||||||
.command('blockchain [environment]')
|
.command('blockchain [environment]')
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"run": "run",
|
"run": "run",
|
||||||
"upload": "upload",
|
"upload": "upload",
|
||||||
"build": "build",
|
"build": "build",
|
||||||
|
"console": "console",
|
||||||
"graph": "graph",
|
"graph": "graph",
|
||||||
"test": "test",
|
"test": "test",
|
||||||
"reset": "reset",
|
"reset": "reset",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
let blessed = require("neo-blessed");
|
let blessed = require("neo-blessed");
|
||||||
let CommandHistory = require('./command_history.js');
|
let CommandHistory = require('./command_history.js');
|
||||||
|
|
||||||
class Dashboard {
|
class Monitor {
|
||||||
constructor(_options) {
|
constructor(_options) {
|
||||||
let options = _options || {};
|
let options = _options || {};
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
@ -378,4 +378,4 @@ class Dashboard {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Dashboard;
|
module.exports = Monitor;
|
||||||
|
49
lib/dashboard/repl.js
Normal file
49
lib/dashboard/repl.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
const repl = require("repl");
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
|
const Console = require('./console.js');
|
||||||
|
|
||||||
|
class REPL {
|
||||||
|
constructor(options) {
|
||||||
|
this.env = options.env;
|
||||||
|
this.plugins = options.plugins;
|
||||||
|
this.events = options.events;
|
||||||
|
this.console = new Console({
|
||||||
|
events: this.events,
|
||||||
|
plugins: this.plugins,
|
||||||
|
version: options.version
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
enhancedEval(cmd, context, filename, callback) {
|
||||||
|
this.console.executeCmd(cmd.trim(), (result) => {
|
||||||
|
callback(null, result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
enhancedWriter(output) {
|
||||||
|
if ((typeof output) === "string") {
|
||||||
|
return output;
|
||||||
|
} else {
|
||||||
|
return util.inspect(output, {colors: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
start(done) {
|
||||||
|
this.replServer = repl.start({
|
||||||
|
prompt: "Embark (" + this.env + ") > ",
|
||||||
|
useGlobal: true,
|
||||||
|
eval: this.enhancedEval.bind(this),
|
||||||
|
writer: this.enhancedWriter.bind(this)
|
||||||
|
});
|
||||||
|
|
||||||
|
this.replServer.on("exit", () => {
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = REPL;
|
83
lib/index.js
83
lib/index.js
@ -65,16 +65,16 @@ class Embark {
|
|||||||
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
self.context = options.context || [constants.contexts.run, constants.contexts.build];
|
||||||
let Dashboard = require('./dashboard/dashboard.js');
|
let Dashboard = require('./dashboard/dashboard.js');
|
||||||
|
|
||||||
let webServerConfig = {
|
let webServerConfig = {
|
||||||
enabled: options.runWebserver
|
enabled: options.runWebserver
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.serverHost) {
|
if (options.serverHost) {
|
||||||
webServerConfig.host = options.serverHost;
|
webServerConfig.host = options.serverHost;
|
||||||
}
|
}
|
||||||
if (options.serverPort) {
|
if (options.serverPort) {
|
||||||
webServerConfig.port = options.serverPort;
|
webServerConfig.port = options.serverPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Engine = require('./core/engine.js');
|
const Engine = require('./core/engine.js');
|
||||||
const engine = new Engine({
|
const engine = new Engine({
|
||||||
@ -204,6 +204,7 @@ class Embark {
|
|||||||
engine.startService("deployment", {onlyCompile: options.onlyCompile});
|
engine.startService("deployment", {onlyCompile: options.onlyCompile});
|
||||||
engine.startService("storage");
|
engine.startService("storage");
|
||||||
engine.startService("codeGenerator");
|
engine.startService("codeGenerator");
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function deploy(callback) {
|
function deploy(callback) {
|
||||||
@ -237,6 +238,70 @@ class Embark {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console(options) {
|
||||||
|
this.context = options.context || [constants.contexts.run, constants.contexts.console];
|
||||||
|
const REPL = require('./dashboard/repl.js');
|
||||||
|
const Engine = require('./core/engine.js');
|
||||||
|
const engine = new Engine({
|
||||||
|
env: options.env,
|
||||||
|
client: options.client,
|
||||||
|
locale: options.locale,
|
||||||
|
version: this.version,
|
||||||
|
embarkConfig: options.embarkConfig || 'embark.json',
|
||||||
|
logFile: options.logFile,
|
||||||
|
logLevel: options.logLevel,
|
||||||
|
context: this.context
|
||||||
|
});
|
||||||
|
engine.init();
|
||||||
|
async.waterfall([
|
||||||
|
function startServices(callback) {
|
||||||
|
let pluginList = engine.plugins.listPlugins();
|
||||||
|
if (pluginList.length > 0) {
|
||||||
|
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.startService("libraryManager");
|
||||||
|
engine.startService("codeRunner");
|
||||||
|
engine.startService("web3");
|
||||||
|
engine.startService("pipeline");
|
||||||
|
engine.startService("deployment", {onlyCompile: false});
|
||||||
|
engine.startService("storage");
|
||||||
|
engine.startService("codeGenerator");
|
||||||
|
engine.startService("fileWatcher");
|
||||||
|
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function deploy(callback) {
|
||||||
|
engine.events.request('deploy:contracts', function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function waitForWriteFinish(callback) {
|
||||||
|
engine.logger.info("Finished deploying".underline);
|
||||||
|
engine.events.once('outputDone', (err) => {
|
||||||
|
engine.logger.info(__("finished building").underline);
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function startREPL(callback) {
|
||||||
|
let repl = new REPL({
|
||||||
|
env: engine.env,
|
||||||
|
plugins: engine.plugins,
|
||||||
|
version: engine.version,
|
||||||
|
events: engine.events
|
||||||
|
});
|
||||||
|
repl.start(callback);
|
||||||
|
}
|
||||||
|
], function (err, _result) {
|
||||||
|
if (err) {
|
||||||
|
engine.logger.error(err.message);
|
||||||
|
engine.logger.info(err.stack);
|
||||||
|
} else {
|
||||||
|
engine.events.emit('firstDeploymentDone');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
graph(options) {
|
graph(options) {
|
||||||
this.context = options.context || [constants.contexts.graph];
|
this.context = options.context || [constants.contexts.graph];
|
||||||
options.onlyCompile = true;
|
options.onlyCompile = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user