@awsless/clui 0.0.1
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/dist/index.cjs +278 -0
- package/dist/index.d.cts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +249 -0
- package/package.json +41 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Cancelled: () => Cancelled,
|
|
34
|
+
ansi: () => ansi_exports,
|
|
35
|
+
color: () => color,
|
|
36
|
+
isCancel: () => import_prompts4.isCancel,
|
|
37
|
+
log: () => logs_exports,
|
|
38
|
+
prompt: () => prompts_exports,
|
|
39
|
+
symbol: () => symbols_exports
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
var import_prompts4 = require("@clack/prompts");
|
|
43
|
+
|
|
44
|
+
// src/symbols.ts
|
|
45
|
+
var symbols_exports = {};
|
|
46
|
+
__export(symbols_exports, {
|
|
47
|
+
error: () => error,
|
|
48
|
+
info: () => info,
|
|
49
|
+
step: () => step,
|
|
50
|
+
success: () => success,
|
|
51
|
+
warning: () => warning
|
|
52
|
+
});
|
|
53
|
+
var step = "\u25C7";
|
|
54
|
+
var error = "\xD7";
|
|
55
|
+
var success = "\u25C6";
|
|
56
|
+
var warning = "\u25B2";
|
|
57
|
+
var info = "\xB7";
|
|
58
|
+
|
|
59
|
+
// src/prompts.ts
|
|
60
|
+
var prompts_exports = {};
|
|
61
|
+
__export(prompts_exports, {
|
|
62
|
+
confirm: () => confirm,
|
|
63
|
+
multiSelect: () => multiSelect,
|
|
64
|
+
password: () => password,
|
|
65
|
+
select: () => select,
|
|
66
|
+
text: () => text
|
|
67
|
+
});
|
|
68
|
+
var import_prompts2 = require("@clack/prompts");
|
|
69
|
+
|
|
70
|
+
// src/error.ts
|
|
71
|
+
var import_prompts = require("@clack/prompts");
|
|
72
|
+
var Cancelled = class extends Error {
|
|
73
|
+
constructor() {
|
|
74
|
+
super("cancelled");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
|
|
78
|
+
const result = await cb();
|
|
79
|
+
if ((0, import_prompts.isCancel)(result) && throwOnCancel) {
|
|
80
|
+
throw new Cancelled();
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/prompts.ts
|
|
86
|
+
var text = async (opts) => {
|
|
87
|
+
return wrapPrompt(() => {
|
|
88
|
+
return (0, import_prompts2.text)(opts);
|
|
89
|
+
}, opts);
|
|
90
|
+
};
|
|
91
|
+
var password = async (opts) => {
|
|
92
|
+
return wrapPrompt(() => {
|
|
93
|
+
return (0, import_prompts2.password)({ mask: "*", ...opts });
|
|
94
|
+
}, opts);
|
|
95
|
+
};
|
|
96
|
+
var confirm = async (opts) => {
|
|
97
|
+
return wrapPrompt(() => {
|
|
98
|
+
return (0, import_prompts2.confirm)(opts);
|
|
99
|
+
}, opts);
|
|
100
|
+
};
|
|
101
|
+
var select = async (opts) => {
|
|
102
|
+
return wrapPrompt(() => {
|
|
103
|
+
return (0, import_prompts2.select)(opts);
|
|
104
|
+
}, opts);
|
|
105
|
+
};
|
|
106
|
+
var multiSelect = async (opts) => {
|
|
107
|
+
return wrapPrompt(() => {
|
|
108
|
+
return (0, import_prompts2.multiselect)(opts);
|
|
109
|
+
}, opts);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/logs.ts
|
|
113
|
+
var logs_exports = {};
|
|
114
|
+
__export(logs_exports, {
|
|
115
|
+
error: () => error2,
|
|
116
|
+
info: () => info2,
|
|
117
|
+
intro: () => intro,
|
|
118
|
+
list: () => list,
|
|
119
|
+
message: () => message,
|
|
120
|
+
note: () => note,
|
|
121
|
+
outro: () => outro,
|
|
122
|
+
step: () => step2,
|
|
123
|
+
success: () => success2,
|
|
124
|
+
table: () => table,
|
|
125
|
+
task: () => task,
|
|
126
|
+
warning: () => warning2
|
|
127
|
+
});
|
|
128
|
+
var import_prompts3 = require("@clack/prompts");
|
|
129
|
+
var import_cli_table3 = __toESM(require("cli-table3"), 1);
|
|
130
|
+
|
|
131
|
+
// src/ansi.ts
|
|
132
|
+
var ansi_exports = {};
|
|
133
|
+
__export(ansi_exports, {
|
|
134
|
+
padString: () => padString,
|
|
135
|
+
stringLength: () => import_string_length.default,
|
|
136
|
+
subString: () => subString,
|
|
137
|
+
wrapString: () => wrapString
|
|
138
|
+
});
|
|
139
|
+
var import_ansi_substring = __toESM(require("ansi-substring"), 1);
|
|
140
|
+
var import_string_length = __toESM(require("string-length"), 1);
|
|
141
|
+
var import_wrap_ansi = __toESM(require("wrap-ansi"), 1);
|
|
142
|
+
var wrapString = (lines, width, options) => {
|
|
143
|
+
return (0, import_wrap_ansi.default)(typeof lines === "string" ? lines : lines.join("\n"), width, options);
|
|
144
|
+
};
|
|
145
|
+
var subString = (message2, width) => {
|
|
146
|
+
const length = (0, import_string_length.default)(message2);
|
|
147
|
+
if (length > width - 1) {
|
|
148
|
+
return (0, import_ansi_substring.default)(message2, 0, width - 1) + "\u2026";
|
|
149
|
+
}
|
|
150
|
+
return (0, import_ansi_substring.default)(message2, 0, width);
|
|
151
|
+
};
|
|
152
|
+
var padString = (texts) => {
|
|
153
|
+
const size = Math.max(...texts.map((text2) => (0, import_string_length.default)(text2)));
|
|
154
|
+
return (text2, padding = 0, fill) => {
|
|
155
|
+
return text2.padEnd(size + padding, fill);
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/colors.ts
|
|
160
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
161
|
+
var color = import_chalk.default;
|
|
162
|
+
|
|
163
|
+
// src/logs.ts
|
|
164
|
+
var endMargin = 1;
|
|
165
|
+
var intro = (title) => {
|
|
166
|
+
(0, import_prompts3.intro)(subString(title, process.stdout.columns - 8 - endMargin));
|
|
167
|
+
};
|
|
168
|
+
var outro = (title) => {
|
|
169
|
+
(0, import_prompts3.outro)(subString(title, process.stdout.columns - 8 - endMargin));
|
|
170
|
+
};
|
|
171
|
+
var note = (title, message2) => {
|
|
172
|
+
const width = process.stdout.columns - 8 - endMargin;
|
|
173
|
+
(0, import_prompts3.note)(
|
|
174
|
+
wrapString(message2, width, {
|
|
175
|
+
hard: true
|
|
176
|
+
}),
|
|
177
|
+
subString(title, width)
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
var logMessage = (symbol, message2) => {
|
|
181
|
+
import_prompts3.log.message(
|
|
182
|
+
wrapString(message2, process.stdout.columns - 8 - endMargin, {
|
|
183
|
+
hard: true,
|
|
184
|
+
trim: false
|
|
185
|
+
}),
|
|
186
|
+
{ symbol }
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
var message = (message2, symbol = color.gray("\u2502")) => logMessage(symbol, message2);
|
|
190
|
+
var error2 = (message2) => logMessage(color.red(error), message2);
|
|
191
|
+
var info2 = (message2) => logMessage(color.blue(info), message2);
|
|
192
|
+
var step2 = (message2) => logMessage(color.green(step), message2);
|
|
193
|
+
var warning2 = (message2) => logMessage(color.yellow(warning), message2);
|
|
194
|
+
var success2 = (message2) => logMessage(color.green(success), message2);
|
|
195
|
+
var list = (title, data) => {
|
|
196
|
+
const padName = padString(Object.keys(data));
|
|
197
|
+
note(
|
|
198
|
+
title,
|
|
199
|
+
Object.entries(data).map(([name, value]) => {
|
|
200
|
+
return color.reset.whiteBright.bold(padName(name + ":", 2)) + value;
|
|
201
|
+
}).join("\n")
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
var task = async (opts) => {
|
|
205
|
+
let last;
|
|
206
|
+
const spin = (0, import_prompts3.spinner)();
|
|
207
|
+
spin.start(opts.initialMessage);
|
|
208
|
+
const stop = (message2, code) => {
|
|
209
|
+
spin.stop(subString(message2 ?? last ?? opts.initialMessage, process.stdout.columns - 8 - endMargin), code);
|
|
210
|
+
};
|
|
211
|
+
try {
|
|
212
|
+
const result = await opts.task((m) => {
|
|
213
|
+
spin.message(subString(m, process.stdout.columns - 8 - endMargin));
|
|
214
|
+
last = m;
|
|
215
|
+
});
|
|
216
|
+
stop(opts.successMessage);
|
|
217
|
+
return result;
|
|
218
|
+
} catch (error3) {
|
|
219
|
+
stop(opts.errorMessage, 2);
|
|
220
|
+
throw error3;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var table = (props) => {
|
|
224
|
+
import_prompts3.log.message();
|
|
225
|
+
const padding = 2;
|
|
226
|
+
const totalPadding = padding * 2;
|
|
227
|
+
const length = Math.max(props.head.length, ...props.body.map((b) => b.length));
|
|
228
|
+
const gap = totalPadding + 1;
|
|
229
|
+
const totalGap = (length - 1) * gap;
|
|
230
|
+
const max = process.stdout.columns - 4 - totalPadding - totalGap - endMargin;
|
|
231
|
+
const column = Math.floor(max / length);
|
|
232
|
+
const leftover = Math.floor(max - column * length);
|
|
233
|
+
const table2 = new import_cli_table3.default({
|
|
234
|
+
head: props.head.map(
|
|
235
|
+
(h, i) => "\n" + color.reset.whiteBright.bold(
|
|
236
|
+
wrapString(h, column + (i + 1 === length ? leftover : 0), {
|
|
237
|
+
hard: true
|
|
238
|
+
})
|
|
239
|
+
)
|
|
240
|
+
),
|
|
241
|
+
style: {
|
|
242
|
+
"padding-left": padding,
|
|
243
|
+
"padding-right": padding
|
|
244
|
+
},
|
|
245
|
+
chars: {
|
|
246
|
+
"bottom-right": "\u256F",
|
|
247
|
+
"top-right": "\u256E",
|
|
248
|
+
"top-left": "\u251C",
|
|
249
|
+
"bottom-left": "\u251C"
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
table2.push(
|
|
253
|
+
...props.body.map((row) => {
|
|
254
|
+
return row.map((value, x) => {
|
|
255
|
+
if (typeof value === "boolean") {
|
|
256
|
+
return value ? color.green("yes") : color.red("no");
|
|
257
|
+
}
|
|
258
|
+
if (typeof value === "number") {
|
|
259
|
+
return color.blue(value);
|
|
260
|
+
}
|
|
261
|
+
return wrapString(value, column + (x + 1 === length ? leftover : 0), {
|
|
262
|
+
hard: true
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
console.log(table2.toString());
|
|
268
|
+
};
|
|
269
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
270
|
+
0 && (module.exports = {
|
|
271
|
+
Cancelled,
|
|
272
|
+
ansi,
|
|
273
|
+
color,
|
|
274
|
+
isCancel,
|
|
275
|
+
log,
|
|
276
|
+
prompt,
|
|
277
|
+
symbol
|
|
278
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
|
|
2
|
+
export { isCancel } from '@clack/prompts';
|
|
3
|
+
import stringLength from 'string-length';
|
|
4
|
+
import { Options } from 'wrap-ansi';
|
|
5
|
+
import * as chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
declare const step$1 = "\u25C7";
|
|
8
|
+
declare const error$1 = "\u00D7";
|
|
9
|
+
declare const success$1 = "\u25C6";
|
|
10
|
+
declare const warning$1 = "\u25B2";
|
|
11
|
+
declare const info$1 = "\u00B7";
|
|
12
|
+
|
|
13
|
+
declare namespace symbols {
|
|
14
|
+
export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class Cancelled extends Error {
|
|
18
|
+
constructor();
|
|
19
|
+
}
|
|
20
|
+
type WrapPromptOptions<T extends boolean | undefined = boolean> = {
|
|
21
|
+
throwOnCancel?: T;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare const text: <T extends boolean | undefined = undefined>(opts: TextOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
|
|
25
|
+
declare const password: <T extends boolean | undefined = undefined>(opts: PasswordOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
|
|
26
|
+
declare const confirm: <T extends boolean | undefined = undefined>(opts: ConfirmOptions & WrapPromptOptions<T>) => Promise<T extends false ? boolean | symbol : boolean>;
|
|
27
|
+
declare const select: <Value, T extends boolean | undefined = undefined>(opts: SelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value : Exclude<Value, symbol>>;
|
|
28
|
+
declare const multiSelect: <Value, T extends boolean | undefined = undefined>(opts: MultiSelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value[] : Value[]>;
|
|
29
|
+
|
|
30
|
+
declare const prompts_confirm: typeof confirm;
|
|
31
|
+
declare const prompts_multiSelect: typeof multiSelect;
|
|
32
|
+
declare const prompts_password: typeof password;
|
|
33
|
+
declare const prompts_select: typeof select;
|
|
34
|
+
declare const prompts_text: typeof text;
|
|
35
|
+
declare namespace prompts {
|
|
36
|
+
export { prompts_confirm as confirm, prompts_multiSelect as multiSelect, prompts_password as password, prompts_select as select, prompts_text as text };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare const intro: (title: string) => void;
|
|
40
|
+
declare const outro: (title: string) => void;
|
|
41
|
+
declare const note: (title: string, message: string) => void;
|
|
42
|
+
declare const message: (message: string, symbol?: string) => void;
|
|
43
|
+
declare const error: (message: string) => void;
|
|
44
|
+
declare const info: (message: string) => void;
|
|
45
|
+
declare const step: (message: string) => void;
|
|
46
|
+
declare const warning: (message: string) => void;
|
|
47
|
+
declare const success: (message: string) => void;
|
|
48
|
+
declare const list: (title: string, data: Record<string, string>) => void;
|
|
49
|
+
type TaskOptions<T> = {
|
|
50
|
+
initialMessage: string;
|
|
51
|
+
errorMessage?: string;
|
|
52
|
+
successMessage?: string;
|
|
53
|
+
task: (updateMessage: (message: string) => void) => Promise<T>;
|
|
54
|
+
};
|
|
55
|
+
declare const task: <T>(opts: TaskOptions<T>) => Promise<T>;
|
|
56
|
+
declare const table: (props: {
|
|
57
|
+
head: string[];
|
|
58
|
+
body: (string | number | boolean)[][];
|
|
59
|
+
}) => void;
|
|
60
|
+
|
|
61
|
+
declare const logs_error: typeof error;
|
|
62
|
+
declare const logs_info: typeof info;
|
|
63
|
+
declare const logs_intro: typeof intro;
|
|
64
|
+
declare const logs_list: typeof list;
|
|
65
|
+
declare const logs_message: typeof message;
|
|
66
|
+
declare const logs_note: typeof note;
|
|
67
|
+
declare const logs_outro: typeof outro;
|
|
68
|
+
declare const logs_step: typeof step;
|
|
69
|
+
declare const logs_success: typeof success;
|
|
70
|
+
declare const logs_table: typeof table;
|
|
71
|
+
declare const logs_task: typeof task;
|
|
72
|
+
declare const logs_warning: typeof warning;
|
|
73
|
+
declare namespace logs {
|
|
74
|
+
export { logs_error as error, logs_info as info, logs_intro as intro, logs_list as list, logs_message as message, logs_note as note, logs_outro as outro, logs_step as step, logs_success as success, logs_table as table, logs_task as task, logs_warning as warning };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare const wrapString: (lines: string | string[], width: number, options?: Options) => string;
|
|
78
|
+
declare const subString: (message: string, width: number) => any;
|
|
79
|
+
declare const padString: (texts: string[]) => (text: string, padding?: number, fill?: string) => string;
|
|
80
|
+
|
|
81
|
+
declare const ansi_padString: typeof padString;
|
|
82
|
+
declare const ansi_stringLength: typeof stringLength;
|
|
83
|
+
declare const ansi_subString: typeof subString;
|
|
84
|
+
declare const ansi_wrapString: typeof wrapString;
|
|
85
|
+
declare namespace ansi {
|
|
86
|
+
export { ansi_padString as padString, ansi_stringLength as stringLength, ansi_subString as subString, ansi_wrapString as wrapString };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare const color: chalk.ChalkInstance;
|
|
90
|
+
|
|
91
|
+
export { Cancelled, ansi, color, logs as log, prompts as prompt, symbols as symbol };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
|
|
2
|
+
export { isCancel } from '@clack/prompts';
|
|
3
|
+
import stringLength from 'string-length';
|
|
4
|
+
import { Options } from 'wrap-ansi';
|
|
5
|
+
import * as chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
declare const step$1 = "\u25C7";
|
|
8
|
+
declare const error$1 = "\u00D7";
|
|
9
|
+
declare const success$1 = "\u25C6";
|
|
10
|
+
declare const warning$1 = "\u25B2";
|
|
11
|
+
declare const info$1 = "\u00B7";
|
|
12
|
+
|
|
13
|
+
declare namespace symbols {
|
|
14
|
+
export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class Cancelled extends Error {
|
|
18
|
+
constructor();
|
|
19
|
+
}
|
|
20
|
+
type WrapPromptOptions<T extends boolean | undefined = boolean> = {
|
|
21
|
+
throwOnCancel?: T;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare const text: <T extends boolean | undefined = undefined>(opts: TextOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
|
|
25
|
+
declare const password: <T extends boolean | undefined = undefined>(opts: PasswordOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
|
|
26
|
+
declare const confirm: <T extends boolean | undefined = undefined>(opts: ConfirmOptions & WrapPromptOptions<T>) => Promise<T extends false ? boolean | symbol : boolean>;
|
|
27
|
+
declare const select: <Value, T extends boolean | undefined = undefined>(opts: SelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value : Exclude<Value, symbol>>;
|
|
28
|
+
declare const multiSelect: <Value, T extends boolean | undefined = undefined>(opts: MultiSelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value[] : Value[]>;
|
|
29
|
+
|
|
30
|
+
declare const prompts_confirm: typeof confirm;
|
|
31
|
+
declare const prompts_multiSelect: typeof multiSelect;
|
|
32
|
+
declare const prompts_password: typeof password;
|
|
33
|
+
declare const prompts_select: typeof select;
|
|
34
|
+
declare const prompts_text: typeof text;
|
|
35
|
+
declare namespace prompts {
|
|
36
|
+
export { prompts_confirm as confirm, prompts_multiSelect as multiSelect, prompts_password as password, prompts_select as select, prompts_text as text };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare const intro: (title: string) => void;
|
|
40
|
+
declare const outro: (title: string) => void;
|
|
41
|
+
declare const note: (title: string, message: string) => void;
|
|
42
|
+
declare const message: (message: string, symbol?: string) => void;
|
|
43
|
+
declare const error: (message: string) => void;
|
|
44
|
+
declare const info: (message: string) => void;
|
|
45
|
+
declare const step: (message: string) => void;
|
|
46
|
+
declare const warning: (message: string) => void;
|
|
47
|
+
declare const success: (message: string) => void;
|
|
48
|
+
declare const list: (title: string, data: Record<string, string>) => void;
|
|
49
|
+
type TaskOptions<T> = {
|
|
50
|
+
initialMessage: string;
|
|
51
|
+
errorMessage?: string;
|
|
52
|
+
successMessage?: string;
|
|
53
|
+
task: (updateMessage: (message: string) => void) => Promise<T>;
|
|
54
|
+
};
|
|
55
|
+
declare const task: <T>(opts: TaskOptions<T>) => Promise<T>;
|
|
56
|
+
declare const table: (props: {
|
|
57
|
+
head: string[];
|
|
58
|
+
body: (string | number | boolean)[][];
|
|
59
|
+
}) => void;
|
|
60
|
+
|
|
61
|
+
declare const logs_error: typeof error;
|
|
62
|
+
declare const logs_info: typeof info;
|
|
63
|
+
declare const logs_intro: typeof intro;
|
|
64
|
+
declare const logs_list: typeof list;
|
|
65
|
+
declare const logs_message: typeof message;
|
|
66
|
+
declare const logs_note: typeof note;
|
|
67
|
+
declare const logs_outro: typeof outro;
|
|
68
|
+
declare const logs_step: typeof step;
|
|
69
|
+
declare const logs_success: typeof success;
|
|
70
|
+
declare const logs_table: typeof table;
|
|
71
|
+
declare const logs_task: typeof task;
|
|
72
|
+
declare const logs_warning: typeof warning;
|
|
73
|
+
declare namespace logs {
|
|
74
|
+
export { logs_error as error, logs_info as info, logs_intro as intro, logs_list as list, logs_message as message, logs_note as note, logs_outro as outro, logs_step as step, logs_success as success, logs_table as table, logs_task as task, logs_warning as warning };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare const wrapString: (lines: string | string[], width: number, options?: Options) => string;
|
|
78
|
+
declare const subString: (message: string, width: number) => any;
|
|
79
|
+
declare const padString: (texts: string[]) => (text: string, padding?: number, fill?: string) => string;
|
|
80
|
+
|
|
81
|
+
declare const ansi_padString: typeof padString;
|
|
82
|
+
declare const ansi_stringLength: typeof stringLength;
|
|
83
|
+
declare const ansi_subString: typeof subString;
|
|
84
|
+
declare const ansi_wrapString: typeof wrapString;
|
|
85
|
+
declare namespace ansi {
|
|
86
|
+
export { ansi_padString as padString, ansi_stringLength as stringLength, ansi_subString as subString, ansi_wrapString as wrapString };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare const color: chalk.ChalkInstance;
|
|
90
|
+
|
|
91
|
+
export { Cancelled, ansi, color, logs as log, prompts as prompt, symbols as symbol };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/index.ts
|
|
8
|
+
import { isCancel as isCancel2 } from "@clack/prompts";
|
|
9
|
+
|
|
10
|
+
// src/symbols.ts
|
|
11
|
+
var symbols_exports = {};
|
|
12
|
+
__export(symbols_exports, {
|
|
13
|
+
error: () => error,
|
|
14
|
+
info: () => info,
|
|
15
|
+
step: () => step,
|
|
16
|
+
success: () => success,
|
|
17
|
+
warning: () => warning
|
|
18
|
+
});
|
|
19
|
+
var step = "\u25C7";
|
|
20
|
+
var error = "\xD7";
|
|
21
|
+
var success = "\u25C6";
|
|
22
|
+
var warning = "\u25B2";
|
|
23
|
+
var info = "\xB7";
|
|
24
|
+
|
|
25
|
+
// src/prompts.ts
|
|
26
|
+
var prompts_exports = {};
|
|
27
|
+
__export(prompts_exports, {
|
|
28
|
+
confirm: () => confirm,
|
|
29
|
+
multiSelect: () => multiSelect,
|
|
30
|
+
password: () => password,
|
|
31
|
+
select: () => select,
|
|
32
|
+
text: () => text
|
|
33
|
+
});
|
|
34
|
+
import {
|
|
35
|
+
confirm as p_confirm,
|
|
36
|
+
multiselect as p_multiselect,
|
|
37
|
+
password as p_password,
|
|
38
|
+
select as p_select,
|
|
39
|
+
text as p_text
|
|
40
|
+
} from "@clack/prompts";
|
|
41
|
+
|
|
42
|
+
// src/error.ts
|
|
43
|
+
import { isCancel } from "@clack/prompts";
|
|
44
|
+
var Cancelled = class extends Error {
|
|
45
|
+
constructor() {
|
|
46
|
+
super("cancelled");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
|
|
50
|
+
const result = await cb();
|
|
51
|
+
if (isCancel(result) && throwOnCancel) {
|
|
52
|
+
throw new Cancelled();
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/prompts.ts
|
|
58
|
+
var text = async (opts) => {
|
|
59
|
+
return wrapPrompt(() => {
|
|
60
|
+
return p_text(opts);
|
|
61
|
+
}, opts);
|
|
62
|
+
};
|
|
63
|
+
var password = async (opts) => {
|
|
64
|
+
return wrapPrompt(() => {
|
|
65
|
+
return p_password({ mask: "*", ...opts });
|
|
66
|
+
}, opts);
|
|
67
|
+
};
|
|
68
|
+
var confirm = async (opts) => {
|
|
69
|
+
return wrapPrompt(() => {
|
|
70
|
+
return p_confirm(opts);
|
|
71
|
+
}, opts);
|
|
72
|
+
};
|
|
73
|
+
var select = async (opts) => {
|
|
74
|
+
return wrapPrompt(() => {
|
|
75
|
+
return p_select(opts);
|
|
76
|
+
}, opts);
|
|
77
|
+
};
|
|
78
|
+
var multiSelect = async (opts) => {
|
|
79
|
+
return wrapPrompt(() => {
|
|
80
|
+
return p_multiselect(opts);
|
|
81
|
+
}, opts);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/logs.ts
|
|
85
|
+
var logs_exports = {};
|
|
86
|
+
__export(logs_exports, {
|
|
87
|
+
error: () => error2,
|
|
88
|
+
info: () => info2,
|
|
89
|
+
intro: () => intro,
|
|
90
|
+
list: () => list,
|
|
91
|
+
message: () => message,
|
|
92
|
+
note: () => note,
|
|
93
|
+
outro: () => outro,
|
|
94
|
+
step: () => step2,
|
|
95
|
+
success: () => success2,
|
|
96
|
+
table: () => table,
|
|
97
|
+
task: () => task,
|
|
98
|
+
warning: () => warning2
|
|
99
|
+
});
|
|
100
|
+
import { log, intro as p_intro, note as p_note, outro as p_outro, spinner } from "@clack/prompts";
|
|
101
|
+
import Table from "cli-table3";
|
|
102
|
+
|
|
103
|
+
// src/ansi.ts
|
|
104
|
+
var ansi_exports = {};
|
|
105
|
+
__export(ansi_exports, {
|
|
106
|
+
padString: () => padString,
|
|
107
|
+
stringLength: () => stringLength,
|
|
108
|
+
subString: () => subString,
|
|
109
|
+
wrapString: () => wrapString
|
|
110
|
+
});
|
|
111
|
+
import ansiSubstring from "ansi-substring";
|
|
112
|
+
import stringLength from "string-length";
|
|
113
|
+
import wrapAnsi from "wrap-ansi";
|
|
114
|
+
var wrapString = (lines, width, options) => {
|
|
115
|
+
return wrapAnsi(typeof lines === "string" ? lines : lines.join("\n"), width, options);
|
|
116
|
+
};
|
|
117
|
+
var subString = (message2, width) => {
|
|
118
|
+
const length = stringLength(message2);
|
|
119
|
+
if (length > width - 1) {
|
|
120
|
+
return ansiSubstring(message2, 0, width - 1) + "\u2026";
|
|
121
|
+
}
|
|
122
|
+
return ansiSubstring(message2, 0, width);
|
|
123
|
+
};
|
|
124
|
+
var padString = (texts) => {
|
|
125
|
+
const size = Math.max(...texts.map((text2) => stringLength(text2)));
|
|
126
|
+
return (text2, padding = 0, fill) => {
|
|
127
|
+
return text2.padEnd(size + padding, fill);
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/colors.ts
|
|
132
|
+
import chalk from "chalk";
|
|
133
|
+
var color = chalk;
|
|
134
|
+
|
|
135
|
+
// src/logs.ts
|
|
136
|
+
var endMargin = 1;
|
|
137
|
+
var intro = (title) => {
|
|
138
|
+
p_intro(subString(title, process.stdout.columns - 8 - endMargin));
|
|
139
|
+
};
|
|
140
|
+
var outro = (title) => {
|
|
141
|
+
p_outro(subString(title, process.stdout.columns - 8 - endMargin));
|
|
142
|
+
};
|
|
143
|
+
var note = (title, message2) => {
|
|
144
|
+
const width = process.stdout.columns - 8 - endMargin;
|
|
145
|
+
p_note(
|
|
146
|
+
wrapString(message2, width, {
|
|
147
|
+
hard: true
|
|
148
|
+
}),
|
|
149
|
+
subString(title, width)
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
var logMessage = (symbol, message2) => {
|
|
153
|
+
log.message(
|
|
154
|
+
wrapString(message2, process.stdout.columns - 8 - endMargin, {
|
|
155
|
+
hard: true,
|
|
156
|
+
trim: false
|
|
157
|
+
}),
|
|
158
|
+
{ symbol }
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
var message = (message2, symbol = color.gray("\u2502")) => logMessage(symbol, message2);
|
|
162
|
+
var error2 = (message2) => logMessage(color.red(error), message2);
|
|
163
|
+
var info2 = (message2) => logMessage(color.blue(info), message2);
|
|
164
|
+
var step2 = (message2) => logMessage(color.green(step), message2);
|
|
165
|
+
var warning2 = (message2) => logMessage(color.yellow(warning), message2);
|
|
166
|
+
var success2 = (message2) => logMessage(color.green(success), message2);
|
|
167
|
+
var list = (title, data) => {
|
|
168
|
+
const padName = padString(Object.keys(data));
|
|
169
|
+
note(
|
|
170
|
+
title,
|
|
171
|
+
Object.entries(data).map(([name, value]) => {
|
|
172
|
+
return color.reset.whiteBright.bold(padName(name + ":", 2)) + value;
|
|
173
|
+
}).join("\n")
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
var task = async (opts) => {
|
|
177
|
+
let last;
|
|
178
|
+
const spin = spinner();
|
|
179
|
+
spin.start(opts.initialMessage);
|
|
180
|
+
const stop = (message2, code) => {
|
|
181
|
+
spin.stop(subString(message2 ?? last ?? opts.initialMessage, process.stdout.columns - 8 - endMargin), code);
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
const result = await opts.task((m) => {
|
|
185
|
+
spin.message(subString(m, process.stdout.columns - 8 - endMargin));
|
|
186
|
+
last = m;
|
|
187
|
+
});
|
|
188
|
+
stop(opts.successMessage);
|
|
189
|
+
return result;
|
|
190
|
+
} catch (error3) {
|
|
191
|
+
stop(opts.errorMessage, 2);
|
|
192
|
+
throw error3;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var table = (props) => {
|
|
196
|
+
log.message();
|
|
197
|
+
const padding = 2;
|
|
198
|
+
const totalPadding = padding * 2;
|
|
199
|
+
const length = Math.max(props.head.length, ...props.body.map((b) => b.length));
|
|
200
|
+
const gap = totalPadding + 1;
|
|
201
|
+
const totalGap = (length - 1) * gap;
|
|
202
|
+
const max = process.stdout.columns - 4 - totalPadding - totalGap - endMargin;
|
|
203
|
+
const column = Math.floor(max / length);
|
|
204
|
+
const leftover = Math.floor(max - column * length);
|
|
205
|
+
const table2 = new Table({
|
|
206
|
+
head: props.head.map(
|
|
207
|
+
(h, i) => "\n" + color.reset.whiteBright.bold(
|
|
208
|
+
wrapString(h, column + (i + 1 === length ? leftover : 0), {
|
|
209
|
+
hard: true
|
|
210
|
+
})
|
|
211
|
+
)
|
|
212
|
+
),
|
|
213
|
+
style: {
|
|
214
|
+
"padding-left": padding,
|
|
215
|
+
"padding-right": padding
|
|
216
|
+
},
|
|
217
|
+
chars: {
|
|
218
|
+
"bottom-right": "\u256F",
|
|
219
|
+
"top-right": "\u256E",
|
|
220
|
+
"top-left": "\u251C",
|
|
221
|
+
"bottom-left": "\u251C"
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
table2.push(
|
|
225
|
+
...props.body.map((row) => {
|
|
226
|
+
return row.map((value, x) => {
|
|
227
|
+
if (typeof value === "boolean") {
|
|
228
|
+
return value ? color.green("yes") : color.red("no");
|
|
229
|
+
}
|
|
230
|
+
if (typeof value === "number") {
|
|
231
|
+
return color.blue(value);
|
|
232
|
+
}
|
|
233
|
+
return wrapString(value, column + (x + 1 === length ? leftover : 0), {
|
|
234
|
+
hard: true
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
})
|
|
238
|
+
);
|
|
239
|
+
console.log(table2.toString());
|
|
240
|
+
};
|
|
241
|
+
export {
|
|
242
|
+
Cancelled,
|
|
243
|
+
ansi_exports as ansi,
|
|
244
|
+
color,
|
|
245
|
+
isCancel2 as isCancel,
|
|
246
|
+
logs_exports as log,
|
|
247
|
+
prompts_exports as prompt,
|
|
248
|
+
symbols_exports as symbol
|
|
249
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@awsless/clui",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/awsless/awsless.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/awsless/awsless/issues"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@clack/prompts": "^0.11.0",
|
|
28
|
+
"ansi-substring": "^1.0.3",
|
|
29
|
+
"chalk": "^5.4.1",
|
|
30
|
+
"cli-table3": "^0.6.5",
|
|
31
|
+
"string-length": "^6.0.0",
|
|
32
|
+
"wrap-ansi": "^9.0.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"prompts": "deno run --unstable-sloppy-imports --allow-env ./demo/prompts.ts",
|
|
36
|
+
"logs": "deno run --unstable-sloppy-imports --allow-env ./demo/logs.ts",
|
|
37
|
+
"test": "pnpm code test",
|
|
38
|
+
"build": "pnpm tsup src/index.ts --format cjs,esm --dts --clean",
|
|
39
|
+
"prepublish": "if pnpm test; then pnpm build; else exit; fi"
|
|
40
|
+
}
|
|
41
|
+
}
|