Comparing version 1.1.13 to 2.0.0
@@ -1,3 +0,3 @@ | ||
import { Base, IBaseOptions } from '../base'; | ||
export declare function shouldDisplaySpinner(options: IBaseOptions): boolean; | ||
import { Base } from '../base'; | ||
export declare function shouldDisplaySpinner(): boolean; | ||
export interface ITask { | ||
@@ -4,0 +4,0 @@ action: string; |
@@ -12,6 +12,7 @@ "use strict"; | ||
const base_1 = require("../base"); | ||
function shouldDisplaySpinner(options) { | ||
const config_1 = require("../config"); | ||
function shouldDisplaySpinner() { | ||
return (!process.env.DEBUG && | ||
!options.mock && | ||
!options.debug && | ||
!config_1.Config.mock && | ||
!config_1.Config.debug && | ||
!!process.stdin.isTTY && | ||
@@ -18,0 +19,0 @@ !!process.stderr.isTTY && |
import { ActionBase } from './base'; | ||
import { IBaseOptions } from '../base'; | ||
export declare class SpinnerAction extends ActionBase { | ||
@@ -8,3 +7,3 @@ spinner: number; | ||
output: string | undefined; | ||
constructor(options?: Partial<IBaseOptions>); | ||
constructor(); | ||
_start(): void; | ||
@@ -11,0 +10,0 @@ _stop(): void; |
@@ -14,5 +14,5 @@ "use strict"; | ||
class SpinnerAction extends base_1.ActionBase { | ||
constructor(options = {}) { | ||
super(options); | ||
this.frames = require('./spinners')[config_1.windows ? 'line' : 'dots2'].frames; | ||
constructor() { | ||
super(); | ||
this.frames = require('./spinners')[config_1.Config.windows ? 'line' : 'dots2'].frames; | ||
this.frameIndex = 0; | ||
@@ -25,3 +25,3 @@ } | ||
this._render(); | ||
let interval = (this.spinner = setInterval(this._render.bind(this), config_1.windows ? 500 : 100, 'spinner')); | ||
let interval = (this.spinner = setInterval(this._render.bind(this), config_1.Config.windows ? 500 : 100, 'spinner')); | ||
interval.unref(); | ||
@@ -28,0 +28,0 @@ } |
import { StreamOutput } from './stream'; | ||
export interface IBaseOptions { | ||
stdout: StreamOutput; | ||
stderr: StreamOutput; | ||
debug: boolean; | ||
mock: boolean; | ||
errlog?: string; | ||
} | ||
import { Config } from './config'; | ||
export declare abstract class Base { | ||
stdout: StreamOutput; | ||
stderr: StreamOutput; | ||
protected options: IBaseOptions; | ||
constructor(options?: Partial<IBaseOptions>); | ||
config: typeof Config; | ||
constructor(); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const stream_1 = require("./stream"); | ||
const config_1 = require("./config"); | ||
class Base { | ||
constructor(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; | ||
this.stderr = this.options.stderr; | ||
constructor() { | ||
this.config = config_1.Config; | ||
this.stdout = new stream_1.StreamOutput('stdout', process.stdout); | ||
this.stderr = new stream_1.StreamOutput('stderr', process.stderr); | ||
} | ||
} | ||
exports.Base = Base; |
@@ -1,1 +0,10 @@ | ||
export declare const windows: boolean; | ||
export declare 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; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.windows = process.platform === 'win32'; | ||
class Config { | ||
static get debug() { | ||
return !!Config._globals.debug; | ||
} | ||
static set debug(debug) { | ||
Config._globals.debug = debug; | ||
} | ||
static get mock() { | ||
return !!Config._globals.mock; | ||
} | ||
static set mock(mock) { | ||
if (mock) { | ||
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.Config = Config; |
@@ -6,3 +6,2 @@ /// <reference types="chalk" /> | ||
import fs = require('fs-extra'); | ||
import { IBaseOptions } from './base'; | ||
import { SpinnerAction } from './action/spinner'; | ||
@@ -24,3 +23,3 @@ import { SimpleAction } from './action/simple'; | ||
readonly supportsColor: any; | ||
readonly shouldDisplaySpinner: (options: IBaseOptions) => boolean; | ||
readonly shouldDisplaySpinner: () => boolean; | ||
readonly SpinnerAction: typeof SpinnerAction; | ||
@@ -27,0 +26,0 @@ readonly SimpleAction: typeof SimpleAction; |
@@ -9,2 +9,3 @@ "use strict"; | ||
const screen_1 = require("./screen"); | ||
const config_1 = require("./config"); | ||
const arrow = process.platform === 'win32' ? ' !' : ' ▸'; | ||
@@ -63,3 +64,3 @@ function bangify(msg, c) { | ||
options.exitCode = 1; | ||
if (options.severity !== 'warn' && this.options.mock && typeof err !== 'string' && options.exitCode !== false) | ||
if (options.severity !== 'warn' && config_1.Config.mock && typeof err !== 'string' && options.exitCode !== false) | ||
throw err; | ||
@@ -71,3 +72,3 @@ try { | ||
this.logError(err); | ||
if (this.options.debug) { | ||
if (config_1.Config.debug) { | ||
this.stderr.write(`${options.severity.toUpperCase()}: ${prefix}`); | ||
@@ -105,6 +106,6 @@ this.stderr.log(err.stack || util.inspect(err)); | ||
exit(code = 0) { | ||
if (this.options.debug) { | ||
if (config_1.Config.debug) { | ||
console.error(`Exiting with code: ${code}`); | ||
} | ||
if (this.options.mock) { | ||
if (config_1.Config.mock) { | ||
throw new exit_error_1.ExitError(code, this.stdout.output, this.stderr.output); | ||
@@ -117,7 +118,7 @@ } | ||
logError(err) { | ||
if (!this.options.errlog) | ||
if (!config_1.Config.errlog) | ||
return; | ||
stream_1.StreamOutput.logToFile(util.inspect(err) + '\n', this.options.errlog); | ||
stream_1.StreamOutput.logToFile(util.inspect(err) + '\n', config_1.Config.errlog); | ||
} | ||
} | ||
exports.Errors = Errors; |
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 interface IOptions { | ||
errlog?: string; | ||
mock?: boolean; | ||
debug?: boolean; | ||
action?: ActionBase; | ||
} | ||
export declare class CLI { | ||
readonly options: IOptions; | ||
export declare class CLI extends Base { | ||
stdout: StreamOutput; | ||
stderr: StreamOutput; | ||
constructor(options?: IOptions); | ||
constructor(); | ||
private _prompt; | ||
@@ -40,5 +34,4 @@ readonly Prompt: Prompt; | ||
done(): void; | ||
private readonly _depOpts; | ||
} | ||
export declare const cli: CLI; | ||
export default cli; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const deps_1 = require("./deps"); | ||
const base_1 = require("./base"); | ||
const config_1 = require("./config"); | ||
const debug = require('debug')('cli-ux'); | ||
class CLI { | ||
constructor(options = {}) { | ||
this.options = options; | ||
const globalOptions = global['cli-ux'] || {}; | ||
if (options.mock === undefined) | ||
options.mock = globalOptions.mock; | ||
if (options.debug === undefined) | ||
options.debug = globalOptions.debug; | ||
this.stdout = new deps_1.deps.StreamOutput(options.mock ? undefined : process.stdout); | ||
this.stderr = new deps_1.deps.StreamOutput(options.mock ? undefined : process.stderr); | ||
if (options.mock) | ||
class CLI extends base_1.Base { | ||
constructor() { | ||
super(); | ||
if (config_1.Config.mock) | ||
deps_1.deps.chalk.enabled = false; | ||
@@ -20,3 +15,3 @@ } | ||
if (!this._prompt) { | ||
this._prompt = new deps_1.deps.Prompt(this._depOpts); | ||
this._prompt = new deps_1.deps.Prompt(); | ||
} | ||
@@ -27,3 +22,3 @@ return this._prompt; | ||
if (!this._errors) { | ||
this._errors = new deps_1.deps.Errors(this._depOpts); | ||
this._errors = new deps_1.deps.Errors(); | ||
} | ||
@@ -34,5 +29,3 @@ return this._errors; | ||
if (!this._action) { | ||
this._action = deps_1.deps.shouldDisplaySpinner(this._depOpts) | ||
? new deps_1.deps.SpinnerAction(this._depOpts) | ||
: new deps_1.deps.SimpleAction(this._depOpts); | ||
this._action = deps_1.deps.shouldDisplaySpinner() ? new deps_1.deps.SpinnerAction() : new deps_1.deps.SimpleAction(); | ||
} | ||
@@ -129,10 +122,2 @@ return this._action; | ||
} | ||
get _depOpts() { | ||
return { | ||
debug: this.options.debug || (this.options.debug === undefined && debug.enabled), | ||
mock: !!this.options.mock, | ||
stderr: this.stderr, | ||
stdout: this.stdout, | ||
}; | ||
} | ||
} | ||
@@ -139,0 +124,0 @@ exports.CLI = CLI; |
/// <reference types="node" /> | ||
export interface IOptions { | ||
displayTimestamps?: boolean; | ||
} | ||
export declare class StreamOutput { | ||
readonly stream: NodeJS.WriteStream | undefined; | ||
readonly options: IOptions; | ||
readonly type: 'stdout' | 'stderr'; | ||
readonly stream: NodeJS.WriteStream; | ||
static logToFile(msg: string, logfile: string): void; | ||
private static startOfLine; | ||
logfile: string | undefined; | ||
output: string; | ||
private displayTimestamps; | ||
private mock; | ||
constructor(stream?: NodeJS.WriteStream | undefined, options?: IOptions); | ||
readonly output: string; | ||
constructor(type: 'stdout' | 'stderr', stream: NodeJS.WriteStream); | ||
write(msg?: string, options?: { | ||
@@ -20,3 +14,4 @@ log?: boolean; | ||
writeLogFile(msg: string, withTimestamp: boolean): void; | ||
readonly logfile: string | undefined; | ||
private timestamp(msg); | ||
} |
@@ -6,7 +6,7 @@ "use strict"; | ||
const deps_1 = require("./deps"); | ||
const config_1 = require("./config"); | ||
class StreamOutput { | ||
constructor(stream, options = {}) { | ||
constructor(type, stream) { | ||
this.type = type; | ||
this.stream = stream; | ||
this.options = options; | ||
this.output = ''; | ||
} | ||
@@ -22,2 +22,5 @@ static logToFile(msg, logfile) { | ||
} | ||
get output() { | ||
return this.type === 'stdout' ? config_1.Config.stdout : config_1.Config.stderr; | ||
} | ||
write(msg, options = {}) { | ||
@@ -29,10 +32,14 @@ msg = msg || ''; | ||
// conditionally show timestamp if configured to display | ||
if (StreamOutput.startOfLine && this.displayTimestamps) { | ||
if (StreamOutput.startOfLine && config_1.Config.displayTimestamps) { | ||
msg = this.timestamp(msg); | ||
} | ||
if (this.stream) { | ||
this.stream.write(msg); | ||
if (config_1.Config.mock) { | ||
let m = deps_1.deps.stripAnsi(msg); | ||
if (this.type === 'stdout') | ||
config_1.Config.stdout += m; | ||
else | ||
config_1.Config.stderr += m; | ||
} | ||
else { | ||
this.output += deps_1.deps.stripAnsi(msg); | ||
this.stream.write(msg); | ||
} | ||
@@ -53,2 +60,6 @@ StreamOutput.startOfLine = msg.endsWith('\n'); | ||
} | ||
get logfile() { | ||
if (this.type === 'stderr') | ||
return config_1.Config.errlog; | ||
} | ||
timestamp(msg) { | ||
@@ -55,0 +66,0 @@ return `[${deps_1.deps.moment().format()}] ${msg}`; |
{ | ||
"name": "cli-ux", | ||
"description": "set of CLI output utilities", | ||
"version": "1.1.13", | ||
"version": "2.0.0", | ||
"author": "Jeff Dickey", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/jdxcode/cli-ux/issues", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49416
1503