@oclif/core 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +8 -4
- package/lib/cli-ux/action/base.d.ts +35 -0
- package/lib/cli-ux/action/base.js +166 -0
- package/lib/cli-ux/action/pride-spinner.d.ts +4 -0
- package/lib/cli-ux/action/pride-spinner.js +31 -0
- package/lib/cli-ux/action/simple.d.ts +11 -0
- package/lib/cli-ux/action/simple.js +52 -0
- package/lib/cli-ux/action/spinner.d.ts +16 -0
- package/lib/cli-ux/action/spinner.js +79 -0
- package/lib/cli-ux/action/spinners.d.ts +0 -0
- package/lib/cli-ux/action/spinners.js +373 -0
- package/lib/cli-ux/config.d.ts +20 -0
- package/lib/cli-ux/config.js +45 -0
- package/lib/cli-ux/deps.d.ts +22 -0
- package/lib/cli-ux/deps.js +47 -0
- package/lib/cli-ux/exit.d.ts +8 -0
- package/lib/cli-ux/exit.js +13 -0
- package/lib/cli-ux/index.d.ts +37 -0
- package/lib/cli-ux/index.js +139 -0
- package/lib/cli-ux/list.d.ts +3 -0
- package/lib/cli-ux/list.js +30 -0
- package/lib/cli-ux/open.d.ts +6 -0
- package/lib/cli-ux/open.js +70 -0
- package/lib/cli-ux/prompt.d.ts +29 -0
- package/lib/cli-ux/prompt.js +150 -0
- package/lib/cli-ux/styled/header.d.ts +1 -0
- package/lib/cli-ux/styled/header.js +8 -0
- package/lib/cli-ux/styled/json.d.ts +1 -0
- package/lib/cli-ux/styled/json.js +16 -0
- package/lib/cli-ux/styled/object.d.ts +1 -0
- package/lib/cli-ux/styled/object.js +39 -0
- package/lib/cli-ux/styled/progress.d.ts +1 -0
- package/lib/cli-ux/styled/progress.js +14 -0
- package/lib/cli-ux/styled/table.d.ts +45 -0
- package/lib/cli-ux/styled/table.js +312 -0
- package/lib/cli-ux/styled/tree.d.ts +9 -0
- package/lib/cli-ux/styled/tree.js +40 -0
- package/lib/cli-ux/wait.d.ts +2 -0
- package/lib/cli-ux/wait.js +8 -0
- package/lib/command.js +4 -5
- package/lib/config/config.js +10 -5
- package/lib/config/plugin.js +1 -1
- package/lib/help/util.js +2 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/interfaces/hooks.d.ts +3 -1
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/interfaces/s3-manifest.d.ts +14 -0
- package/lib/interfaces/s3-manifest.js +2 -0
- package/package.json +21 -4
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Table = exports.ExitError = exports.Config = exports.ActionBase = exports.config = exports.ux = void 0;
|
|
4
|
+
const Errors = require("../errors");
|
|
5
|
+
const util = require("util");
|
|
6
|
+
const base_1 = require("./action/base");
|
|
7
|
+
Object.defineProperty(exports, "ActionBase", { enumerable: true, get: function () { return base_1.ActionBase; } });
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
|
|
10
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
11
|
+
const deps_1 = require("./deps");
|
|
12
|
+
const exit_1 = require("./exit");
|
|
13
|
+
Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
|
|
14
|
+
const Table = require("./styled/table");
|
|
15
|
+
exports.Table = Table;
|
|
16
|
+
const hyperlinker = require('hyperlinker');
|
|
17
|
+
function timeout(p, ms) {
|
|
18
|
+
function wait(ms, unref = false) {
|
|
19
|
+
return new Promise(resolve => {
|
|
20
|
+
const t = setTimeout(() => resolve(null), ms);
|
|
21
|
+
if (unref)
|
|
22
|
+
t.unref();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return Promise.race([p, wait(ms, true).then(() => exports.ux.error('timed out'))]);
|
|
26
|
+
}
|
|
27
|
+
async function flush() {
|
|
28
|
+
const p = new Promise(resolve => {
|
|
29
|
+
process.stdout.once('drain', () => resolve(null));
|
|
30
|
+
});
|
|
31
|
+
process.stdout.write('');
|
|
32
|
+
return p;
|
|
33
|
+
}
|
|
34
|
+
exports.ux = {
|
|
35
|
+
config: config_1.config,
|
|
36
|
+
warn: Errors.warn,
|
|
37
|
+
error: Errors.error,
|
|
38
|
+
exit: Errors.exit,
|
|
39
|
+
get prompt() {
|
|
40
|
+
return deps_1.default.prompt.prompt;
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* "press anykey to continue"
|
|
44
|
+
*/
|
|
45
|
+
get anykey() {
|
|
46
|
+
return deps_1.default.prompt.anykey;
|
|
47
|
+
},
|
|
48
|
+
get confirm() {
|
|
49
|
+
return deps_1.default.prompt.confirm;
|
|
50
|
+
},
|
|
51
|
+
get action() {
|
|
52
|
+
return config_1.config.action;
|
|
53
|
+
},
|
|
54
|
+
get prideAction() {
|
|
55
|
+
return config_1.config.prideAction;
|
|
56
|
+
},
|
|
57
|
+
styledObject(obj, keys) {
|
|
58
|
+
exports.ux.info(deps_1.default.styledObject(obj, keys));
|
|
59
|
+
},
|
|
60
|
+
get styledHeader() {
|
|
61
|
+
return deps_1.default.styledHeader;
|
|
62
|
+
},
|
|
63
|
+
get styledJSON() {
|
|
64
|
+
return deps_1.default.styledJSON;
|
|
65
|
+
},
|
|
66
|
+
get table() {
|
|
67
|
+
return deps_1.default.table;
|
|
68
|
+
},
|
|
69
|
+
get tree() {
|
|
70
|
+
return deps_1.default.tree;
|
|
71
|
+
},
|
|
72
|
+
get open() {
|
|
73
|
+
return deps_1.default.open;
|
|
74
|
+
},
|
|
75
|
+
get wait() {
|
|
76
|
+
return deps_1.default.wait;
|
|
77
|
+
},
|
|
78
|
+
get progress() {
|
|
79
|
+
return deps_1.default.progress;
|
|
80
|
+
},
|
|
81
|
+
async done() {
|
|
82
|
+
config_1.config.action.stop();
|
|
83
|
+
// await flushStdout()
|
|
84
|
+
},
|
|
85
|
+
trace(format, ...args) {
|
|
86
|
+
if (this.config.outputLevel === 'trace') {
|
|
87
|
+
process.stdout.write(util.format(format, ...args) + '\n');
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
debug(format, ...args) {
|
|
91
|
+
if (['trace', 'debug'].includes(this.config.outputLevel)) {
|
|
92
|
+
process.stdout.write(util.format(format, ...args) + '\n');
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
info(format, ...args) {
|
|
96
|
+
process.stdout.write(util.format(format, ...args) + '\n');
|
|
97
|
+
},
|
|
98
|
+
log(format, ...args) {
|
|
99
|
+
this.info(format || '', ...args);
|
|
100
|
+
},
|
|
101
|
+
url(text, uri, params = {}) {
|
|
102
|
+
const supports = require('supports-hyperlinks');
|
|
103
|
+
if (supports.stdout) {
|
|
104
|
+
this.log(hyperlinker(text, uri, params));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.log(uri);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
annotation(text, annotation) {
|
|
111
|
+
const supports = require('supports-hyperlinks');
|
|
112
|
+
if (supports.stdout) {
|
|
113
|
+
// \u001b]8;;https://google.com\u0007sometext\u001b]8;;\u0007
|
|
114
|
+
this.log(`\u001B]1337;AddAnnotation=${text.length}|${annotation}\u0007${text}`);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
this.log(text);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
async flush() {
|
|
121
|
+
await timeout(flush(), 10000);
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
const cliuxProcessExitHandler = async () => {
|
|
125
|
+
try {
|
|
126
|
+
await exports.ux.done();
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
// tslint:disable no-console
|
|
130
|
+
console.error(error);
|
|
131
|
+
process.exitCode = 1;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
// to avoid MaxListenersExceededWarning
|
|
135
|
+
// only attach named listener once
|
|
136
|
+
const cliuxListener = process.listeners('exit').find(fn => fn.name === cliuxProcessExitHandler.name);
|
|
137
|
+
if (!cliuxListener) {
|
|
138
|
+
process.once('exit', cliuxProcessExitHandler);
|
|
139
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.renderList = void 0;
|
|
5
|
+
const maxBy_1 = require("lodash/maxBy");
|
|
6
|
+
const deps_1 = require("./deps");
|
|
7
|
+
function linewrap(length, s) {
|
|
8
|
+
const lw = require('@oclif/linewrap');
|
|
9
|
+
return lw(length, deps_1.default.screen.stdtermwidth, {
|
|
10
|
+
skipScheme: 'ansi-color',
|
|
11
|
+
})(s).trim();
|
|
12
|
+
}
|
|
13
|
+
function renderList(items) {
|
|
14
|
+
if (items.length === 0) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
const maxLength = (0, maxBy_1.default)(items, '[0].length')[0].length;
|
|
18
|
+
const lines = items.map(i => {
|
|
19
|
+
let left = i[0];
|
|
20
|
+
let right = i[1];
|
|
21
|
+
if (!right) {
|
|
22
|
+
return left;
|
|
23
|
+
}
|
|
24
|
+
left = left.padEnd(maxLength);
|
|
25
|
+
right = linewrap(maxLength + 2, right);
|
|
26
|
+
return `${left} ${right}`;
|
|
27
|
+
});
|
|
28
|
+
return lines.join('\n');
|
|
29
|
+
}
|
|
30
|
+
exports.renderList = renderList;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// this code is largely taken from opn
|
|
4
|
+
const childProcess = require("child_process");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const isWsl = require('is-wsl');
|
|
7
|
+
function open(target, opts = {}) {
|
|
8
|
+
// opts = {wait: true, ...opts}
|
|
9
|
+
let cmd;
|
|
10
|
+
let appArgs = [];
|
|
11
|
+
let args = [];
|
|
12
|
+
const cpOpts = {};
|
|
13
|
+
if (Array.isArray(opts.app)) {
|
|
14
|
+
appArgs = opts.app.slice(1);
|
|
15
|
+
opts.app = opts.app[0];
|
|
16
|
+
}
|
|
17
|
+
if (process.platform === 'darwin') {
|
|
18
|
+
cmd = 'open';
|
|
19
|
+
// if (opts.wait) {
|
|
20
|
+
// args.push('-W')
|
|
21
|
+
// }
|
|
22
|
+
if (opts.app) {
|
|
23
|
+
args.push('-a', opts.app);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (process.platform === 'win32' || isWsl) {
|
|
27
|
+
cmd = 'cmd' + (isWsl ? '.exe' : '');
|
|
28
|
+
args.push('/c', 'start', '""', '/b');
|
|
29
|
+
target = target.replace(/&/g, '^&');
|
|
30
|
+
// if (opts.wait) {
|
|
31
|
+
// args.push('/wait')
|
|
32
|
+
// }
|
|
33
|
+
if (opts.app) {
|
|
34
|
+
args.push(opts.app);
|
|
35
|
+
}
|
|
36
|
+
if (appArgs.length > 0) {
|
|
37
|
+
args = [...args, ...appArgs];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
cmd = opts.app ? opts.app : 'xdg-open';
|
|
42
|
+
if (appArgs.length > 0) {
|
|
43
|
+
args = [...args, ...appArgs];
|
|
44
|
+
}
|
|
45
|
+
// if (!opts.wait) {
|
|
46
|
+
// `xdg-open` will block the process unless
|
|
47
|
+
// stdio is ignored and it's detached from the parent
|
|
48
|
+
// even if it's unref'd
|
|
49
|
+
cpOpts.stdio = 'ignore';
|
|
50
|
+
cpOpts.detached = true;
|
|
51
|
+
// }
|
|
52
|
+
}
|
|
53
|
+
args.push(target);
|
|
54
|
+
if (process.platform === 'darwin' && appArgs.length > 0) {
|
|
55
|
+
args.push('--args');
|
|
56
|
+
args = [...args, ...appArgs];
|
|
57
|
+
}
|
|
58
|
+
const cp = childProcess.spawn(cmd, args, cpOpts);
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
cp.once('error', reject);
|
|
61
|
+
cp.once('close', code => {
|
|
62
|
+
if (lodash_1.default.isNumber(code) && code > 0) {
|
|
63
|
+
reject(new Error('Exited with code ' + code));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
resolve(cp);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.default = open;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface IPromptOptions {
|
|
2
|
+
prompt?: string;
|
|
3
|
+
type?: 'normal' | 'mask' | 'hide' | 'single';
|
|
4
|
+
timeout?: number;
|
|
5
|
+
/**
|
|
6
|
+
* Requires user input if true, otherwise allows empty input
|
|
7
|
+
*/
|
|
8
|
+
required?: boolean;
|
|
9
|
+
default?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* prompt for input
|
|
13
|
+
* @param name - prompt text
|
|
14
|
+
* @param options - @see IPromptOptions
|
|
15
|
+
* @returns void
|
|
16
|
+
*/
|
|
17
|
+
export declare function prompt(name: string, options?: IPromptOptions): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* confirmation prompt (yes/no)
|
|
20
|
+
* @param message - confirmation text
|
|
21
|
+
* @returns Promise<boolean>
|
|
22
|
+
*/
|
|
23
|
+
export declare function confirm(message: string): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* "press anykey to continue"
|
|
26
|
+
* @param message - optional message to display to user
|
|
27
|
+
* @returns Promise<void>
|
|
28
|
+
*/
|
|
29
|
+
export declare function anykey(message?: string): Promise<void>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.anykey = exports.confirm = exports.prompt = void 0;
|
|
4
|
+
const Errors = require("../errors");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const config_1 = require("./config");
|
|
7
|
+
const deps_1 = require("./deps");
|
|
8
|
+
function normal(options, retries = 100) {
|
|
9
|
+
if (retries < 0)
|
|
10
|
+
throw new Error('no input');
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
let timer;
|
|
13
|
+
if (options.timeout) {
|
|
14
|
+
timer = setTimeout(() => {
|
|
15
|
+
process.stdin.pause();
|
|
16
|
+
reject(new Error('Prompt timeout'));
|
|
17
|
+
}, options.timeout);
|
|
18
|
+
timer.unref();
|
|
19
|
+
}
|
|
20
|
+
process.stdin.setEncoding('utf8');
|
|
21
|
+
process.stderr.write(options.prompt);
|
|
22
|
+
process.stdin.resume();
|
|
23
|
+
process.stdin.once('data', b => {
|
|
24
|
+
if (timer)
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
process.stdin.pause();
|
|
27
|
+
const data = (typeof b === 'string' ? b : b.toString()).trim();
|
|
28
|
+
if (!options.default && options.required && data === '') {
|
|
29
|
+
resolve(normal(options, retries - 1));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
resolve(data || options.default);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function getPrompt(name, type, defaultValue) {
|
|
38
|
+
let prompt = '> ';
|
|
39
|
+
if (defaultValue && type === 'hide') {
|
|
40
|
+
defaultValue = '*'.repeat(defaultValue.length);
|
|
41
|
+
}
|
|
42
|
+
if (name && defaultValue)
|
|
43
|
+
prompt = name + ' ' + chalk.yellow('[' + defaultValue + ']') + ': ';
|
|
44
|
+
else if (name)
|
|
45
|
+
prompt = `${name}: `;
|
|
46
|
+
return prompt;
|
|
47
|
+
}
|
|
48
|
+
async function single(options) {
|
|
49
|
+
var _a;
|
|
50
|
+
const raw = process.stdin.isRaw;
|
|
51
|
+
if (process.stdin.setRawMode)
|
|
52
|
+
process.stdin.setRawMode(true);
|
|
53
|
+
options.required = (_a = options.required) !== null && _a !== void 0 ? _a : false;
|
|
54
|
+
const response = await normal(options);
|
|
55
|
+
if (process.stdin.setRawMode)
|
|
56
|
+
process.stdin.setRawMode(Boolean(raw));
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
function replacePrompt(prompt) {
|
|
60
|
+
process.stderr.write(deps_1.default.ansiEscapes.cursorHide + deps_1.default.ansiEscapes.cursorUp(1) + deps_1.default.ansiEscapes.cursorLeft + prompt +
|
|
61
|
+
deps_1.default.ansiEscapes.cursorDown(1) + deps_1.default.ansiEscapes.cursorLeft + deps_1.default.ansiEscapes.cursorShow);
|
|
62
|
+
}
|
|
63
|
+
function _prompt(name, inputOptions = {}) {
|
|
64
|
+
const prompt = getPrompt(name, inputOptions.type, inputOptions.default);
|
|
65
|
+
const options = {
|
|
66
|
+
isTTY: Boolean(process.env.TERM !== 'dumb' && process.stdin.isTTY),
|
|
67
|
+
name,
|
|
68
|
+
prompt,
|
|
69
|
+
type: 'normal',
|
|
70
|
+
required: true,
|
|
71
|
+
default: '',
|
|
72
|
+
...inputOptions,
|
|
73
|
+
};
|
|
74
|
+
switch (options.type) {
|
|
75
|
+
case 'normal':
|
|
76
|
+
return normal(options);
|
|
77
|
+
case 'single':
|
|
78
|
+
return single(options);
|
|
79
|
+
case 'mask':
|
|
80
|
+
return deps_1.default.passwordPrompt(options.prompt, {
|
|
81
|
+
method: options.type,
|
|
82
|
+
required: options.required,
|
|
83
|
+
default: options.default,
|
|
84
|
+
}).then((value) => {
|
|
85
|
+
replacePrompt(getPrompt(name, 'hide', inputOptions.default));
|
|
86
|
+
return value;
|
|
87
|
+
});
|
|
88
|
+
case 'hide':
|
|
89
|
+
return deps_1.default.passwordPrompt(options.prompt, {
|
|
90
|
+
method: options.type,
|
|
91
|
+
required: options.required,
|
|
92
|
+
default: options.default,
|
|
93
|
+
});
|
|
94
|
+
default:
|
|
95
|
+
throw new Error(`unexpected type ${options.type}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* prompt for input
|
|
100
|
+
* @param name - prompt text
|
|
101
|
+
* @param options - @see IPromptOptions
|
|
102
|
+
* @returns void
|
|
103
|
+
*/
|
|
104
|
+
function prompt(name, options = {}) {
|
|
105
|
+
return config_1.default.action.pauseAsync(() => {
|
|
106
|
+
return _prompt(name, options);
|
|
107
|
+
}, chalk.cyan('?'));
|
|
108
|
+
}
|
|
109
|
+
exports.prompt = prompt;
|
|
110
|
+
/**
|
|
111
|
+
* confirmation prompt (yes/no)
|
|
112
|
+
* @param message - confirmation text
|
|
113
|
+
* @returns Promise<boolean>
|
|
114
|
+
*/
|
|
115
|
+
function confirm(message) {
|
|
116
|
+
return config_1.default.action.pauseAsync(async () => {
|
|
117
|
+
const confirm = async () => {
|
|
118
|
+
const response = (await _prompt(message)).toLowerCase();
|
|
119
|
+
if (['n', 'no'].includes(response))
|
|
120
|
+
return false;
|
|
121
|
+
if (['y', 'yes'].includes(response))
|
|
122
|
+
return true;
|
|
123
|
+
return confirm();
|
|
124
|
+
};
|
|
125
|
+
return confirm();
|
|
126
|
+
}, chalk.cyan('?'));
|
|
127
|
+
}
|
|
128
|
+
exports.confirm = confirm;
|
|
129
|
+
/**
|
|
130
|
+
* "press anykey to continue"
|
|
131
|
+
* @param message - optional message to display to user
|
|
132
|
+
* @returns Promise<void>
|
|
133
|
+
*/
|
|
134
|
+
async function anykey(message) {
|
|
135
|
+
const tty = Boolean(process.stdin.setRawMode);
|
|
136
|
+
if (!message) {
|
|
137
|
+
message = tty ?
|
|
138
|
+
`Press any key to continue or ${chalk.yellow('q')} to exit` :
|
|
139
|
+
`Press enter to continue or ${chalk.yellow('q')} to exit`;
|
|
140
|
+
}
|
|
141
|
+
const char = await prompt(message, { type: 'single', required: false });
|
|
142
|
+
if (tty)
|
|
143
|
+
process.stderr.write('\n');
|
|
144
|
+
if (char === 'q')
|
|
145
|
+
Errors.error('quit');
|
|
146
|
+
if (char === '\u0003')
|
|
147
|
+
Errors.error('ctrl-c');
|
|
148
|
+
return char;
|
|
149
|
+
}
|
|
150
|
+
exports.anykey = anykey;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function styledHeader(header: string): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable restrict-plus-operands
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
function styledHeader(header) {
|
|
6
|
+
process.stdout.write(chalk.dim('=== ') + chalk.bold(header) + '\n');
|
|
7
|
+
}
|
|
8
|
+
exports.default = styledHeader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function styledJSON(obj: any): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable restrict-plus-operands
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const index_1 = require("../../index");
|
|
6
|
+
function styledJSON(obj) {
|
|
7
|
+
const json = JSON.stringify(obj, null, 2);
|
|
8
|
+
if (!chalk.level) {
|
|
9
|
+
index_1.CliUx.ux.info(json);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const cardinal = require('cardinal');
|
|
13
|
+
const theme = require('cardinal/themes/jq');
|
|
14
|
+
index_1.CliUx.ux.info(cardinal.highlight(json, { json: true, theme }));
|
|
15
|
+
}
|
|
16
|
+
exports.default = styledJSON;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function styledObject(obj: any, keys?: string[]): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// tslint:disable
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const util = require("util");
|
|
6
|
+
function styledObject(obj, keys) {
|
|
7
|
+
const output = [];
|
|
8
|
+
const keyLengths = Object.keys(obj).map(key => key.toString().length);
|
|
9
|
+
const maxKeyLength = Math.max(...keyLengths) + 2;
|
|
10
|
+
function pp(obj) {
|
|
11
|
+
if (typeof obj === 'string' || typeof obj === 'number')
|
|
12
|
+
return obj;
|
|
13
|
+
if (typeof obj === 'object') {
|
|
14
|
+
return Object.keys(obj)
|
|
15
|
+
.map(k => k + ': ' + util.inspect(obj[k]))
|
|
16
|
+
.join(', ');
|
|
17
|
+
}
|
|
18
|
+
return util.inspect(obj);
|
|
19
|
+
}
|
|
20
|
+
const logKeyValue = (key, value) => {
|
|
21
|
+
return `${chalk.blue(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + pp(value);
|
|
22
|
+
};
|
|
23
|
+
for (const key of keys || Object.keys(obj).sort()) {
|
|
24
|
+
const value = obj[key];
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
if (value.length > 0) {
|
|
27
|
+
output.push(logKeyValue(key, value[0]));
|
|
28
|
+
for (const e of value.slice(1)) {
|
|
29
|
+
output.push(' '.repeat(maxKeyLength) + pp(e));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (value !== null && value !== undefined) {
|
|
34
|
+
output.push(logKeyValue(key, value));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return output.join('\n');
|
|
38
|
+
}
|
|
39
|
+
exports.default = styledObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function progress(options?: any): any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// 3pp
|
|
4
|
+
const cliProgress = require("cli-progress");
|
|
5
|
+
function progress(options) {
|
|
6
|
+
// if no options passed, create empty options
|
|
7
|
+
if (!options) {
|
|
8
|
+
options = {};
|
|
9
|
+
}
|
|
10
|
+
// set noTTYOutput for options
|
|
11
|
+
options.noTTYOutput = Boolean(process.env.TERM === 'dumb' || !process.stdin.isTTY);
|
|
12
|
+
return new cliProgress.SingleBar(options);
|
|
13
|
+
}
|
|
14
|
+
exports.default = progress;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as Interfaces from '../../interfaces';
|
|
2
|
+
export declare function table<T extends Record<string, unknown>>(data: T[], columns: table.Columns<T>, options?: table.Options): void;
|
|
3
|
+
export declare namespace table {
|
|
4
|
+
export const Flags: {
|
|
5
|
+
columns: Interfaces.OptionFlag<string | undefined>;
|
|
6
|
+
sort: Interfaces.OptionFlag<string | undefined>;
|
|
7
|
+
filter: Interfaces.OptionFlag<string | undefined>;
|
|
8
|
+
csv: Interfaces.Flag<boolean>;
|
|
9
|
+
output: Interfaces.OptionFlag<string | undefined>;
|
|
10
|
+
extended: Interfaces.Flag<boolean>;
|
|
11
|
+
'no-truncate': Interfaces.Flag<boolean>;
|
|
12
|
+
'no-header': Interfaces.Flag<boolean>;
|
|
13
|
+
};
|
|
14
|
+
type IFlags = typeof Flags;
|
|
15
|
+
type ExcludeFlags<T, Z> = Pick<T, Exclude<keyof T, Z>>;
|
|
16
|
+
type IncludeFlags<T, K extends keyof T> = Pick<T, K>;
|
|
17
|
+
export function flags(): IFlags;
|
|
18
|
+
export function flags<Z extends keyof IFlags = keyof IFlags>(opts: {
|
|
19
|
+
except: Z | Z[];
|
|
20
|
+
}): ExcludeFlags<IFlags, Z>;
|
|
21
|
+
export function flags<K extends keyof IFlags = keyof IFlags>(opts: {
|
|
22
|
+
only: K | K[];
|
|
23
|
+
}): IncludeFlags<IFlags, K>;
|
|
24
|
+
export interface Column<T extends Record<string, unknown>> {
|
|
25
|
+
header: string;
|
|
26
|
+
extended: boolean;
|
|
27
|
+
minWidth: number;
|
|
28
|
+
get(row: T): any;
|
|
29
|
+
}
|
|
30
|
+
export type Columns<T extends Record<string, unknown>> = {
|
|
31
|
+
[key: string]: Partial<Column<T>>;
|
|
32
|
+
};
|
|
33
|
+
export interface Options {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
sort?: string;
|
|
36
|
+
filter?: string;
|
|
37
|
+
columns?: string;
|
|
38
|
+
extended?: boolean;
|
|
39
|
+
'no-truncate'?: boolean;
|
|
40
|
+
output?: string;
|
|
41
|
+
'no-header'?: boolean;
|
|
42
|
+
printLine?(s: any): any;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
}
|