mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
make api only options, add interface and deprecate old api
This commit is contained in:
parent
983921e917
commit
cf8f7720d0
@ -160,12 +160,12 @@ Plugin.prototype.addContractFile = function(file) {
|
||||
this.addPluginType('contractFiles');
|
||||
};
|
||||
|
||||
Plugin.prototype.registerConsoleCommand = function(options, cb) {
|
||||
if (typeof options === 'function') {
|
||||
cb = options;
|
||||
options = {};
|
||||
Plugin.prototype.registerConsoleCommand = function(optionsOrCb) {
|
||||
if (typeof optionsOrCb === 'function') {
|
||||
this.logger.warn(__('Registering console commands with a function is deprecated'));
|
||||
// TODO add docs on how to register
|
||||
}
|
||||
this.console.push({options, execute: cb});
|
||||
this.console.push(optionsOrCb);
|
||||
this.addPluginType('console');
|
||||
};
|
||||
|
||||
|
@ -9,6 +9,12 @@ import Web3 from "web3";
|
||||
import { Embark, Events } from "../../../typings/embark";
|
||||
import Suggestions from "./suggestions";
|
||||
|
||||
interface HelpDescription {
|
||||
matches: string[] | any; // (cmd: string): boolean;
|
||||
description: string;
|
||||
use?: string;
|
||||
}
|
||||
|
||||
class Console {
|
||||
private embark: Embark;
|
||||
private events: Events;
|
||||
@ -72,7 +78,7 @@ class Console {
|
||||
});
|
||||
}
|
||||
|
||||
private processEmbarkCmd(cmd: string, helpDescriptions: any[]) {
|
||||
private processEmbarkCmd(cmd: string, helpDescriptions: HelpDescription[]) {
|
||||
if (cmd === "help" || cmd === __("help") || cmd === "01189998819991197253") {
|
||||
const helpText = [
|
||||
__("Welcome to Embark") + " " + this.version,
|
||||
@ -118,19 +124,23 @@ class Console {
|
||||
const helpDescriptions = [];
|
||||
for (const plugin of plugins) {
|
||||
// New API
|
||||
if (plugin.options.description) {
|
||||
helpDescriptions.push(plugin.options);
|
||||
if (plugin.description) {
|
||||
helpDescriptions.push({
|
||||
description: plugin.description,
|
||||
matches: plugin.matches,
|
||||
use: plugin.use,
|
||||
});
|
||||
}
|
||||
if (plugin.options.matches) {
|
||||
const isFunction = typeof plugin.options.matches === "function";
|
||||
if ((isFunction && plugin.options.matches.call(this, cmd))
|
||||
|| (!isFunction && plugin.options.matches.includes(cmd))) {
|
||||
return plugin.execute.call(this, cmd, callback);
|
||||
if (plugin.matches) {
|
||||
const isFunction = typeof plugin.matches === "function";
|
||||
if ((isFunction && plugin.matches.call(this, cmd))
|
||||
|| (!isFunction && plugin.matches.includes(cmd))) {
|
||||
return plugin.process.call(this, cmd, callback);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const pluginResult = plugin.execute.call(this, cmd, {});
|
||||
const pluginResult = plugin.call(this, cmd, {});
|
||||
|
||||
if (typeof pluginResult !== "object") {
|
||||
if (pluginResult !== false && pluginResult !== "false" && pluginResult !== undefined) {
|
||||
|
@ -45,13 +45,14 @@ class LibraryManager {
|
||||
}
|
||||
this.embark.registerConsoleCommand({
|
||||
matches,
|
||||
description: __("display versions in use for libraries and tools like web3 and solc")
|
||||
}, (cmd, callback) => {
|
||||
let text = [__('versions in use') + ':'];
|
||||
for (let lib in self.versions) {
|
||||
text.push(lib + ": " + self.versions[lib]);
|
||||
description: __("display versions in use for libraries and tools like web3 and solc"),
|
||||
process: (cmd, callback) => {
|
||||
let text = [__('versions in use') + ':'];
|
||||
for (let lib in self.versions) {
|
||||
text.push(lib + ": " + self.versions[lib]);
|
||||
}
|
||||
callback(null, text.join('\n'));
|
||||
}
|
||||
callback(null, text.join('\n'));
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user