@anycli/config
Version:
base config object and standard interfaces for anycli components
51 lines (50 loc) • 1.59 kB
JavaScript
;
// tslint:disable no-implicit-dependencies
Object.defineProperty(exports, "__esModule", { value: true });
const screen_1 = require("./screen");
class CLIError extends Error {
constructor(error, options = {}) {
const addExitCode = (error) => {
error['cli-ux'] = error['cli-ux'] || {};
error['cli-ux'].exit = options.exit === undefined ? 1 : options.exit;
return error;
};
if (error instanceof Error)
return addExitCode(error);
super(error);
addExitCode(this);
this.code = options.code;
}
render() {
let cli;
try {
cli = require('cli-ux');
}
catch (_a) { }
if (cli)
return cli.error(this);
let red = ((s) => s);
try {
red = require('chalk').red;
}
catch (_b) { }
let wrap = require('wrap-ansi');
let indent = require('indent-string');
let bang = process.platform === 'win32' ? '×' : '✖';
let output = this.message;
output = wrap(output, screen_1.errtermwidth, { trim: false, hard: true });
output = indent(output, 3);
output = indent(output, 1, red(bang));
output = indent(output, 1);
// tslint:disable-next-line no-console
console.error(output);
}
}
exports.CLIError = CLIError;
class ExitError extends CLIError {
constructor(exitCode = 0) {
super(`EEXIT: ${exitCode}`, { exit: exitCode });
this.code = 'EEXIT';
}
}
exports.ExitError = ExitError;