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.build();
|
||||
this.run();
|
||||
this.console();
|
||||
this.blockchain();
|
||||
this.simulator();
|
||||
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() {
|
||||
program
|
||||
.command('blockchain [environment]')
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"run": "run",
|
||||
"upload": "upload",
|
||||
"build": "build",
|
||||
"console": "console",
|
||||
"graph": "graph",
|
||||
"test": "test",
|
||||
"reset": "reset",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
let blessed = require("neo-blessed");
|
||||
let CommandHistory = require('./command_history.js');
|
||||
|
||||
class Dashboard {
|
||||
class Monitor {
|
||||
constructor(_options) {
|
||||
let options = _options || {};
|
||||
this.env = options.env;
|
||||
|
@ -378,4 +378,4 @@ class Dashboard {
|
|||
|
||||
}
|
||||
|
||||
module.exports = Dashboard;
|
||||
module.exports = Monitor;
|
||||
|
|
|
@ -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];
|
||||
let Dashboard = require('./dashboard/dashboard.js');
|
||||
|
||||
let webServerConfig = {
|
||||
enabled: options.runWebserver
|
||||
};
|
||||
let webServerConfig = {
|
||||
enabled: options.runWebserver
|
||||
};
|
||||
|
||||
if (options.serverHost) {
|
||||
webServerConfig.host = options.serverHost;
|
||||
}
|
||||
if (options.serverPort) {
|
||||
webServerConfig.port = options.serverPort;
|
||||
}
|
||||
if (options.serverHost) {
|
||||
webServerConfig.host = options.serverHost;
|
||||
}
|
||||
if (options.serverPort) {
|
||||
webServerConfig.port = options.serverPort;
|
||||
}
|
||||
|
||||
const Engine = require('./core/engine.js');
|
||||
const engine = new Engine({
|
||||
|
@ -204,6 +204,7 @@ class Embark {
|
|||
engine.startService("deployment", {onlyCompile: options.onlyCompile});
|
||||
engine.startService("storage");
|
||||
engine.startService("codeGenerator");
|
||||
|
||||
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) {
|
||||
this.context = options.context || [constants.contexts.graph];
|
||||
options.onlyCompile = true;
|
||||
|
|
Loading…
Reference in New Issue