Socket
Socket
Sign inDemoInstall

cli-ux

Package Overview
Dependencies
Maintainers
3
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-ux - npm Package Compare versions

Comparing version 2.0.21 to 3.0.0-alpha.0

lib/exit.d.ts

17

lib/config.d.ts

@@ -1,10 +0,9 @@

export default class Config {
static debug: boolean;
static mock: boolean;
static displayTimestamps: boolean;
static errlog: string | undefined;
static stdout: string;
static stderr: string;
static readonly windows: boolean;
static readonly _globals: any;
import Rx = require('rxjs/Rx');
import { ConfigMessage } from './message';
export declare type Levels = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
export declare class Config extends Rx.Subject<ConfigMessage> {
logLevel: Levels;
outputLevel: Levels;
errlog: string | undefined;
}
export declare const config: Config;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const deps_1 = require("./deps");
class Config {
static get debug() {
return !!Config._globals.debug;
const Rx = require("rxjs/Rx");
const semver = require("semver");
const version = semver.parse(require('../package.json').version);
const globals = global['cli-ux'] || (global['cli-ux'] = {});
class Config extends Rx.Subject {
constructor() {
super(...arguments);
this.logLevel = 'warn';
this.outputLevel = 'info';
}
static set debug(debug) {
Config._globals.debug = debug;
get errlog() { return globals.errlog; }
set errlog(errlog) {
globals.errlog = errlog;
this.next({ type: 'config', prop: 'errlog', value: errlog });
}
static get mock() {
return !!Config._globals.mock;
}
static set mock(mock) {
if (mock) {
deps_1.default.chalk.enabled = false;
Config.stdout = '';
Config.stderr = '';
}
Config._globals.mock = mock;
}
static get displayTimestamps() {
return !!Config._globals.displayTimestamps;
}
static set displayTimestamps(displayTimestamps) {
Config._globals.displayTimestamps = displayTimestamps;
}
static get errlog() {
return Config._globals.errlog;
}
static set errlog(errlog) {
Config._globals.errlog = errlog;
}
static get stdout() {
return Config._globals.stdout || '';
}
static set stdout(stdout) {
Config._globals.stdout = stdout;
}
static get stderr() {
return Config._globals.stderr || '';
}
static set stderr(stderr) {
Config._globals.stderr = stderr;
}
static get windows() {
return process.platform === 'win32';
}
static get _globals() {
const globals = (global['cli-ux'] = global['cli-ux'] || {});
globals.action = globals.action || {};
return globals;
}
}
exports.default = Config;
exports.Config = Config;
function current() {
if (!globals[version.major] || globals[version.major].closed)
return;
return globals[version.major];
}
function fetch() {
let subject = current();
if (subject)
return subject;
return globals[version.major] = new Config();
}
exports.config = fetch();

@@ -1,17 +0,3 @@

import deps from './deps';
export interface IErrorOptions {
exitCode?: number | false;
severity: 'warn' | 'fatal' | 'error';
context?: string;
}
export declare class Errors extends deps.Base {
handleUnhandleds(): void;
error(err: Error | string, options: Partial<IErrorOptions> & {
exitCode: false;
}): void;
error(err: Error | string, options?: Partial<IErrorOptions>): never;
fatal(err: Error | string, options?: Partial<IErrorOptions>): void;
warn(err: Error | string, options?: Partial<IErrorOptions>): void;
exit(code?: number): void;
private logError(err);
}
import Rx = require('rxjs/Rx');
import { CLI } from '.';
export default function (cli: CLI): Rx.Observable<any>;
"use strict";
// tslint:disable no-console
Object.defineProperty(exports, "__esModule", { value: true });
const deps_1 = require("./deps");
const util = require("util");
const arrow = process.platform === 'win32' ? ' !' : ' ▸';
const screen = require("@dxcli/screen");
const chalk_1 = require("chalk");
const util_1 = require("util");
const _1 = require(".");
const arrow = process.platform === 'win32' ? ' ×' : ' ✖';
function bangify(msg, c) {

@@ -19,6 +22,6 @@ const lines = msg.split('\n');

if (err.body.message) {
message = util.inspect(err.body.message);
message = util_1.inspect(err.body.message);
}
else if (err.body.error) {
message = util.inspect(err.body.error);
message = util_1.inspect(err.body.error);
}

@@ -28,3 +31,3 @@ }

if (err.message && err.code) {
message = `${util.inspect(err.code)}: ${err.message}`;
message = `${util_1.inspect(err.code)}: ${err.message}`;
}

@@ -34,7 +37,7 @@ else if (err.message) {

}
return message || util.inspect(err);
return message || util_1.inspect(err);
}
function wrap(msg) {
const linewrap = require('@heroku/linewrap');
return linewrap(6, deps_1.default.screen.errtermwidth, {
return linewrap(6, screen.errtermwidth, {
skip: /^\$ .*$/,

@@ -44,75 +47,55 @@ skipScheme: 'ansi-color',

}
class Errors extends deps_1.default.Base {
handleUnhandleds() {
process.on('unhandledRejection', (reason, p) => {
this.fatal(reason, { context: 'Promise unhandledRejection' });
});
process.on('uncaughtException', error => {
this.fatal(error, { context: 'Error uncaughtException' });
});
function default_1(cli) {
function renderError(message) {
let bang = chalk_1.default.red(arrow);
if (message.severity === 'fatal')
bang = chalk_1.default.bgRed.bold.white(' FATAL ');
if (message.severity === 'warn')
bang = chalk_1.default.yellow(arrow);
const msg = cli.scope ? `${cli.scope}: ${getErrorMessage(message.error)}` : getErrorMessage(message.error);
return bangify(wrap(msg), bang);
}
error(err, options) {
if (typeof options === 'string')
options = { context: options };
options = options || {};
if (!options.severity)
options.severity = 'error';
if (options.exitCode === undefined)
options.exitCode = 1;
if (options.severity !== 'warn' && deps_1.default.Config.mock && typeof err !== 'string' && options.exitCode !== false)
throw err;
const handleError = (scope) => async (err) => {
// ignore EPIPE errors
// these come from using | head and | tail
// and can be ignored
try {
if (typeof err === 'string')
err = new Error(err);
const prefix = options.context ? `${options.context}: ` : '';
this.logError(err);
if (deps_1.default.Config.debug) {
this.stderr.write(`${options.severity.toUpperCase()}: ${prefix}`);
this.stderr.log(err.stack || util.inspect(err));
if (err.code === 'EPIPE')
return;
if (err.code === 'EEXIT') {
process.exitCode = err.status;
}
else {
let bang = deps_1.default.chalk.red(arrow);
if (options.severity === 'fatal')
bang = deps_1.default.chalk.bgRed.bold.white(' FATAL ');
if (options.severity === 'warn')
bang = deps_1.default.chalk.yellow(arrow);
this.stderr.log(bangify(wrap(prefix + getErrorMessage(err)), bang));
const cli = new _1.CLI(scope);
cli.fatal(err, { exit: false });
await cli.done();
process.exit(100);
}
}
catch (e) {
console.error('error displaying error');
console.error(e);
catch (err) {
console.error(err);
process.exit(101);
}
if (options.exitCode !== false)
this.exit(options.exitCode);
};
function handleUnhandleds() {
process.once('SIGINT', () => {
const cli = new _1.CLI('SIGINT');
const err = new Error();
err.code = 'ESIGINT';
cli.error(err);
});
process.once('unhandledRejection', handleError('unhandledRejection'));
process.once('uncaughtException', handleError('uncaughtException'));
process.stdout.on('error', handleError);
process.stderr.on('error', handleError);
}
fatal(err, options = {}) {
options.severity = 'fatal';
this.error(err, options);
}
warn(err, options = {}) {
if (typeof options === 'string')
options = { context: options };
options.exitCode = false;
options.severity = 'warn';
this.error(err, options);
}
exit(code = 0) {
if (deps_1.default.Config.debug) {
console.error(`Exiting with code: ${code}`);
}
if (deps_1.default.Config.mock) {
throw new deps_1.default.ExitError(code, this.stdout.output, this.stderr.output);
}
else {
process.exit(code);
}
}
logError(err) {
if (!deps_1.default.Config.errlog)
return;
deps_1.default.StreamOutput.logToFile(util.inspect(err) + '\n', deps_1.default.Config.errlog);
}
handleUnhandleds();
return cli
.takeUntil(cli.filter(m => m.type === 'done'))
.filter((m) => m.type === 'error')
.do(m => {
cli.next({ type: 'logger', severity: m.severity, message: getErrorMessage(m.error) });
process.stderr.write(renderError(m) + '\n');
});
}
exports.Errors = Errors;
exports.default = default_1;

@@ -1,37 +0,24 @@

import StreamOutput from './stream';
import Prompt, { IPromptOptions } from './prompt';
import { Errors, IErrorOptions } from './errors';
import { ActionBase } from './action/base';
import { TableOptions } from './table';
import deps from './deps';
export declare class CLI extends deps.Base {
stdout: StreamOutput;
stderr: StreamOutput;
private _prompt;
readonly Prompt: Prompt;
private _errors;
readonly Errors: Errors;
private _action;
readonly action: ActionBase;
prompt(name: string, options?: IPromptOptions): Promise<any>;
confirm(message: string): Promise<boolean>;
log(data?: string, ...args: any[]): void;
warn(err: Error | string, options?: Partial<IErrorOptions>): void;
error(err: Error | string, options?: Partial<IErrorOptions>): void;
exit(code?: number): void;
table(data: any[], options: Partial<TableOptions>): any;
styledJSON(obj: any): void;
styledHeader(header: string): void;
styledObject(obj: any, keys: string[]): void;
readonly color: any;
/**
* puts in a handler for process.on('uncaughtException') and process.on('unhandledRejection')
*/
handleUnhandleds(): void;
/**
* cleanup any outstanding output like actions that need to be stopped
*/
done(): void;
import Rx = require('rxjs/Rx');
import { Message } from './message';
import { Config } from './config';
export interface IErrorOptions {
exit?: number | false;
}
export declare const cli: CLI;
export default cli;
export declare class CLI extends Rx.Subject<Message> {
scope: string | undefined;
children: Rx.Observable<any>;
subscription: Rx.Subscription;
config: Config;
constructor(scope?: string | undefined);
fatal(input: Error | string, options?: IErrorOptions): void;
error(input: Error | string, options?: IErrorOptions): void;
warn(input: Error | string): void;
info(...input: any[]): void;
debug(...input: any[]): void;
trace(...input: any[]): void;
exit(code?: number, error?: Error): void;
done(): Promise<void>;
private reset();
}
declare const _default: CLI;
export default _default;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const deps_1 = require("./deps");
// import { deprecate } from 'util'
const deprecate = process.env.DEBUG ? require('util').deprecate : (fn) => () => fn();
const deprecatedColor = deprecate(() => require('@heroku-cli/color').default, "cli.color is deprecated. Please use `import color from '@heroku-cli/color'` instead.");
class CLI extends deps_1.default.Base {
get Prompt() {
if (!this._prompt) {
this._prompt = new deps_1.default.Prompt();
}
return this._prompt;
const Rx = require("rxjs/Rx");
const errors_1 = require("./errors");
const exit_1 = require("./exit");
const logger_1 = require("./logger");
const output_1 = require("./output");
const config_1 = require("./config");
const buildError = (i) => i instanceof Error ? i : new Error(i);
class CLI extends Rx.Subject {
constructor(scope) {
super();
this.scope = scope;
this.config = config_1.config;
this.reset();
this.config.subscribe(this);
}
get Errors() {
if (!this._errors) {
this._errors = new deps_1.default.Errors();
}
return this._errors;
fatal(input, options = {}) {
const error = buildError(input);
this.next({ type: 'error', severity: 'fatal', error });
const code = getExitCode(options);
if (code !== false)
this.exit(code, error);
}
get action() {
if (!this._action)
this._action = deps_1.default.ActionBase.getSpinner();
return this._action;
error(input, options = {}) {
const error = buildError(input);
this.next({ type: 'error', severity: 'error', error });
const code = getExitCode(options);
if (code !== false)
this.exit(code, error);
}
prompt(name, options = {}) {
return this.action.pauseAsync(() => {
return this.Prompt.prompt(name, options);
}, deps_1.default.chalk.cyan('?'));
warn(input) {
const error = buildError(input);
this.next({ type: 'error', severity: 'warn', error });
}
confirm(message) {
return this.action.pauseAsync(() => __awaiter(this, void 0, void 0, function* () {
const confirm = () => __awaiter(this, void 0, void 0, function* () {
let response = (yield this.Prompt.prompt(message)).toLowerCase();
if (['n', 'no'].includes(response))
return false;
if (['y', 'yes'].includes(response))
return true;
return confirm();
});
return confirm();
}), deps_1.default.chalk.cyan('?'));
info(...input) {
this.next({ type: 'output', severity: 'info', input });
}
log(data, ...args) {
this.action.pause(() => {
return this.stdout.log(data, ...args);
});
debug(...input) {
this.next({ type: 'output', severity: 'debug', input });
}
warn(err, options = {}) {
this.emit('warn', typeof err === 'string' ? new Error(err) : err);
this.action.pause(() => {
return this.Errors.warn(err, options);
}, deps_1.default.chalk.bold.yellow('!'));
trace(...input) {
this.next({ type: 'output', severity: 'trace', input });
}
error(err, options = {}) {
this.emit('error', typeof err === 'string' ? new Error(err) : err);
this.action.pause(() => {
return this.Errors.error(err, options);
}, deps_1.default.chalk.bold.red('!'));
exit(code = 1, error) {
throw new exit_1.ExitError(code, error);
}
exit(code = 1) {
this.Errors.exit(code);
async done() {
await new Promise((resolve, reject) => {
this.children.subscribe({ error: reject, complete: resolve });
this.next({ type: 'done' });
});
this.reset();
}
table(data, options) {
let table = require('./table');
return table(this, data, options);
reset() {
this.children = Rx.Observable.forkJoin(errors_1.default(this), output_1.default(this), logger_1.default(this)).share();
this.children.subscribe();
}
styledJSON(obj) {
let json = JSON.stringify(obj, null, 2);
if (deps_1.default.chalk.enabled) {
let cardinal = require('cardinal');
let theme = require('cardinal/themes/jq');
this.log(cardinal.highlight(json, { json: true, theme: theme }));
}
else {
this.log(json);
}
}
styledHeader(header) {
this.log(deps_1.default.chalk.dim('=== ') + deps_1.default.chalk.bold(header));
}
styledObject(obj, keys) {
const util = require('util');
let keyLengths = Object.keys(obj).map(key => key.toString().length);
let maxKeyLength = Math.max.apply(Math, keyLengths) + 2;
function pp(obj) {
if (typeof obj === 'string' || typeof obj === 'number') {
return obj;
}
else if (typeof obj === 'object') {
return Object.keys(obj)
.map(k => k + ': ' + util.inspect(obj[k]))
.join(', ');
}
else {
return util.inspect(obj);
}
}
let logKeyValue = (key, value) => {
this.log(`${deps_1.default.chalk.blue(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + pp(value));
};
for (var key of keys || Object.keys(obj).sort()) {
let value = obj[key];
if (Array.isArray(value)) {
if (value.length > 0) {
logKeyValue(key, value[0]);
for (var e of value.slice(1)) {
this.log(' '.repeat(maxKeyLength) + pp(e));
}
}
}
else if (value !== null && value !== undefined) {
logKeyValue(key, value);
}
}
}
get color() {
return deprecatedColor();
}
/**
* puts in a handler for process.on('uncaughtException') and process.on('unhandledRejection')
*/
handleUnhandleds() {
this.Errors.handleUnhandleds();
}
/**
* cleanup any outstanding output like actions that need to be stopped
*/
done() {
this.action.stop();
}
}
exports.CLI = CLI;
exports.cli = new CLI();
exports.default = exports.cli;
// swallow error event so it does not cause a crash
exports.cli.on('error', () => { });
function getExitCode(options) {
let exit = options.exit === undefined ? options.exitCode : options.exit;
if (exit === false)
return false;
if (exit === undefined)
return 1;
return exit;
}
exports.default = new CLI();
{
"name": "cli-ux",
"description": "set of CLI output utilities",
"version": "2.0.21",
"author": "Jeff Dickey",
"bugs": "https://github.com/heroku/cli-ux/issues",
"description": "cli IO utilities",
"version": "3.0.0-alpha.0",
"author": "Jeff Dickey @jdxcode",
"bugs": "https://github.com/dxcli/cli-ux/issues",
"dependencies": {
"@cli-engine/screen": "^0.0.0",
"@heroku-cli/color": "^1.0.4",
"@dxcli/screen": "^0.0.0",
"@heroku/linewrap": "^1.0.0",
"ansi-escapes": "^3.0.0",
"ansi-styles": "^3.2.0",
"cardinal": "^1.0.0",
"chalk": "^2.3.0",
"fs-extra": "^5.0.0",
"lodash": "^4.17.4",
"moment": "^2.20.1",
"password-prompt": "^1.0.3",
"strip-ansi": "^4.0.0",
"supports-color": "^5.1.0",
"ts-lodash": "^4.0.8"
"rxjs": "^5.5.6",
"semver": "^5.4.1"
},
"devDependencies": {
"@types/ansi-styles": "^2.0.30",
"@types/jest": "^21.1.9",
"@types/lodash": "^4.14.91",
"@types/node": "^8.5.2",
"@types/strip-ansi": "^3.0.0",
"@types/supports-color": "^3.1.0",
"babel-core": "^6.26.0",
"del-cli": "^1.1.0",
"@dxcli/dev": "^1.1.3",
"@dxcli/dev-semantic-release": "^0.0.3",
"@dxcli/dev-test": "^0.2.0",
"@dxcli/dev-tslint": "^0.0.14",
"@types/fs-extra": "^5.0.0",
"@types/node": "^9.3.0",
"@types/semver": "^5.4.0",
"eslint": "^4.15.0",
"eslint-config-dxcli": "^1.1.4",
"husky": "^0.14.3",
"jest": "^22.0.4",
"prettier": "^1.9.2",
"std-mocks": "^1.0.1",
"ts-jest": "^22.0.0",
"mocha": "^4.1.0",
"nyc": "^11.4.1",
"ts-node": "^4.1.0",
"typescript": "^2.6.2"
},
"dxcli": {
"workflows": {
"test": [
"eslint .",
"tsc -p test --noEmit",
"tslint -p test",
"commitlint --from origin/master",
"mocha \"test/**/*.ts\""
],
"lint": [
"eslint .",
"tsc -p test --noEmit",
"tslint -p test",
"commitlint --from origin/master"
]
}
},
"engines": {
"node": ">=6.0.0"
"node": ">=8.0.0"
},
"files": [
"lib"
"/lib"
],
"homepage": "https://github.com/heroku/cli-ux",
"homepage": "https://github.com/dxcli/cli-ux",
"keywords": [
"cli"
"dxcli"
],
"license": "ISC",
"main": "./lib/index.js",
"repository": "heroku/cli-ux",
"license": "MIT",
"main": "lib/index.js",
"repository": "dxcli/cli-ux",
"scripts": {
"prepare": "del lib && tsc",
"pretest": "tsc",
"test": "jest"
"commitmsg": "dxcli-dev-commitmsg",
"lint": "dxcli-dev lint",
"precommit": "dxcli-dev lint",
"prepare": "rm -rf lib && tsc",
"test": "dxcli-dev test"
},
"types": "./lib/index.d.ts"
"types": "lib/index.d.ts"
}
cli-ux
==========
======
[![CircleCI](https://circleci.com/gh/heroku/cli-ux.svg?style=svg)](https://circleci.com/gh/heroku/cli-ux)
cli IO utilities
[![Version](https://img.shields.io/npm/v/cli-ux.svg)](https://npmjs.org/package/cli-ux)
[![CircleCI](https://circleci.com/gh/dxcli/cli-ux/tree/master.svg?style=svg)](https://circleci.com/gh/dxcli/cli-ux/tree/master)
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/dxcli/cli-ux?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/cli-ux/branch/master)
[![Codecov](https://codecov.io/gh/dxcli/cli-ux/branch/master/graph/badge.svg)](https://codecov.io/gh/dxcli/cli-ux)
[![Greenkeeper](https://badges.greenkeeper.io/dxcli/cli-ux.svg)](https://greenkeeper.io/)
[![Known Vulnerabilities](https://snyk.io/test/npm/cli-ux/badge.svg)](https://snyk.io/test/npm/cli-ux)
[![Downloads/week](https://img.shields.io/npm/dw/cli-ux.svg)](https://npmjs.org/package/cli-ux)
[![License](https://img.shields.io/npm/l/cli-ux.svg)](https://github.com/dxcli/cli-ux/blob/master/package.json)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc