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.10 to 2.0.11

lib/deps.d.ts

4

lib/action/base.d.ts

@@ -1,2 +0,2 @@

import { Base } from '../base';
import deps from '../deps';
export declare function getSpinner(): ActionBase;

@@ -8,3 +8,3 @@ export interface ITask {

}
export declare class ActionBase extends Base {
export declare class ActionBase extends deps.Base {
start(action: string, status?: string): void;

@@ -11,0 +11,0 @@ stop(msg?: string): void;

@@ -11,9 +11,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const base_1 = require("../base");
const config_1 = require("../config");
const deps_1 = require("../deps");
function getSpinner() {
let Action;
if (config_1.Config.debug)
if (deps_1.default.Config.debug)
Action = require('./debug').DebugAction;
else if (!config_1.Config.mock &&
else if (!deps_1.default.Config.mock &&
!!process.stdin.isTTY &&

@@ -29,3 +28,3 @@ !!process.stderr.isTTY &&

exports.getSpinner = getSpinner;
class ActionBase extends base_1.Base {
class ActionBase extends deps_1.default.Base {
start(action, status) {

@@ -32,0 +31,0 @@ const task = (this.task = { action, status, active: !!(this.task && this.task.active) });

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

import { ActionBase } from './base';
export declare class DebugAction extends ActionBase {
import deps from '../deps';
export declare class DebugAction extends deps.ActionBase.ActionBase {
_start(): void;

@@ -4,0 +4,0 @@ _pause(): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const base_1 = require("./base");
class DebugAction extends base_1.ActionBase {
const deps_1 = require("../deps");
class DebugAction extends deps_1.default.ActionBase.ActionBase {
_start() {

@@ -6,0 +6,0 @@ const task = this.task;

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

import { ActionBase } from './base';
export declare class SpinnerAction extends ActionBase {
import deps from '../deps';
export declare class SpinnerAction extends deps.ActionBase.ActionBase {
spinner: number;

@@ -4,0 +4,0 @@ frames: any;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const base_1 = require("./base");
const config_1 = require("../config");
const screen_1 = require("../screen");
const deps_1 = require("../deps");
const supportsColor = require("supports-color");
const ansiEscapes = require('ansi-escapes');
const spinners = require('./spinners');
const stripAnsi = require("strip-ansi");
const ansiStyles = require("ansi-styles");
const chalk_1 = require("chalk");
function color(s) {

@@ -16,8 +10,8 @@ if (!supportsColor)

let has256 = supportsColor.has256 || (process.env.TERM || '').indexOf('256') !== -1;
return has256 ? '\u001b[38;5;104m' + s + ansiStyles.reset.open : chalk_1.default.magenta(s);
return has256 ? '\u001b[38;5;104m' + s + deps_1.default.ansiStyles.reset.open : deps_1.default.chalk.magenta(s);
}
class SpinnerAction extends base_1.ActionBase {
class SpinnerAction extends deps_1.default.ActionBase.ActionBase {
constructor() {
super();
this.frames = spinners[config_1.Config.windows ? 'line' : 'dots2'].frames;
this.frames = spinners[deps_1.default.Config.windows ? 'line' : 'dots2'].frames;
this.frameIndex = 0;

@@ -30,3 +24,3 @@ }

this._render();
let interval = (this.spinner = setInterval(this._render.bind(this), config_1.Config.windows ? 500 : 100, 'spinner'));
let interval = (this.spinner = setInterval(this._render.bind(this), deps_1.default.Config.windows ? 500 : 100, 'spinner'));
interval.unref();

@@ -62,3 +56,3 @@ }

let lines = this._lines(this.output);
this._write(ansiEscapes.cursorLeft + ansiEscapes.cursorUp(lines) + ansiEscapes.eraseDown);
this._write(deps_1.default.ansiEscapes.cursorLeft + deps_1.default.ansiEscapes.cursorUp(lines) + deps_1.default.ansiEscapes.eraseDown);
this.output = undefined;

@@ -72,5 +66,6 @@ }

_lines(s) {
return stripAnsi(s)
return deps_1.default
.stripAnsi(s)
.split('\n')
.map(l => Math.ceil(l.length / screen_1.default.errtermwidth))
.map(l => Math.ceil(l.length / deps_1.default.screen.errtermwidth))
.reduce((c, i) => c + i, 0);

@@ -77,0 +72,0 @@ }

@@ -1,8 +0,8 @@

import { StreamOutput } from './stream';
import { Config } from './config';
export declare abstract class Base {
import StreamOutput from './stream';
import deps from './deps';
export default abstract class Base {
stdout: StreamOutput;
stderr: StreamOutput;
config: typeof Config;
config: typeof deps.Config;
constructor();
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const stream_1 = require("./stream");
const config_1 = require("./config");
const deps_1 = require("./deps");
class Base {
constructor() {
this.config = config_1.Config;
this.stdout = new stream_1.StreamOutput('stdout', process.stdout);
this.stderr = new stream_1.StreamOutput('stderr', process.stderr);
this.config = deps_1.default.Config;
this.stdout = new deps_1.default.StreamOutput('stdout', process.stdout);
this.stderr = new deps_1.default.StreamOutput('stderr', process.stderr);
}
}
exports.Base = Base;
exports.default = Base;

@@ -1,2 +0,2 @@

export declare class Config {
export default class Config {
static debug: boolean;

@@ -3,0 +3,0 @@ static mock: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const deps_1 = require("./deps");
class Config {

@@ -15,2 +16,3 @@ static get debug() {

if (mock) {
deps_1.default.chalk.enabled = false;
Config.stdout = '';

@@ -54,2 +56,2 @@ Config.stderr = '';

}
exports.Config = Config;
exports.default = Config;

@@ -1,2 +0,2 @@

import { Base } from './base';
import deps from './deps';
export interface IErrorOptions {

@@ -7,3 +7,3 @@ exitCode?: number | false;

}
export declare class Errors extends Base {
export declare class Errors extends deps.Base {
handleUnhandleds(): void;

@@ -10,0 +10,0 @@ error(err: Error | string, options: Partial<IErrorOptions> & {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const deps_1 = require("./deps");
const util = require("util");
const chalk_1 = require("chalk");
const base_1 = require("./base");
const exit_error_1 = require("./exit_error");
const stream_1 = require("./stream");
const screen_1 = require("./screen");
const config_1 = require("./config");
const arrow = process.platform === 'win32' ? ' !' : ' ▸';

@@ -41,3 +36,3 @@ function bangify(msg, c) {

const linewrap = require('@heroku/linewrap');
return linewrap(6, screen_1.default.errtermwidth, {
return linewrap(6, deps_1.default.screen.errtermwidth, {
skip: /^\$ .*$/,

@@ -47,3 +42,3 @@ skipScheme: 'ansi-color',

}
class Errors extends base_1.Base {
class Errors extends deps_1.default.Base {
handleUnhandleds() {

@@ -65,3 +60,3 @@ process.on('unhandledRejection', (reason, p) => {

options.exitCode = 1;
if (options.severity !== 'warn' && config_1.Config.mock && typeof err !== 'string' && options.exitCode !== false)
if (options.severity !== 'warn' && deps_1.default.Config.mock && typeof err !== 'string' && options.exitCode !== false)
throw err;

@@ -73,3 +68,3 @@ try {

this.logError(err);
if (config_1.Config.debug) {
if (deps_1.default.Config.debug) {
this.stderr.write(`${options.severity.toUpperCase()}: ${prefix}`);

@@ -79,7 +74,7 @@ this.stderr.log(err.stack || util.inspect(err));

else {
let bang = chalk_1.default.red(arrow);
let bang = deps_1.default.chalk.red(arrow);
if (options.severity === 'fatal')
bang = chalk_1.default.bgRed.bold.white(' FATAL ');
bang = deps_1.default.chalk.bgRed.bold.white(' FATAL ');
if (options.severity === 'warn')
bang = chalk_1.default.yellow(arrow);
bang = deps_1.default.chalk.yellow(arrow);
this.stderr.log(bangify(wrap(prefix + getErrorMessage(err)), bang));

@@ -108,7 +103,7 @@ }

exit(code = 0) {
if (config_1.Config.debug) {
if (deps_1.default.Config.debug) {
console.error(`Exiting with code: ${code}`);
}
if (config_1.Config.mock) {
throw new exit_error_1.ExitError(code, this.stdout.output, this.stderr.output);
if (deps_1.default.Config.mock) {
throw new deps_1.default.ExitError(code, this.stdout.output, this.stderr.output);
}

@@ -120,7 +115,7 @@ else {

logError(err) {
if (!config_1.Config.errlog)
if (!deps_1.default.Config.errlog)
return;
stream_1.StreamOutput.logToFile(util.inspect(err) + '\n', config_1.Config.errlog);
deps_1.default.StreamOutput.logToFile(util.inspect(err) + '\n', deps_1.default.Config.errlog);
}
}
exports.Errors = Errors;

@@ -1,11 +0,10 @@

import { StreamOutput } from './stream';
import { Prompt, IPromptOptions } from './prompt';
import StreamOutput from './stream';
import Prompt, { IPromptOptions } from './prompt';
import { Errors, IErrorOptions } from './errors';
import { Base } from './base';
import { ActionBase } from './action/base';
import { TableOptions } from './table';
export declare class CLI extends Base {
import deps from './deps';
export declare class CLI extends deps.Base {
stdout: StreamOutput;
stderr: StreamOutput;
constructor();
private _prompt;

@@ -12,0 +11,0 @@ readonly Prompt: Prompt;

@@ -11,17 +11,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const prompt_1 = require("./prompt");
const errors_1 = require("./errors");
const base_1 = require("./action/base");
const base_2 = require("./base");
const config_1 = require("./config");
const chalk_1 = require("chalk");
class CLI extends base_2.Base {
constructor() {
super();
if (config_1.Config.mock)
chalk_1.default.enabled = false;
}
const deps_1 = require("./deps");
class CLI extends deps_1.default.Base {
get Prompt() {
if (!this._prompt) {
this._prompt = new prompt_1.Prompt();
this._prompt = new deps_1.default.Prompt();
}

@@ -32,3 +22,3 @@ return this._prompt;

if (!this._errors) {
this._errors = new errors_1.Errors();
this._errors = new deps_1.default.Errors();
}

@@ -39,3 +29,3 @@ return this._errors;

if (!this._action)
this._action = base_1.getSpinner();
this._action = deps_1.default.ActionBase.getSpinner();
return this._action;

@@ -46,3 +36,3 @@ }

return this.Prompt.prompt(name, options);
}, chalk_1.default.cyan('?'));
}, deps_1.default.chalk.cyan('?'));
}

@@ -60,3 +50,3 @@ confirm(message) {

return confirm();
}), chalk_1.default.cyan('?'));
}), deps_1.default.chalk.cyan('?'));
}

@@ -71,3 +61,3 @@ log(data, ...args) {

return this.Errors.warn(err, options);
}, chalk_1.default.bold.yellow('!'));
}, deps_1.default.chalk.bold.yellow('!'));
}

@@ -77,3 +67,3 @@ error(err, options = {}) {

return this.Errors.error(err, options);
}, chalk_1.default.bold.red('!'));
}, deps_1.default.chalk.bold.red('!'));
}

@@ -89,3 +79,3 @@ exit(code = 1) {

let json = JSON.stringify(obj, null, 2);
if (chalk_1.default.enabled) {
if (deps_1.default.chalk.enabled) {
let cardinal = require('cardinal');

@@ -100,3 +90,3 @@ let theme = require('cardinal/themes/jq');

styledHeader(header) {
this.log(chalk_1.default.dim('=== ') + chalk_1.default.bold(header));
this.log(deps_1.default.chalk.dim('=== ') + deps_1.default.chalk.bold(header));
}

@@ -121,3 +111,3 @@ styledObject(obj, keys) {

let logKeyValue = (key, value) => {
this.log(`${chalk_1.default.blue(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + pp(value));
this.log(`${deps_1.default.chalk.blue(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + pp(value));
};

@@ -124,0 +114,0 @@ for (var key of keys || Object.keys(obj).sort()) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const screen_1 = require("./screen");
const ts_lodash_1 = require("ts-lodash");
const deps_1 = require("./deps");
function linewrap(length, s) {
const lw = require('@heroku/linewrap');
return lw(length, screen_1.default.stdtermwidth, {
return lw(length, deps_1.default.screen.stdtermwidth, {
skipScheme: 'ansi-color',

@@ -15,3 +14,4 @@ })(s).trim();

}
const maxLength = ts_lodash_1.default.maxBy(items, '[0].length')[0].length;
let { default: _ } = require('ts-lodash');
const maxLength = _.maxBy(items, '[0].length')[0].length;
const lines = items.map(i => {

@@ -23,3 +23,3 @@ let left = i[0];

}
left = `${ts_lodash_1.default.padEnd(left, maxLength)}`;
left = `${_.padEnd(left, maxLength)}`;
right = linewrap(maxLength + 2, right);

@@ -26,0 +26,0 @@ return `${left} ${right}`;

@@ -1,2 +0,2 @@

import { Base } from './base';
import deps from './deps';
export interface IPromptOptions {

@@ -6,5 +6,5 @@ prompt?: string;

}
export declare class Prompt extends Base {
export default class Prompt extends deps.Base {
prompt(name: string, inputOptions?: Partial<IPromptOptions>): Promise<string>;
private normal(options, retries?);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const base_1 = require("./base");
const chalk_1 = require("chalk");
const passwordPrompt = require('password-prompt');
class Prompt extends base_1.Base {
const deps_1 = require("./deps");
class Prompt extends deps_1.default.Base {
prompt(name, inputOptions = {}) {
const options = Object.assign({ isTTY: !!(process.env.TERM !== 'dumb' && process.stdin.isTTY), name, prompt: name ? chalk_1.default.dim(`${name}: `) : chalk_1.default.dim('> '), type: 'normal' }, inputOptions);
const options = Object.assign({ isTTY: !!(process.env.TERM !== 'dumb' && process.stdin.isTTY), name, prompt: name ? deps_1.default.chalk.dim(`${name}: `) : deps_1.default.chalk.dim('> '), type: 'normal' }, inputOptions);
switch (options.type) {

@@ -14,3 +12,3 @@ case 'normal':

case 'hide':
return passwordPrompt(options.prompt, { method: options.type });
return deps_1.default.passwordPrompt(options.prompt, { method: options.type });
default:

@@ -40,2 +38,2 @@ throw new Error(`unexpected type ${options.type}`);

}
exports.Prompt = Prompt;
exports.default = Prompt;
/// <reference types="node" />
export declare class StreamOutput {
export default class StreamOutput {
readonly type: 'stdout' | 'stderr';

@@ -4,0 +4,0 @@ readonly stream: NodeJS.WriteStream;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const deps_1 = require("./deps");
const path = require("path");
const util = require("util");
const config_1 = require("./config");
const stripAnsi = require("strip-ansi");
const fs = require("./fs");
const moment = require("moment");
class StreamOutput {

@@ -17,3 +15,3 @@ constructor(type, stream) {

fs.mkdirpSync(path.dirname(logfile));
fs.appendFileSync(logfile, stripAnsi(msg));
fs.appendFileSync(logfile, deps_1.default.stripAnsi(msg));
}

@@ -25,3 +23,3 @@ catch (err) {

get output() {
return this.type === 'stdout' ? config_1.Config.stdout : config_1.Config.stderr;
return this.type === 'stdout' ? deps_1.default.Config.stdout : deps_1.default.Config.stderr;
}

@@ -34,11 +32,11 @@ write(msg, options = {}) {

// conditionally show timestamp if configured to display
if (StreamOutput.startOfLine && config_1.Config.displayTimestamps) {
if (StreamOutput.startOfLine && deps_1.default.Config.displayTimestamps) {
msg = this.timestamp(msg);
}
if (config_1.Config.mock) {
let m = stripAnsi(msg);
if (deps_1.default.Config.mock) {
let m = deps_1.default.stripAnsi(msg);
if (this.type === 'stdout')
config_1.Config.stdout += m;
deps_1.default.Config.stdout += m;
else
config_1.Config.stderr += m;
deps_1.default.Config.stderr += m;
}

@@ -64,9 +62,9 @@ else {

if (this.type === 'stderr')
return config_1.Config.errlog;
return deps_1.default.Config.errlog;
}
timestamp(msg) {
return `[${moment().format()}] ${msg}`;
return `[${deps_1.default.moment().format()}] ${msg}`;
}
}
StreamOutput.startOfLine = false;
exports.StreamOutput = StreamOutput;
exports.default = StreamOutput;

@@ -1,2 +0,2 @@

import { StreamOutput } from './stream';
import StreamOutput from './stream';
export declare type TableColumn = {

@@ -3,0 +3,0 @@ key: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ts_lodash_1 = require("ts-lodash");
const stripAnsi = require("strip-ansi");
const deps_1 = require("./deps");
/**

@@ -47,3 +47,3 @@ * Generates a Unicode table and feeds it into configured printer.

function calcWidth(cell) {
let lines = stripAnsi(cell).split(/[\r\n]+/);
let lines = deps_1.default.stripAnsi(cell).split(/[\r\n]+/);
let lineLengths = lines.map(ts_lodash_1.default.property('length'));

@@ -53,3 +53,3 @@ return Math.max.apply(Math, lineLengths);

function pad(string, length) {
let visibleLength = stripAnsi(string).length;
let visibleLength = deps_1.default.stripAnsi(string).length;
let diff = length - visibleLength;

@@ -56,0 +56,0 @@ return string + ' '.repeat(Math.max(0, diff));

{
"name": "cli-ux",
"description": "set of CLI output utilities",
"version": "2.0.10",
"version": "2.0.11",
"author": "Jeff Dickey",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/jdxcode/cli-ux/issues",

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