mirror of https://github.com/embarklabs/embark.git
chore: move console to module
This commit is contained in:
parent
2044ed5e9b
commit
661ce74877
|
@ -0,0 +1,4 @@
|
|||
engine-strict = true
|
||||
package-lock = false
|
||||
save-exact = true
|
||||
scripts-prepend-node-path = true
|
|
@ -0,0 +1,6 @@
|
|||
# `embark-console`
|
||||
|
||||
> Console component for Embark
|
||||
|
||||
Visit [embark.status.im](https://embark.status.im/) to get started with
|
||||
[Embark](https://github.com/embark-framework/embark).
|
|
@ -0,0 +1,85 @@
|
|||
{
|
||||
"name": "embark-console",
|
||||
"version": "4.1.0-beta.0",
|
||||
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
||||
"contributors": [],
|
||||
"description": "Console component for Embark",
|
||||
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-console#readme",
|
||||
"bugs": "https://github.com/embark-framework/embark/issues",
|
||||
"keywords": [
|
||||
"blockchain",
|
||||
"dapps",
|
||||
"ethereum",
|
||||
"ipfs",
|
||||
"serverless",
|
||||
"solc",
|
||||
"solidity"
|
||||
],
|
||||
"files": [
|
||||
"dist/lib"
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/embark-console",
|
||||
"type": "git",
|
||||
"url": "https://github.com/embark-framework/embark.git"
|
||||
},
|
||||
"main": "./dist/lib/index.js",
|
||||
"scripts": {
|
||||
"build": "cross-env BABEL_ENV=node babel src --extensions \".js,.ts\" --out-dir dist --root-mode upward --source-maps",
|
||||
"ci": "npm run qa",
|
||||
"clean": "npm run reset",
|
||||
"lint": "npm-run-all lint:*",
|
||||
"lint:js": "eslint src/",
|
||||
"lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
|
||||
"package": "npm pack",
|
||||
"qa": "npm-run-all lint typecheck build test package",
|
||||
"reset": "npx rimraf dist embark-*.tgz package",
|
||||
"start": "npm run watch",
|
||||
"test": "nyc --reporter=html --reporter=json mocha \"dist/test/**/*.js\" --exit --no-timeouts --require source-map-support/register",
|
||||
"typecheck": "tsc",
|
||||
"watch": "run-p watch:*",
|
||||
"watch:build": "npm run build -- --verbose --watch",
|
||||
"watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "../../.eslintrc.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs2": "7.3.1",
|
||||
"async": "2.6.1",
|
||||
"chalk": "2.4.2",
|
||||
"embark-core": "^4.1.0-beta.0",
|
||||
"embark-utils": "^4.1.0-beta.0",
|
||||
"i18n": "0.8.3",
|
||||
"json-stringify-safe": "5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/embark": "^4.0.0",
|
||||
"@types/json-stringify-safe": "5.0.0",
|
||||
"@babel/cli": "7.2.3",
|
||||
"@babel/core": "7.2.2",
|
||||
"cross-env": "5.2.0",
|
||||
"embark-logger": "^4.1.0-beta.0",
|
||||
"eslint": "5.7.0",
|
||||
"mocha": "5.2.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"nyc": "13.1.0",
|
||||
"rimraf": "2.6.3",
|
||||
"source-map-support": "0.5.9",
|
||||
"tslint": "5.16.0",
|
||||
"typescript": "3.4.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.12.0",
|
||||
"npm": ">=6.4.1",
|
||||
"yarn": ">=1.12.3"
|
||||
},
|
||||
"nyc": {
|
||||
"exclude": [
|
||||
"**/node_modules/**",
|
||||
"coverage/**",
|
||||
"dist/test/**"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,14 +1,11 @@
|
|||
/*globals __*/
|
||||
import "colors";
|
||||
const env = require("../../core/env");
|
||||
const utils = require("../../utils/utils");
|
||||
const {escapeHtml, exit} = require("embark-utils");
|
||||
import { Callback } from "embark";
|
||||
import constants from "embark-core/constants.json";
|
||||
const stringify = require("json-stringify-safe");
|
||||
import { waterfall } from "async";
|
||||
import { Embark, Events } from "embark";
|
||||
import {__} from "i18n";
|
||||
import chalk from "chalk";
|
||||
import { Callback, Embark, Events } /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
||||
import constants from "embark-core/constants.json";
|
||||
import { escapeHtml, exit, jsonFunctionReplacer } from "embark-utils";
|
||||
import { __ } from "i18n";
|
||||
import stringify from "json-stringify-safe";
|
||||
import { dirname } from "path";
|
||||
import Suggestions from "./suggestions";
|
||||
|
||||
type MatchFunction = (cmd: string) => boolean;
|
||||
|
@ -91,7 +88,7 @@ class Console {
|
|||
}
|
||||
|
||||
private cmdHistorySize() {
|
||||
return env.anchoredValue(env.CMD_HISTORY_SIZE);
|
||||
return parseInt(process.env.CMD_HISTORY_SIZE || constants.console.commandHistorySize, 10);
|
||||
}
|
||||
|
||||
private registerApi() {
|
||||
|
@ -103,7 +100,7 @@ class Console {
|
|||
}
|
||||
let response = result;
|
||||
if (typeof result !== "string") {
|
||||
response = stringify(result, utils.jsonFunctionReplacer, 2);
|
||||
response = stringify(result, jsonFunctionReplacer, 2);
|
||||
} else {
|
||||
// Avoid HTML injection in the Cockpit
|
||||
response = escapeHtml(response);
|
||||
|
@ -125,21 +122,21 @@ class Console {
|
|||
__("possible commands are:"),
|
||||
// TODO: only if the blockchain is actually active!
|
||||
// will need to pass te current embark state here
|
||||
"ipfs".cyan + " - " + __("instantiated js-ipfs object configured to the current environment (available if ipfs is enabled)"),
|
||||
"swarm".cyan + " - " + __("instantiated swarm-api object configured to the current environment (available if swarm is enabled)"),
|
||||
"web3".cyan + " - " + __("instantiated web3.js object configured to the current environment"),
|
||||
"EmbarkJS".cyan + " - " + __("EmbarkJS static functions for Storage, Messages, Names, etc."),
|
||||
"log [process] on/off".cyan + " - " + __("Activate or deactivate the logs of a sub-process. Options: blockchain, ipfs, webserver"),
|
||||
chalk.cyan("ipfs") + " - " + __("instantiated js-ipfs object configured to the current environment (available if ipfs is enabled)"),
|
||||
chalk.cyan("swarm") + " - " + __("instantiated swarm-api object configured to the current environment (available if swarm is enabled)"),
|
||||
chalk.cyan("web3") + " - " + __("instantiated web3.js object configured to the current environment"),
|
||||
chalk.cyan("EmbarkJS") + " - " + __("EmbarkJS static functions for Storage, Messages, Names, etc."),
|
||||
chalk.cyan("log [process] on/off") + " - " + __("Activate or deactivate the logs of a sub-process. Options: blockchain, ipfs, webserver"),
|
||||
];
|
||||
helpDescriptions.forEach((helpDescription) => {
|
||||
let matches = [] as string[];
|
||||
if (Array.isArray(helpDescription.matches)) {
|
||||
matches = helpDescription.matches as string[];
|
||||
}
|
||||
helpText.push(`${(helpDescription.usage || matches.join("/")).cyan} - ${helpDescription.description}`);
|
||||
helpText.push(`${chalk.cyan(helpDescription.usage || matches.join("/"))} - ${helpDescription.description}`);
|
||||
});
|
||||
// Add end commands
|
||||
helpText.push("quit".cyan + " - " + __("to immediatly exit (alias: exit)"),
|
||||
helpText.push(chalk.cyan("quit") + " - " + __("to immediatly exit (alias: exit)"),
|
||||
"",
|
||||
__("The web3 object and the interfaces for the deployed contracts and their methods are also available"));
|
||||
return helpText.join("\n");
|
||||
|
@ -297,7 +294,7 @@ class Console {
|
|||
this.ipc.client.emit("console:history:save", cmd);
|
||||
}
|
||||
|
||||
if (this.fs.existsSync(utils.dirname(this.cmdHistoryFile))) {
|
||||
if (this.fs.existsSync(dirname(this.cmdHistoryFile))) {
|
||||
this.fs.writeFileSync(
|
||||
this.cmdHistoryFile,
|
||||
history
|
|
@ -1,6 +1,6 @@
|
|||
const fuzzySearch = require("../../utils/utils").fuzzySearch;
|
||||
|
||||
import { Embark, Events } from "embark";
|
||||
import { Embark, Events } /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
||||
import { fuzzySearch } from "embark-utils";
|
||||
import { suggestions as defaultSuggestions } from "../../suggestions.json";
|
||||
|
||||
interface ContractsManager {
|
||||
[key: string]: any;
|
||||
|
@ -18,7 +18,7 @@ export default class Suggestions {
|
|||
private embark: Embark;
|
||||
private events: Events;
|
||||
private contracts: ContractsManager;
|
||||
private static readonly DEFAULT_SUGGESTIONS = require("./suggestions.json").suggestions;
|
||||
private static readonly DEFAULT_SUGGESTIONS = defaultSuggestions;
|
||||
private _suggestions: SuggestionsList = [];
|
||||
|
||||
constructor(embark: Embark, options?: object) {
|
|
@ -1,25 +1,38 @@
|
|||
/*globals describe, it*/
|
||||
let Console = require('../lib/modules/console/');
|
||||
let Plugins = require('../lib/core/plugins.js');
|
||||
let IPC = require('../lib/core/ipc.js');
|
||||
let Logger = require('embark-logger');
|
||||
let assert = require('assert');
|
||||
let version = require('../../package.json').version;
|
||||
import Console from '../lib';
|
||||
import Logger from 'embark-logger';
|
||||
import assert from 'assert';
|
||||
import { version } from '../../package.json';
|
||||
import * as i18n from "i18n";
|
||||
|
||||
i18n.configure({
|
||||
directory: undefined,
|
||||
locales: []
|
||||
});
|
||||
|
||||
describe('embark.Console', function() {
|
||||
let ipc = new IPC({ipcRole: 'none'});
|
||||
let events = {once: () => {}, setCommandHandler: () => {}, emit: () => {}, on: () => {}, request: () => {}};
|
||||
let logger = new Logger({logLevel: 'error'});
|
||||
let plugins = new Plugins({plugins: {}, events, logger});
|
||||
let ipc = {
|
||||
isServer: () => { return true; },
|
||||
broadcast: () => {},
|
||||
on: () => {},
|
||||
isClient: () => { return false; }
|
||||
};
|
||||
let events = {once: () => {}, setCommandHandler: () => {}, emit: () => {}, on: () => {}, request: () => {}};
|
||||
let plugins = {
|
||||
logger: logger,
|
||||
createPlugin: () => { return {registerAPICall: () => {}}; },
|
||||
getPluginsProperty: () => { return []; }
|
||||
};
|
||||
let embarkObject = {
|
||||
registerAPICall: () => {},
|
||||
events: events,
|
||||
logger: plugins.logger,
|
||||
fs: {
|
||||
existsSync: () => { return false },
|
||||
dappPath: () => { return "ok" }
|
||||
existsSync: () => { return false; },
|
||||
dappPath: () => { return "ok"; }
|
||||
},
|
||||
registerConsoleCommand: (cmd, opt) => {},
|
||||
registerConsoleCommand: (_cmd, _opt) => {},
|
||||
embarkConfig: {
|
||||
options: {
|
||||
solc: {
|
||||
|
@ -28,7 +41,7 @@ describe('embark.Console', function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let console = new Console(embarkObject, {plugins, version, ipc, events, logger});
|
||||
|
||||
describe('#executeCmd', function() {
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src/**/*"]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": "../../tslint.json"
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"httpContractsDirectory": ".embark/contracts/",
|
||||
"console": {
|
||||
"commandHistorySize": "20"
|
||||
},
|
||||
"contexts": {
|
||||
"simulator": "simulator",
|
||||
"blockchain": "blockchain",
|
||||
|
|
|
@ -51,14 +51,15 @@
|
|||
"colors": "1.3.2",
|
||||
"ethereumjs-wallet": "0.6.0",
|
||||
"follow-redirects": "1.5.7",
|
||||
"fuzzy": "0.1.3",
|
||||
"i18n": "0.8.3",
|
||||
"merge": "1.2.1",
|
||||
"multihashes": "0.4.14",
|
||||
"ora": "2.1.0",
|
||||
"shelljs": "0.5.3",
|
||||
"web3": "1.0.0-beta.37",
|
||||
"web3-eth": "1.0.0-beta.37",
|
||||
"web3-eth-abi": "1.0.0-beta.37",
|
||||
"shelljs": "0.5.3"
|
||||
"web3-eth-abi": "1.0.0-beta.37"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
|
|
|
@ -165,12 +165,26 @@ function prepareContractsConfig(config) {
|
|||
return config;
|
||||
}
|
||||
|
||||
function jsonFunctionReplacer(_key, value) {
|
||||
if (typeof value === 'function') {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function fuzzySearch(text, list, filter) {
|
||||
const fuzzy = require('fuzzy');
|
||||
return fuzzy.filter(text, list, {extract: (filter || function () {})});
|
||||
}
|
||||
|
||||
const Utils = {
|
||||
joinPath: function() {
|
||||
const path = require('path');
|
||||
return path.join.apply(path.join, arguments);
|
||||
},
|
||||
jsonFunctionReplacer,
|
||||
fuzzySearch,
|
||||
canonicalHost,
|
||||
copyToClipboard,
|
||||
deconstructUrl,
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
"embark-authenticator": "^4.1.0-beta.0",
|
||||
"embark-api": "^4.1.0-beta.0",
|
||||
"embark-compiler": "^4.0.0",
|
||||
"embark-console": "^4.1.0-beta.0",
|
||||
"embark-contracts-manager": "^4.1.0-beta.0",
|
||||
"embark-core": "^4.1.0-beta.0",
|
||||
"embark-ens": "^4.1.0-beta.0",
|
||||
|
@ -125,7 +126,6 @@
|
|||
"flatted": "0.2.3",
|
||||
"follow-redirects": "1.5.7",
|
||||
"fs-extra": "7.0.1",
|
||||
"fuzzy": "0.1.3",
|
||||
"ganache-cli": "6.2.3",
|
||||
"glob": "7.1.3",
|
||||
"globule": "1.2.1",
|
||||
|
|
|
@ -170,7 +170,7 @@ class Engine {
|
|||
}
|
||||
|
||||
console(_options) {
|
||||
this.registerModule('console', {
|
||||
this.registerModulePackage('embark-console', {
|
||||
events: this.events,
|
||||
plugins: this.plugins,
|
||||
version: this.version,
|
||||
|
|
|
@ -34,10 +34,6 @@ const DAPP_PATH = 'DAPP_PATH';
|
|||
const DEFAULT_DAPP_PATH = anchoredValue(PWD);
|
||||
anchoredValue(DAPP_PATH, DEFAULT_DAPP_PATH);
|
||||
|
||||
const CMD_HISTORY_SIZE = 'CMD_HISTORY_SIZE';
|
||||
const DEFAULT_CMD_HISTORY_SIZE = 20;
|
||||
anchoredValue(CMD_HISTORY_SIZE, DEFAULT_CMD_HISTORY_SIZE);
|
||||
|
||||
const DIAGRAM_PATH = 'DIAGRAM_PATH';
|
||||
const DEFAULT_DIAGRAM_PATH = joinPath(anchoredValue(DAPP_PATH), 'diagram.svg');
|
||||
anchoredValue(DIAGRAM_PATH, DEFAULT_DIAGRAM_PATH);
|
||||
|
@ -74,7 +70,6 @@ module.exports = {
|
|||
anchoredValue,
|
||||
PWD,
|
||||
DAPP_PATH,
|
||||
CMD_HISTORY_SIZE,
|
||||
DIAGRAM_PATH,
|
||||
EMBARK_PATH,
|
||||
PKG_PATH
|
||||
|
|
|
@ -394,19 +394,6 @@ function fileTreeSort(nodes){
|
|||
return folders.concat(files);
|
||||
}
|
||||
|
||||
function fuzzySearch(text, list, filter) {
|
||||
const fuzzy = require('fuzzy');
|
||||
return fuzzy.filter(text, list, {extract: (filter || function () {})});
|
||||
}
|
||||
|
||||
function jsonFunctionReplacer(_key, value) {
|
||||
if (typeof value === 'function') {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function getWindowSize() {
|
||||
const windowSize = require('window-size');
|
||||
if (windowSize) {
|
||||
|
@ -467,8 +454,6 @@ module.exports = {
|
|||
interceptLogs,
|
||||
errorMessage,
|
||||
fileTreeSort,
|
||||
fuzzySearch,
|
||||
jsonFunctionReplacer,
|
||||
getWindowSize,
|
||||
isEs6Module,
|
||||
urlJoin
|
||||
|
|
|
@ -2803,6 +2803,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/i18n/-/i18n-0.8.3.tgz#f602164f2fae486ea87590f6be5d6dd5db1664e6"
|
||||
integrity sha512-JyNZyqamS3jfJ/qTXkAIAtBKlapN5OrEVosdde6LT41Gf209NzXppDVoNkn1pABGZbSnT8dgEgiuTFBIgxweIQ==
|
||||
|
||||
"@types/json-stringify-safe@5.0.0":
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/json-stringify-safe/-/json-stringify-safe-5.0.0.tgz#df34d054419d39323a3730966bacba02ac5e474e"
|
||||
integrity sha512-UUA1sH0RSRROdInuDOA1yoRzbi5xVFD1RHCoOvNRPTNwR8zBkJ/84PZ6NhKVDtKp0FTeIccJCdQz1X2aJPr4uw==
|
||||
|
||||
"@types/lockfile@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/lockfile/-/lockfile-1.0.0.tgz#76a7c19c50fe8ee2b1666d653ff5d557c30fe0ff"
|
||||
|
@ -11897,7 +11902,7 @@ json-stable-stringify@^1.0.1:
|
|||
dependencies:
|
||||
jsonify "~0.0.0"
|
||||
|
||||
json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
|
||||
json-stringify-safe@5.0.1, json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
|
||||
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=
|
||||
|
|
Loading…
Reference in New Issue