Comparing version 1.0.0 to 1.0.1
@@ -47,2 +47,4 @@ "use strict"; | ||
error(err, exitCode = 1) { | ||
if (this.options.mock && typeof err !== 'string' && exitCode !== false) | ||
throw err; | ||
try { | ||
@@ -49,0 +51,0 @@ if (typeof err === 'string') { |
import { ActionBase } from './action/base'; | ||
import { IWarnOptions } from './errors'; | ||
import { IPromptOptions } from './prompt'; | ||
import { StreamOutput } from './stream'; | ||
import { TableOptions } from './table'; | ||
export interface IOptions { | ||
@@ -12,9 +14,7 @@ errlog?: string; | ||
action: ActionBase; | ||
private stdoutStream; | ||
private stderrStream; | ||
stdout: StreamOutput; | ||
stderr: StreamOutput; | ||
private errorsDep; | ||
private promptDep; | ||
constructor(options?: IOptions); | ||
readonly stderr: string; | ||
readonly stdout: string; | ||
prompt(name: string, options?: IPromptOptions): Promise<any>; | ||
@@ -24,3 +24,9 @@ log(data: string, ...args: any[]): void; | ||
error(err: Error | string, exitCode?: number | false): 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; | ||
done(): void; | ||
} | ||
export declare const cli: CLI; |
@@ -13,9 +13,9 @@ "use strict"; | ||
this.options = options; | ||
this.stdoutStream = new stream_1.StreamOutput(this.options.mock ? undefined : process.stdout); | ||
this.stderrStream = new stream_1.StreamOutput(this.options.mock ? undefined : process.stderr); | ||
this.stdout = new stream_1.StreamOutput(this.options.mock ? undefined : process.stdout); | ||
this.stderr = new stream_1.StreamOutput(this.options.mock ? undefined : process.stderr); | ||
const depOpts = { | ||
debug: !!options.debug, | ||
mock: !!options.mock, | ||
stderr: this.stderrStream, | ||
stdout: this.stdoutStream, | ||
stderr: this.stderr, | ||
stdout: this.stdout, | ||
}; | ||
@@ -25,17 +25,5 @@ this.errorsDep = new errors_1.Errors(depOpts); | ||
this.action = base_1.shouldDisplaySpinner(depOpts) ? new spinner_1.SpinnerAction(depOpts) : new simple_1.SimpleAction(depOpts); | ||
if (this.options.mock || !process.stderr.isTTY || !process.stdout.isTTY) | ||
deps_1.deps.chalk.enabled = false; | ||
} | ||
get stderr() { | ||
const output = this.stderrStream.output; | ||
if (!output) { | ||
throw new Error('not mocking stderr'); | ||
} | ||
return output; | ||
} | ||
get stdout() { | ||
const output = this.stdoutStream.output; | ||
if (!output) { | ||
throw new Error('not mocking stdout'); | ||
} | ||
return output; | ||
} | ||
prompt(name, options = {}) { | ||
@@ -48,3 +36,3 @@ return this.action.pauseAsync(() => { | ||
this.action.pause(() => { | ||
return this.stdoutStream.log(data, ...args); | ||
return this.stdout.log(data, ...args); | ||
}); | ||
@@ -62,4 +50,63 @@ } | ||
} | ||
exit(code = 1) { | ||
this.errorsDep.exit(code); | ||
} | ||
table(data, options) { | ||
let table = require('./table'); | ||
return table(this, data, options); | ||
} | ||
styledJSON(obj) { | ||
let json = JSON.stringify(obj, null, 2); | ||
if (deps_1.deps.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.deps.chalk.dim('=== ') + deps_1.deps.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.deps.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); | ||
} | ||
} | ||
} | ||
done() { | ||
this.action.stop(); | ||
} | ||
} | ||
exports.CLI = CLI; | ||
exports.cli = new CLI(); |
{ | ||
"name": "cli-ux", | ||
"description": "set of CLI output utilities", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "Jeff Dickey", | ||
"bugs": "https://github.com/jdxcode/cli-ux/issues", | ||
"dependencies": { | ||
"@types/fs-extra": "^4.0.2", | ||
"ansi-escapes": "^3.0.0", | ||
"ansi-styles": "^3.2.0", | ||
"cardinal": "^1.0.0", | ||
"chalk": "^2.1.0", | ||
"fs-extra": "^4.0.1", | ||
"lodash.ary": "^4.1.1", | ||
"lodash.get": "^4.4.2", | ||
"lodash.identity": "^3.0.0", | ||
"lodash.partial": "^4.2.1", | ||
"lodash.property": "^4.4.2", | ||
"lodash.result": "^4.5.2", | ||
"moment": "^2.18.1", | ||
@@ -22,2 +28,3 @@ "password-prompt": "^1.0.3", | ||
"@types/chalk": "^0.4.31", | ||
"@types/fs-extra": "^4.0.2", | ||
"@types/jest": "^20.0.8", | ||
@@ -24,0 +31,0 @@ "@types/node": "^8.0.28", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43637
29
1332
7
15
18
+ Addedcardinal@^1.0.0
+ Addedlodash.ary@^4.1.1
+ Addedlodash.get@^4.4.2
+ Addedlodash.identity@^3.0.0
+ Addedlodash.partial@^4.2.1
+ Addedlodash.property@^4.4.2
+ Addedlodash.result@^4.5.2
+ Addedansicolors@0.2.1(transitive)
+ Addedcardinal@1.0.0(transitive)
+ Addedesprima@3.0.0(transitive)
+ Addedlodash.ary@4.1.1(transitive)
+ Addedlodash.get@4.4.2(transitive)
+ Addedlodash.identity@3.0.0(transitive)
+ Addedlodash.partial@4.2.1(transitive)
+ Addedlodash.property@4.4.2(transitive)
+ Addedlodash.result@4.5.2(transitive)
+ Addedredeyed@1.0.1(transitive)
- Removed@types/fs-extra@^4.0.2
- Removed@types/fs-extra@4.0.15(transitive)
- Removed@types/node@22.5.5(transitive)
- Removedundici-types@6.19.8(transitive)