Socket
Socket
Sign inDemoInstall

cli-ux

Package Overview
Dependencies
Maintainers
1
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 0.0.1 to 1.0.0

lib/action/base.d.ts

1

lib/base.d.ts

@@ -6,2 +6,3 @@ import { StreamOutput } from './stream';

debug: boolean;
mock: boolean;
errlog?: string;

@@ -8,0 +9,0 @@ }

3

lib/base.js
"use strict";
// @flow
Object.defineProperty(exports, "__esModule", { value: true });

@@ -7,3 +6,3 @@ const stream_1 = require("./stream");

constructor(options = {}) {
this.options = Object.assign({ debug: !!options.debug, stderr: new stream_1.StreamOutput(), stdout: new stream_1.StreamOutput() }, options);
this.options = Object.assign({ debug: !!options.debug, mock: !!options.mock, stderr: new stream_1.StreamOutput(), stdout: new stream_1.StreamOutput() }, options);
this.stdout = this.options.stdout;

@@ -10,0 +9,0 @@ this.stderr = this.options.stderr;

@@ -0,5 +1,13 @@

/// <reference types="chalk" />
import ansiStyles = require('ansi-styles');
import chalk = require('chalk');
import * as moment from 'moment';
export declare const deps: {
readonly ansiStyles: typeof ansiStyles;
readonly ansiEscapes: any;
readonly chalk: typeof chalk;
readonly moment: typeof moment;
readonly stripAnsi: (str: string) => string;
readonly supportsColor: any;
readonly passwordPrompt: any;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deps = {
get ansiStyles() {
return fetch('ansi-styles');
},
get ansiEscapes() {
return fetch('ansi-escapes');
},
get chalk() {
return fetch('chalk');
},
get moment() {

@@ -10,2 +19,8 @@ return fetch('moment');

},
get supportsColor() {
return fetch('supports-color');
},
get passwordPrompt() {
return fetch('password-prompt');
},
};

@@ -12,0 +27,0 @@ const cache = {};

@@ -6,4 +6,6 @@ import { Base } from './base';

export declare class Errors extends Base {
error(err: Error | string, exitCode?: number | false): void;
warn(err: Error | string, options?: IWarnOptions): void;
exit(code?: number): void;
private logError(err);
}
"use strict";
// @flow
Object.defineProperty(exports, "__esModule", { value: true });
const chalk = require("chalk");
const util = require("util");
const deps_1 = require("./deps");
const base_1 = require("./base");
const exit_error_1 = require("./exit_error");
const stream_1 = require("./stream");

@@ -46,4 +46,25 @@ const arrow = process.platform === 'win32' ? '!' : '▸';

class Errors extends base_1.Base {
error(err, exitCode = 1) {
try {
if (typeof err === 'string') {
err = new Error(err);
}
this.logError(err);
if (this.options.debug) {
this.stderr.log(err.stack || util.inspect(err));
}
else {
this.stderr.log(bangify(wrap(getErrorMessage(err)), deps_1.deps.chalk.red(arrow)));
}
}
catch (e) {
console.error('error displaying error');
console.error(e);
console.error(err);
}
if (exitCode !== false) {
this.exit(exitCode);
}
}
warn(err, options = {}) {
// this.action.pause(() => {
try {

@@ -58,12 +79,23 @@ const prefix = options.prefix ? `${options.prefix} ` : '';

else {
this.stderr.log(bangify(wrap(prefix + getErrorMessage(err)), chalk.yellow(arrow)));
this.stderr.log(bangify(wrap(prefix + getErrorMessage(err)), deps_1.deps.chalk.yellow(arrow)));
}
}
catch (e) {
console.error('error displaying warning'); // tslint:disable-line:no-console
console.error(e); // tslint:disable-line:no-console
console.error(err); // tslint:disable-line:no-console
console.error('error displaying warning');
console.error(e);
console.error(err);
}
// }, this.color.bold.yellow('!'))
}
exit(code = 0) {
if (this.options.debug) {
console.error(`Exiting with code: ${code}`);
}
if (this.options.mock) {
throw new exit_error_1.ExitError(code, this.stdout.output, this.stderr.output);
}
else {
process.exit(code);
}
}
logError(err) {

@@ -70,0 +102,0 @@ if (!this.options.errlog) {

@@ -0,1 +1,4 @@

import { ActionBase } from './action/base';
import { IWarnOptions } from './errors';
import { IPromptOptions } from './prompt';
export interface IOptions {

@@ -8,10 +11,15 @@ errlog?: string;

readonly options: IOptions;
action: ActionBase;
private stdoutStream;
private stderrStream;
private errors;
private errorsDep;
private promptDep;
constructor(options?: IOptions);
readonly stderr: string;
readonly stdout: string;
readonly warn: any;
prompt(name: string, options?: IPromptOptions): Promise<any>;
log(data: string, ...args: any[]): void;
warn(err: Error | string, options?: IWarnOptions): void;
error(err: Error | string, exitCode?: number | false): void;
}
export declare const cli: CLI;
"use strict";
// @flow
Object.defineProperty(exports, "__esModule", { value: true });
const base_1 = require("./action/base");
const spinner_1 = require("./action/spinner");
const simple_1 = require("./action/simple");
const errors_1 = require("./errors");
const prompt_1 = require("./prompt");
const stream_1 = require("./stream");
const deps_1 = require("./deps");
class CLI {

@@ -13,6 +17,9 @@ constructor(options = {}) {

debug: !!options.debug,
mock: !!options.mock,
stderr: this.stderrStream,
stdout: this.stdoutStream,
};
this.errors = new errors_1.Errors(depOpts);
this.errorsDep = new errors_1.Errors(depOpts);
this.promptDep = new prompt_1.Prompt(depOpts);
this.action = base_1.shouldDisplaySpinner(depOpts) ? new spinner_1.SpinnerAction(depOpts) : new simple_1.SimpleAction(depOpts);
}

@@ -33,10 +40,24 @@ get stderr() {

}
// public warn(err: Error | string, options: { prefix?: string } = {}) {
// return this.errors.warn(err, options)
// }
get warn() {
return this.errors.warn.bind(this.errors);
prompt(name, options = {}) {
return this.action.pauseAsync(() => {
return this.promptDep.prompt(name, options);
}, deps_1.deps.chalk.cyan('?'));
}
log(data, ...args) {
this.action.pause(() => {
return this.stdoutStream.log(data, ...args);
});
}
warn(err, options = {}) {
this.action.pause(() => {
return this.errorsDep.warn(err, options);
}, deps_1.deps.chalk.bold.yellow('!'));
}
error(err, exitCode = 1) {
this.action.pause(() => {
return this.errorsDep.error(err, exitCode);
}, deps_1.deps.chalk.bold.red('!'));
}
}
exports.CLI = CLI;
exports.cli = new CLI();

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

declare function termwidth(stream: any): number;
declare const columns: number | null;
export declare const errtermwidth: number;
export declare const stdtermwidth: number;
"use strict";
// @flow
Object.defineProperty(exports, "__esModule", { value: true });
function termwidth(stream) {

@@ -16,7 +16,4 @@ if (!stream.isTTY) {

}
// tslint:disable-next-line
const columns = global['columns'];
module.exports = {
errtermwidth: columns || termwidth(process.stderr),
stdtermwidth: columns || termwidth(process.stdout),
};
exports.errtermwidth = columns || termwidth(process.stderr);
exports.stdtermwidth = columns || termwidth(process.stdout);

@@ -10,4 +10,4 @@ /// <reference types="node" />

private static startOfLine;
logfile: string | undefined;
output: string;
private logfile;
private displayTimestamps;

@@ -20,3 +20,4 @@ private mock;

log(data: string, ...args: any[]): void;
writeLogFile(msg: string, withTimestamp: boolean): void;
private timestamp(msg);
}
"use strict";
// @flow
Object.defineProperty(exports, "__esModule", { value: true });

@@ -20,3 +19,2 @@ const fs = require("fs-extra");

catch (err) {
// tslint:disable-next-line:no-console
console.error(err);

@@ -44,4 +42,10 @@ }

this.write(msg);
// this.out.action.pause(() => this.write(msg))
}
writeLogFile(msg, withTimestamp) {
if (!this.logfile) {
return;
}
msg = withTimestamp ? this.timestamp(msg) : msg;
StreamOutput.logToFile(msg, this.logfile);
}
timestamp(msg) {

@@ -48,0 +52,0 @@ return `[${deps_1.deps.moment().format()}] ${msg}`;

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

@@ -9,17 +9,24 @@ "bugs": "https://github.com/jdxcode/cli-ux/issues",

"@types/fs-extra": "^4.0.2",
"ansi-escapes": "^3.0.0",
"ansi-styles": "^3.2.0",
"chalk": "^2.1.0",
"fs-extra": "^4.0.1",
"moment": "^2.18.1",
"strip-ansi": "^4.0.0"
"password-prompt": "^1.0.3",
"strip-ansi": "^4.0.0",
"supports-color": "^4.4.0"
},
"devDependencies": {
"@heroku/linewrap": "^1.0.0",
"@types/ansi-styles": "^2.0.30",
"@types/chalk": "^0.4.31",
"@types/jest": "^20.0.8",
"@types/node": "^8.0.27",
"@types/node": "^8.0.28",
"@types/strip-ansi": "^3.0.0",
"@types/supports-color": "^3.1.0",
"husky": "^0.14.3",
"jest": "^21.0.2",
"lint-staged": "^4.1.0",
"lint-staged": "^4.1.3",
"prettier": "^1.6.1",
"remap-istanbul": "^0.9.5",
"rimraf": "^2.6.1",

@@ -29,4 +36,2 @@ "std-mocks": "^1.0.1",

"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"tslint-config-prettier": "^1.5.0",
"typescript": "^2.5.2"

@@ -58,3 +63,2 @@ },

"prettier --write",
"tslint --fix",
"git add",

@@ -67,3 +71,3 @@ "jest --bail --findRelatedTests"

"scripts": {
"posttest": "tslint --project .",
"coverage": "cat coverage/coverage-final.json | remap-istanbul -o coverage/coverage-final.json && curl -s https://codecov.io/bash | bash",
"precommit": "lint-staged",

@@ -70,0 +74,0 @@ "prepare": "rimraf lib && tsc",

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