convoker 0.3.3 → 0.4.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.
Files changed (54) hide show
  1. package/LICENSE +1 -1
  2. package/dist/chunk-z5eko27R.mjs +13 -0
  3. package/dist/color/index.d.mts +2 -0
  4. package/dist/color/index.mjs +3 -0
  5. package/dist/color-DiZvJ0Fc.mjs +201 -0
  6. package/dist/color-DiZvJ0Fc.mjs.map +1 -0
  7. package/dist/command/index.d.mts +5 -0
  8. package/dist/command/index.mjs +8 -0
  9. package/dist/command-8P8qXJ2o.mjs +486 -0
  10. package/dist/command-8P8qXJ2o.mjs.map +1 -0
  11. package/dist/index-BYLskLxk.d.mts +200 -0
  12. package/dist/index-BtbthYjp.d.mts +168 -0
  13. package/dist/index-ClhbwSD8.d.mts +202 -0
  14. package/dist/index-Cnx4H4D-.d.mts +316 -0
  15. package/dist/index.d.mts +37 -0
  16. package/dist/index.mjs +92 -0
  17. package/dist/index.mjs.map +1 -0
  18. package/dist/input/index.d.mts +3 -0
  19. package/dist/input/index.mjs +4 -0
  20. package/dist/input-XUsy1LCQ.mjs +176 -0
  21. package/dist/input-XUsy1LCQ.mjs.map +1 -0
  22. package/dist/prompt/index.d.mts +5 -0
  23. package/dist/prompt/index.mjs +6 -0
  24. package/dist/prompt/raw.d.mts +2 -0
  25. package/dist/prompt/raw.mjs +3 -0
  26. package/dist/prompt-a5Ix_Hyc.mjs +220 -0
  27. package/dist/prompt-a5Ix_Hyc.mjs.map +1 -0
  28. package/dist/raw-DEtZFeMv.mjs +88 -0
  29. package/dist/raw-DEtZFeMv.mjs.map +1 -0
  30. package/dist/raw-cqTp2vds.d.mts +38 -0
  31. package/dist/standard-schema-DTuaYJjO.mjs +32 -0
  32. package/dist/standard-schema-DTuaYJjO.mjs.map +1 -0
  33. package/dist/standard-schema-DXS-QnwX.d.mts +59 -0
  34. package/package.json +24 -26
  35. package/dist/color.d.ts +0 -153
  36. package/dist/color.js +0 -143
  37. package/dist/command.d.ts +0 -218
  38. package/dist/command.js +0 -531
  39. package/dist/error.d.ts +0 -107
  40. package/dist/error.js +0 -100
  41. package/dist/index.d.ts +0 -6
  42. package/dist/index.js +0 -6
  43. package/dist/input.d.ts +0 -182
  44. package/dist/input.js +0 -185
  45. package/dist/log.d.ts +0 -61
  46. package/dist/log.js +0 -216
  47. package/dist/prompt/index.d.ts +0 -193
  48. package/dist/prompt/index.js +0 -273
  49. package/dist/prompt/raw.d.ts +0 -32
  50. package/dist/prompt/raw.js +0 -105
  51. package/dist/standard-schema.d.ts +0 -62
  52. package/dist/standard-schema.js +0 -16
  53. package/dist/utils.d.ts +0 -30
  54. package/dist/utils.js +0 -56
@@ -0,0 +1,220 @@
1
+ import { t as __export } from "./chunk-z5eko27R.mjs";
2
+ import { t as DEFAULT_THEME } from "./color-DiZvJ0Fc.mjs";
3
+ import { n as InputValidationError, t as validate } from "./standard-schema-DTuaYJjO.mjs";
4
+ import { a as readKey, i as raw_exports, o as readLine, r as cursorUp, t as clearLines } from "./raw-DEtZFeMv.mjs";
5
+ import childProcess from "node:child_process";
6
+ import fs from "node:fs/promises";
7
+ import path from "node:path";
8
+ import os from "node:os";
9
+
10
+ //#region src/prompt/index.ts
11
+ var prompt_exports = /* @__PURE__ */ __export({
12
+ confirm: () => confirm,
13
+ editor: () => editor,
14
+ multiselect: () => multiselect,
15
+ password: () => password,
16
+ raw: () => raw_exports,
17
+ search: () => search,
18
+ select: () => select,
19
+ setTheme: () => setTheme,
20
+ text: () => text
21
+ });
22
+ let theme = DEFAULT_THEME;
23
+ /**
24
+ * Sets the theme of the prompts.
25
+ * @param t The new theme.
26
+ */
27
+ function setTheme(t) {
28
+ theme = t;
29
+ }
30
+ /**
31
+ * Prompts the user for text input.
32
+ * @param opts Options for text input.
33
+ * @returns The text the user typed in, or the default.
34
+ */
35
+ async function text(opts) {
36
+ const message = (opts.theme ?? theme).primary(opts.message) + " ";
37
+ const answer = await readLine(message, opts.default);
38
+ if (opts.minLength && answer.length < opts.minLength) throw new InputValidationError([`Must be at least ${opts.minLength} characters`]);
39
+ if (opts.maxLength && answer.length > opts.maxLength) throw new InputValidationError([`Must be at most ${opts.maxLength} characters`]);
40
+ if (typeof opts.validate === "function") {
41
+ if (!opts.validate(answer)) throw new InputValidationError(["Validation function returned a falsy value"]);
42
+ } else if (opts.validate) await validate(opts.validate, answer);
43
+ return answer;
44
+ }
45
+ /**
46
+ * Prompts the user for a password.
47
+ * @param opts Options for password input.
48
+ * @returns The password.
49
+ */
50
+ async function password(opts) {
51
+ const th = opts.theme ?? theme;
52
+ const first = await readLine(th.primary(opts.message) + " ", void 0, {
53
+ masked: true,
54
+ maskChar: opts.mask ?? "*"
55
+ });
56
+ if (opts.confirm) {
57
+ if (first !== await readLine(th.secondary("Confirm password: "), void 0, {
58
+ masked: true,
59
+ maskChar: opts.mask ?? "*"
60
+ })) throw new Error(th.error("Passwords do not match"));
61
+ }
62
+ return first;
63
+ }
64
+ /**
65
+ * Prompts the user to select a single option.
66
+ * @param opts Options for select input.
67
+ * @returns The selected option's value.
68
+ */
69
+ async function select(opts) {
70
+ const th = opts.theme ?? theme;
71
+ const options = opts.options;
72
+ let index = opts.initialIndex ?? 0;
73
+ const render = () => {
74
+ clearLines(options.length + 1);
75
+ console.log(th.primary(opts.message));
76
+ for (let i = 0; i < options.length; i++) {
77
+ const o = options[i];
78
+ const prefix = i === index ? th.accent?.("> ") ?? "> " : " ";
79
+ const label = o.disabled ? th.secondary(o.label) : th.foreground?.(o.label) ?? o.label;
80
+ console.log(prefix + label);
81
+ }
82
+ };
83
+ console.log(th.primary(opts.message));
84
+ options.forEach((o, i) => console.log(`${i === index ? "> " : " "}${o.label}`));
85
+ while (true) {
86
+ const key = await readKey();
87
+ if (key === "up" && index > 0) index--;
88
+ else if (key === "down" && index < options.length - 1) index++;
89
+ else if (key === "enter") {
90
+ const choice = options[index];
91
+ if (choice.disabled) continue;
92
+ clearLines(options.length + 1);
93
+ console.log(th.success(`${th.symbols?.success ?? "✔"} ${choice.label}`));
94
+ return choice.value;
95
+ }
96
+ render();
97
+ }
98
+ }
99
+ /**
100
+ * Prompts the user to select multiple options.
101
+ * @param opts Options for select input.
102
+ * @returns The selected options.
103
+ */
104
+ async function multiselect(opts) {
105
+ const th = opts.theme ?? theme;
106
+ const options = opts.options;
107
+ let index = opts.initialIndex ?? 0;
108
+ const selected = /* @__PURE__ */ new Set();
109
+ const render = () => {
110
+ clearLines();
111
+ console.log(th.primary(opts.message));
112
+ options.forEach((opt, i) => {
113
+ const prefix = i === index ? th.accent?.("> ") ?? "> " : " ";
114
+ const mark = selected.has(i) ? th.success("[x]") : "[ ]";
115
+ console.log(prefix + mark + " " + opt.label);
116
+ });
117
+ };
118
+ render();
119
+ while (true) {
120
+ const key = await readKey();
121
+ if (key === "up" && index > 0) index--;
122
+ else if (key === "down" && index < options.length - 1) index++;
123
+ else if (key === "space") if (selected.has(index)) selected.delete(index);
124
+ else selected.add(index);
125
+ else if (key === "enter") {
126
+ const chosen = Array.from(selected).map((i) => options[i].value);
127
+ clearLines(options.length + 1);
128
+ console.log(th.success(`${opts.message} ${chosen.length} selected`));
129
+ return chosen;
130
+ }
131
+ cursorUp(options.length);
132
+ render();
133
+ }
134
+ }
135
+ /**
136
+ * Prompts the user to search through a list of options.
137
+ * @param opts Options for search input.
138
+ * @returns The selected option.
139
+ */
140
+ async function search(opts) {
141
+ const th = opts.theme ?? theme;
142
+ let query = "";
143
+ const filter = opts.filter ?? ((q, o) => o.label.toLowerCase().includes(q.toLowerCase()));
144
+ while (true) {
145
+ clearLines();
146
+ console.log(th.primary(opts.message));
147
+ const matches = opts.options.filter((o) => filter(query, o));
148
+ matches.forEach((o) => console.log(" " + (th.foreground?.(o.label) ?? o.label)));
149
+ if (matches.length === 1) return matches[0].value;
150
+ const input = await readLine(th.secondary(`Search: ${query}`));
151
+ if (!input) continue;
152
+ query = input;
153
+ }
154
+ }
155
+ /**
156
+ * Prompts the user to confirm an action.
157
+ * @param opts Options for confirm input.
158
+ * @returns If the user picked Yes.
159
+ */
160
+ async function confirm(opts) {
161
+ const th = opts.theme ?? theme;
162
+ const yes = opts.yesLabel ?? "y";
163
+ const no = opts.noLabel ?? "n";
164
+ const def = opts.default ? yes : no;
165
+ const res = await readLine(`${th.primary(opts.message)} ${th.secondary(`[${yes}/${no}] (default: ${def})`)} `);
166
+ if (!res) return !!opts.default;
167
+ return /^y/i.test(res.trim());
168
+ }
169
+ /**
170
+ * Opens the system editor, or asks for input in the terminal as fallback.
171
+ * @param opts Options for opening the system editor.
172
+ * @returns The result of the system editor.
173
+ */
174
+ async function editor(opts) {
175
+ const th = opts.theme ?? {
176
+ primary: (s) => s,
177
+ secondary: (s) => s
178
+ };
179
+ console.log(th.primary(opts.message ?? "Please enter text:"));
180
+ console.log(th.secondary("Press Ctrl+D (or save & close editor) when done."));
181
+ try {
182
+ const result = await openSystemEditor(opts.initial ?? "");
183
+ if (opts.required && !result.trim()) throw new Error("Input required.");
184
+ return result;
185
+ } catch {
186
+ const value = await readLine("", opts.initial, { multiline: true });
187
+ if (opts.required && !value.trim()) throw new Error("Input required.");
188
+ return value;
189
+ }
190
+ }
191
+ /**
192
+ * Opens the system editor on a temporary file.
193
+ * @param initial Initial contents of the file.
194
+ * @returns The contents of the file after saving.
195
+ */
196
+ async function openSystemEditor(initial) {
197
+ const tmpFile = `edit-${Date.now()}.txt`;
198
+ const filePath = path.join(os.tmpdir(), tmpFile);
199
+ await fs.writeFile(filePath, initial ?? "", "utf8");
200
+ const editor$1 = process.env.EDITOR || process.env.VISUAL || (process.platform === "win32" ? "notepad" : "vi");
201
+ return new Promise((resolve, reject) => {
202
+ childProcess.spawn(editor$1, [filePath], { stdio: "inherit" }).on("exit", async (code) => {
203
+ if (code !== 0) {
204
+ reject(/* @__PURE__ */ new Error(`${editor$1} exited with code ${code}`));
205
+ return;
206
+ }
207
+ try {
208
+ const data = await fs.readFile(filePath, "utf8");
209
+ await fs.unlink(filePath).catch(() => {});
210
+ resolve(data);
211
+ } catch (err) {
212
+ reject(err);
213
+ }
214
+ });
215
+ });
216
+ }
217
+
218
+ //#endregion
219
+ export { prompt_exports as a, setTheme as c, password as i, text as l, editor as n, search as o, multiselect as r, select as s, confirm as t };
220
+ //# sourceMappingURL=prompt-a5Ix_Hyc.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-a5Ix_Hyc.mjs","names":["theme: Theme","raw.readLine","raw.readKey","editor"],"sources":["../src/prompt/index.ts"],"sourcesContent":["import childProcess from \"node:child_process\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport os from \"node:os\";\n\nimport { DEFAULT_THEME, type Theme } from \"@/color\";\nimport { validate, type StandardSchemaV1 } from \"@/input/standard-schema\";\nimport { InputValidationError } from \"@/input/error\";\nimport * as raw from \"./raw\";\n\nlet theme: Theme = DEFAULT_THEME;\n\n/**\n * Sets the theme of the prompts.\n * @param t The new theme.\n */\nexport function setTheme(t: Theme) {\n theme = t;\n}\n\n/**\n * Base options for prompts.\n */\nexport interface BaseOpts<T> {\n /**\n * The message of the prompt.\n */\n message: string;\n /**\n * An `AbortSignal` to cancel the prompt.\n */\n signal?: AbortSignal;\n /**\n * The default value.\n */\n default?: T;\n /**\n * The theme of the prompt.\n */\n theme?: Theme;\n /**\n * A validator function, or a Standard Schema validator.\n */\n validate?: StandardSchemaV1<any, T> | ((value: T) => boolean | T);\n}\n\n// -- text -- //\n\n/**\n * Options for text input.\n */\nexport interface TextOpts extends BaseOpts<string> {\n /**\n * A placeholder, displayed when the user hasn't typed anything yet.\n */\n placeholder?: string;\n /**\n * Minimum length of the input.\n */\n minLength?: number;\n /**\n * Maximum length of the input.\n */\n maxLength?: number;\n}\n\n/**\n * Prompts the user for text input.\n * @param opts Options for text input.\n * @returns The text the user typed in, or the default.\n */\nexport async function text(opts: TextOpts): Promise<string> {\n const th = opts.theme ?? theme;\n const message = th.primary(opts.message) + \" \";\n const answer = await raw.readLine(message, opts.default);\n\n if (opts.minLength && answer.length < opts.minLength)\n throw new InputValidationError([\n `Must be at least ${opts.minLength} characters`,\n ]);\n if (opts.maxLength && answer.length > opts.maxLength)\n throw new InputValidationError([\n `Must be at most ${opts.maxLength} characters`,\n ]);\n\n if (typeof opts.validate === \"function\") {\n if (!opts.validate(answer))\n throw new InputValidationError([\n \"Validation function returned a falsy value\",\n ]);\n } else if (opts.validate) {\n await validate(opts.validate, answer);\n }\n return answer;\n}\n\n// -- password -- //\n\n/**\n * Options for password input.\n */\nexport interface PasswordOpts extends TextOpts {\n /**\n * The mask for the password input.\n */\n mask?: string;\n /**\n * If the user should be asked to confirm the password, by typing it again.\n */\n confirm?: boolean;\n}\n\n/**\n * Prompts the user for a password.\n * @param opts Options for password input.\n * @returns The password.\n */\nexport async function password(opts: PasswordOpts): Promise<string> {\n const th = opts.theme ?? theme;\n const first = await raw.readLine(th.primary(opts.message) + \" \", undefined, {\n masked: true,\n maskChar: opts.mask ?? \"*\",\n });\n if (opts.confirm) {\n const second = await raw.readLine(\n th.secondary(\"Confirm password: \"),\n undefined,\n {\n masked: true,\n maskChar: opts.mask ?? \"*\",\n },\n );\n if (first !== second) throw new Error(th.error(\"Passwords do not match\"));\n }\n return first;\n}\n\n// -- select -- //\n\n/**\n * An option for select input.\n */\nexport interface SelectOption<T> {\n /**\n * The label (what gets displayed) of the select option.\n */\n label: string;\n /**\n * The value (what gets returned) of the select option.\n */\n value: T;\n /**\n * A description of the option.\n */\n hint?: string;\n /**\n * If this option is disabled.\n */\n disabled?: boolean;\n}\n\n/**\n * Options for select input.\n */\nexport interface SelectOpts<T> extends BaseOpts<T> {\n /**\n * Every option the user can pick from.\n */\n options: SelectOption<T>[];\n /**\n * The initial option selected.\n */\n initialIndex?: number;\n}\n\n/**\n * Prompts the user to select a single option.\n * @param opts Options for select input.\n * @returns The selected option's value.\n */\nexport async function select<T>(opts: SelectOpts<T>): Promise<T> {\n const th = opts.theme ?? theme;\n const options = opts.options;\n let index = opts.initialIndex ?? 0;\n\n const render = () => {\n raw.clearLines(options.length + 1);\n console.log(th.primary(opts.message));\n for (let i = 0; i < options.length; i++) {\n const o = options[i];\n const prefix = i === index ? (th.accent?.(\"> \") ?? \"> \") : \" \";\n const label = o.disabled\n ? th.secondary(o.label)\n : (th.foreground?.(o.label) ?? o.label);\n console.log(prefix + label);\n }\n };\n\n console.log(th.primary(opts.message));\n options.forEach((o, i) =>\n console.log(`${i === index ? \"> \" : \" \"}${o.label}`),\n );\n\n while (true) {\n const key = await raw.readKey();\n if (key === \"up\" && index > 0) index--;\n else if (key === \"down\" && index < options.length - 1) index++;\n else if (key === \"enter\") {\n const choice = options[index];\n if (choice.disabled) continue;\n raw.clearLines(options.length + 1);\n console.log(th.success(`${th.symbols?.success ?? \"✔\"} ${choice.label}`));\n return choice.value;\n }\n render();\n }\n}\n\n/**\n * Prompts the user to select multiple options.\n * @param opts Options for select input.\n * @returns The selected options.\n */\nexport async function multiselect<T>(opts: SelectOpts<T>): Promise<T[]> {\n const th = opts.theme ?? theme;\n const options = opts.options;\n let index = opts.initialIndex ?? 0;\n const selected = new Set<number>();\n\n const render = () => {\n raw.clearLines();\n console.log(th.primary(opts.message));\n options.forEach((opt, i) => {\n const prefix = i === index ? (th.accent?.(\"> \") ?? \"> \") : \" \";\n const mark = selected.has(i) ? th.success(\"[x]\") : \"[ ]\";\n console.log(prefix + mark + \" \" + opt.label);\n });\n };\n\n render();\n while (true) {\n const key = await raw.readKey();\n if (key === \"up\" && index > 0) index--;\n else if (key === \"down\" && index < options.length - 1) index++;\n else if (key === \"space\") {\n if (selected.has(index)) selected.delete(index);\n else selected.add(index);\n } else if (key === \"enter\") {\n const chosen = Array.from(selected).map((i) => options[i].value);\n raw.clearLines(options.length + 1);\n console.log(th.success(`${opts.message} ${chosen.length} selected`));\n return chosen;\n }\n raw.cursorUp(options.length);\n render();\n }\n}\n\n// -- search -- //\n\n/**\n * Options for search input.\n */\nexport interface SearchOpts<T> extends BaseOpts<T> {\n /**\n * Every option the user can search through.\n */\n options: SelectOption<T>[];\n /**\n * Placeholder for the search input.\n */\n placeholder?: string;\n /**\n * Minimum length for a query string.\n */\n minQueryLength?: number;\n /**\n * Filters a single option.\n * @param query The search query.\n * @param option The option to filter.\n */\n filter?(query: string, option: SelectOption<T>): boolean;\n}\n\n/**\n * Prompts the user to search through a list of options.\n * @param opts Options for search input.\n * @returns The selected option.\n */\nexport async function search<T>(opts: SearchOpts<T>): Promise<T> {\n const th = opts.theme ?? theme;\n let query = \"\";\n const filter =\n opts.filter ?? ((q, o) => o.label.toLowerCase().includes(q.toLowerCase()));\n while (true) {\n raw.clearLines();\n console.log(th.primary(opts.message));\n\n const matches = opts.options.filter((o) => filter(query, o));\n matches.forEach((o) =>\n console.log(\" \" + (th.foreground?.(o.label) ?? o.label)),\n );\n\n if (matches.length === 1) {\n return matches[0].value;\n }\n\n const input = await raw.readLine(th.secondary(`Search: ${query}`));\n if (!input) continue;\n\n query = input;\n }\n}\n\n// -- confirm -- //\n\n/**\n * Options for confirm input.\n */\nexport interface ConfirmOpts extends BaseOpts<boolean> {\n /**\n * What gets displayed for the Yes option.\n */\n yesLabel?: string;\n /**\n * What gets displayed for the No option.\n */\n noLabel?: string;\n}\n\n/**\n * Prompts the user to confirm an action.\n * @param opts Options for confirm input.\n * @returns If the user picked Yes.\n */\nexport async function confirm(opts: ConfirmOpts): Promise<boolean> {\n const th = opts.theme ?? theme;\n const yes = opts.yesLabel ?? \"y\";\n const no = opts.noLabel ?? \"n\";\n const def = opts.default ? yes : no;\n const res = await raw.readLine(\n `${th.primary(opts.message)} ${th.secondary(`[${yes}/${no}] (default: ${def})`)} `,\n );\n if (!res) return !!opts.default;\n return /^y/i.test(res.trim());\n}\n\n// -- editor -- //\n\n/**\n * Options for opening the system editor.\n */\nexport interface EditorOpts extends BaseOpts<string> {\n /**\n * The initial value.\n */\n initial?: string;\n /**\n * The language of the value.\n */\n language?: string;\n /**\n * If the input is required for continuing or not.\n */\n required?: boolean;\n}\n\n/**\n * Opens the system editor, or asks for input in the terminal as fallback.\n * @param opts Options for opening the system editor.\n * @returns The result of the system editor.\n */\nexport async function editor(opts: EditorOpts): Promise<string> {\n const th = opts.theme ?? {\n primary: (s: string) => s,\n secondary: (s: string) => s,\n };\n\n console.log(th.primary(opts.message ?? \"Please enter text:\"));\n console.log(th.secondary(\"Press Ctrl+D (or save & close editor) when done.\"));\n\n try {\n const result = await openSystemEditor(opts.initial ?? \"\");\n if (opts.required && !result.trim()) throw new Error(\"Input required.\");\n return result;\n } catch {\n // fallback: cross-runtime multiline input\n const value = await raw.readLine(\"\", opts.initial, { multiline: true });\n if (opts.required && !value.trim()) throw new Error(\"Input required.\");\n return value;\n }\n}\n\n/**\n * Opens the system editor on a temporary file.\n * @param initial Initial contents of the file.\n * @returns The contents of the file after saving.\n */\nasync function openSystemEditor(initial: string): Promise<string> {\n const tmpFile = `edit-${Date.now()}.txt`;\n const filePath = path.join(os.tmpdir(), tmpFile);\n await fs.writeFile(filePath, initial ?? \"\", \"utf8\");\n\n const editor =\n process.env.EDITOR ||\n process.env.VISUAL ||\n (process.platform === \"win32\" ? \"notepad\" : \"vi\");\n\n return new Promise((resolve, reject) => {\n const child = childProcess.spawn(editor, [filePath], { stdio: \"inherit\" });\n child.on(\"exit\", async (code: number) => {\n if (code !== 0) {\n reject(new Error(`${editor} exited with code ${code}`));\n return;\n }\n try {\n const data = await fs.readFile(filePath, \"utf8\");\n await fs.unlink(filePath).catch(() => {});\n resolve(data);\n } catch (err) {\n reject(err);\n }\n });\n });\n}\n\nexport { raw };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUA,IAAIA,QAAe;;;;;AAMnB,SAAgB,SAAS,GAAU;AACjC,SAAQ;;;;;;;AAsDV,eAAsB,KAAK,MAAiC;CAE1D,MAAM,WADK,KAAK,SAAS,OACN,QAAQ,KAAK,QAAQ,GAAG;CAC3C,MAAM,SAAS,MAAMC,SAAa,SAAS,KAAK,QAAQ;AAExD,KAAI,KAAK,aAAa,OA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.mjs";
2
+ import readline from "node:readline";
3
+
4
+ //#region src/prompt/raw.ts
5
+ var raw_exports = /* @__PURE__ */ __export({
6
+ clearLines: () => clearLines,
7
+ cursorDown: () => cursorDown,
8
+ cursorUp: () => cursorUp,
9
+ readKey: () => readKey,
10
+ readLine: () => readLine
11
+ });
12
+ /**
13
+ * Reads a line from standard input.
14
+ * @param message The message.
15
+ * @param def Default value.
16
+ * @param opts Options for reading a line.
17
+ * @returns The line that was read.
18
+ */
19
+ function readLine(message = "", def, opts) {
20
+ return new Promise((resolve) => {
21
+ const rl = readline.createInterface({
22
+ input: process.stdin,
23
+ output: process.stdout,
24
+ terminal: true
25
+ });
26
+ if (opts?.masked) {
27
+ const write = rl._writeToOutput.bind(rl);
28
+ rl._writeToOutput = (str) => {
29
+ if (str.match(/^\x1b/)) return write(str);
30
+ if (str.endsWith("\n") || str.endsWith("\r")) return write(str);
31
+ write((opts.maskChar ?? "*").repeat(str.length));
32
+ };
33
+ }
34
+ rl.question(message, (answer) => {
35
+ rl.close();
36
+ resolve(answer || def || "");
37
+ });
38
+ });
39
+ }
40
+ /**
41
+ * Reads a single key from stdin.
42
+ * @returns The key that was read.
43
+ */
44
+ async function readKey() {
45
+ return new Promise((resolve) => {
46
+ const stdin = process.stdin;
47
+ stdin.setRawMode(true);
48
+ stdin.resume();
49
+ stdin.once("data", (data) => {
50
+ const s = data.toString();
51
+ stdin.setRawMode(false);
52
+ stdin.pause();
53
+ if (s === "\r" || s === "\n") return resolve("enter");
54
+ if (s === " ") return resolve("space");
55
+ if (s === "\x1B[A") return resolve("up");
56
+ if (s === "\x1B[B") return resolve("down");
57
+ if (s === "\x1B[C") return resolve("right");
58
+ if (s === "\x1B[D") return resolve("left");
59
+ return resolve(s);
60
+ });
61
+ });
62
+ }
63
+ /**
64
+ * Clears `lines` amount of lines.
65
+ * @param lines Amount of lines to clear.
66
+ */
67
+ function clearLines(lines = 1) {
68
+ for (let i = 0; i < lines; i++) process.stdout.write("\x1B[2K\x1B[1A");
69
+ process.stdout.write("\x1B[2K\r");
70
+ }
71
+ /**
72
+ * Moves the cursor up `n` times.
73
+ * @param n The amount of steps to move.
74
+ */
75
+ function cursorUp(n = 1) {
76
+ process.stdout.write(`\x1b[${n}A`);
77
+ }
78
+ /**
79
+ * Moves the cursor down `n` times.
80
+ * @param n The amount of steps to move.
81
+ */
82
+ function cursorDown(n = 1) {
83
+ process.stdout.write(`\x1b[${n}B`);
84
+ }
85
+
86
+ //#endregion
87
+ export { readKey as a, raw_exports as i, cursorDown as n, readLine as o, cursorUp as r, clearLines as t };
88
+ //# sourceMappingURL=raw-DEtZFeMv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-DEtZFeMv.mjs","names":[],"sources":["../src/prompt/raw.ts"],"sourcesContent":["import readline from \"node:readline\";\n\n/**\n * Reads a line from standard input.\n * @param message The message.\n * @param def Default value.\n * @param opts Options for reading a line.\n * @returns The line that was read.\n */\nexport function readLine(\n message = \"\",\n def?: string,\n opts?: { masked?: boolean; maskChar?: string; multiline?: boolean },\n): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: true,\n });\n\n if (opts?.masked) {\n const write = (rl as any)._writeToOutput.bind(rl);\n (rl as any)._writeToOutput = (str: string) => {\n if (str.match(/^\\x1b/)) return write(str);\n if (str.endsWith(\"\\n\") || str.endsWith(\"\\r\")) return write(str);\n const mask = opts.maskChar ?? \"*\";\n write(mask.repeat(str.length));\n };\n }\n\n rl.question(message, (answer: string) => {\n rl.close();\n resolve(answer || def || \"\");\n });\n });\n}\n\n/**\n * Reads a single key from stdin.\n * @returns The key that was read.\n */\nexport async function readKey(): Promise<string> {\n return new Promise((resolve) => {\n const stdin = process.stdin;\n stdin.setRawMode(true);\n stdin.resume();\n stdin.once(\"data\", (data: Buffer) => {\n const s = data.toString();\n stdin.setRawMode(false);\n stdin.pause();\n if (s === \"\\r\" || s === \"\\n\") return resolve(\"enter\");\n if (s === \" \") return resolve(\"space\");\n if (s === \"\\u001b[A\") return resolve(\"up\");\n if (s === \"\\u001b[B\") return resolve(\"down\");\n if (s === \"\\u001b[C\") return resolve(\"right\");\n if (s === \"\\u001b[D\") return resolve(\"left\");\n return resolve(s);\n });\n });\n}\n\n/**\n * Clears `lines` amount of lines.\n * @param lines Amount of lines to clear.\n */\nexport function clearLines(lines = 1) {\n for (let i = 0; i < lines; i++) process.stdout.write(\"\\x1b[2K\\x1b[1A\");\n process.stdout.write(\"\\x1b[2K\\r\");\n}\n\n/**\n * Moves the cursor up `n` times.\n * @param n The amount of steps to move.\n */\nexport function cursorUp(n = 1) {\n process.stdout.write(`\\x1b[${n}A`);\n}\n\n/**\n * Moves the cursor down `n` times.\n * @param n The amount of steps to move.\n */\nexport function cursorDown(n = 1) {\n process.stdout.write(`\\x1b[${n}B`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AASA,SAAgB,SACd,UAAU,IACV,KACA,MACiB;AACjB,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,KAAK,SAAS,gBAAgB;GAClC,OAAO,QAAQ;GACf,QAAQ,QAAQ;GAChB,UAAU;GACX,CAAC;AAEF,MAAI,MAAM,QAAQ;GAChB,MAAM,QAAS,GAAW,eAAe,KAAK,GAAG;AACjD,GAAC,GAAW,kBAAkB,QAAgB;AAC5C,QAAI,IAAI,MAAM,QAAQ,CAAE,QAAO,MAAM,IAAI;AACzC,QAAI,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,CAAE,QAAO,MAAM,IAAI;AAE/D,WADa,KAAK,YAAY,KACnB,OAAO,IAAI,OAAO,CAAC;;;AAIlC,KAAG,SAAS,UAAU,WAAmB;AACvC,MAAG,OAAO;AACV,WAAQ,UAAU,OAAO,GAAG;IAC5B;GACF;;;;;;AAOJ,eAAsB,UAA2B;AAC/C,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,QAAQ,QAAQ;AACtB,QAAM,WAAW,KAAK;AACtB,QAAM,QAAQ;AACd,QAAM,KAAK,SAAS,SAAiB;GACnC,MAAM,IAAI,KAAK,UAAU;AACzB,SAAM,WAAW,MAAM;AACvB,SAAM,OAAO;AACb,OAAI,MAAM,QAAQ,MAAM,KAAM,QAAO,QAAQ,QAAQ;AACrD,OAAI,MAAM,IAAK,QAAO,QAAQ,QAAQ;AACtC,OAAI,MAAM,SAAY,QAAO,QAAQ,KAAK;AAC1C,OAAI,MAAM,SAAY,QAAO,QAAQ,OAAO;AAC5C,OAAI,MAAM,SAAY,QAAO,QAAQ,QAAQ;AAC7C,OAAI,MAAM,SAAY,QAAO,QAAQ,OAAO;AAC5C,UAAO,QAAQ,EAAE;IACjB;GACF;;;;;;AAOJ,SAAgB,WAAW,QAAQ,GAAG;AACpC,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,IAAK,SAAQ,OAAO,MAAM,iBAAiB;AACtE,SAAQ,OAAO,MAAM,YAAY;;;;;;AAOnC,SAAgB,SAAS,IAAI,GAAG;AAC9B,SAAQ,OAAO,MAAM,QAAQ,EAAE,GAAG;;;;;;AAOpC,SAAgB,WAAW,IAAI,GAAG;AAChC,SAAQ,OAAO,MAAM,QAAQ,EAAE,GAAG"}
@@ -0,0 +1,38 @@
1
+ declare namespace raw_d_exports {
2
+ export { clearLines, cursorDown, cursorUp, readKey, readLine };
3
+ }
4
+ /**
5
+ * Reads a line from standard input.
6
+ * @param message The message.
7
+ * @param def Default value.
8
+ * @param opts Options for reading a line.
9
+ * @returns The line that was read.
10
+ */
11
+ declare function readLine(message?: string, def?: string, opts?: {
12
+ masked?: boolean;
13
+ maskChar?: string;
14
+ multiline?: boolean;
15
+ }): Promise<string>;
16
+ /**
17
+ * Reads a single key from stdin.
18
+ * @returns The key that was read.
19
+ */
20
+ declare function readKey(): Promise<string>;
21
+ /**
22
+ * Clears `lines` amount of lines.
23
+ * @param lines Amount of lines to clear.
24
+ */
25
+ declare function clearLines(lines?: number): void;
26
+ /**
27
+ * Moves the cursor up `n` times.
28
+ * @param n The amount of steps to move.
29
+ */
30
+ declare function cursorUp(n?: number): void;
31
+ /**
32
+ * Moves the cursor down `n` times.
33
+ * @param n The amount of steps to move.
34
+ */
35
+ declare function cursorDown(n?: number): void;
36
+ //#endregion
37
+ export { readKey as a, raw_d_exports as i, cursorDown as n, readLine as o, cursorUp as r, clearLines as t };
38
+ //# sourceMappingURL=raw-cqTp2vds.d.mts.map
@@ -0,0 +1,32 @@
1
+ //#region src/input/error.ts
2
+ /**
3
+ * Thrown when the command fails to validate an input.
4
+ */
5
+ var InputValidationError = class extends Error {
6
+ /**
7
+ * Creates a new input validation error.
8
+ * @param messages The messages.
9
+ */
10
+ constructor(messages) {
11
+ super(`Validation failed: ${messages.join(", ")}`);
12
+ this.messages = messages;
13
+ }
14
+ };
15
+
16
+ //#endregion
17
+ //#region src/input/standard-schema.ts
18
+ /**
19
+ * Validates a value.
20
+ * @param entry The Standard Schema validator.
21
+ * @param value The value to validate.
22
+ * @returns The validated value.
23
+ */
24
+ async function validate(entry, value) {
25
+ const result = await entry["~standard"].validate(value);
26
+ if (result.issues) throw new InputValidationError(result.issues.map((i) => i.message));
27
+ return result.value;
28
+ }
29
+
30
+ //#endregion
31
+ export { InputValidationError as n, validate as t };
32
+ //# sourceMappingURL=standard-schema-DTuaYJjO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema-DTuaYJjO.mjs","names":[],"sources":["../src/input/error.ts","../src/input/standard-schema.ts"],"sourcesContent":["/**\n * Thrown when the command fails to validate an input.\n */\nexport class InputValidationError extends Error {\n /**\n * A list of messages.\n */\n messages: string[];\n\n /**\n * Creates a new input validation error.\n * @param messages The messages.\n */\n constructor(messages: string[]) {\n super(`Validation failed: ${messages.join(\", \")}`);\n this.messages = messages;\n }\n}\n","// * https://standardschema.dev * //\n\nimport { InputValidationError } from \"./error\";\n\n/** The Standard Schema interface. */\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n /** The Standard Schema properties. */\n readonly \"~standard\": StandardSchemaV1.Props<Input, Output>;\n}\n\n// eslint-disable-next-line -- this is Standard Schema\nexport declare namespace StandardSchemaV1 {\n /** The Standard Schema properties interface. */\n export interface Props<Input = unknown, Output = Input> {\n /** The version number of the standard. */\n readonly version: 1;\n /** The vendor name of the schema library. */\n readonly vendor: string;\n /** Validates unknown input values. */\n readonly validate: (\n value: unknown,\n ) => Result<Output> | Promise<Result<Output>>;\n /** Inferred types associated with the schema. */\n readonly types?: Types<Input, Output> | undefined;\n }\n\n /** The result interface of the validate function. */\n export type Result<Output> = SuccessResult<Output> | FailureResult;\n\n /** The result interface if validation succeeds. */\n export interface SuccessResult<Output> {\n /** The typed output value. */\n readonly value: Output;\n /** The non-existent issues. */\n readonly issues?: undefined;\n }\n\n /** The result interface if validation fails. */\n export interface FailureResult {\n /** The issues of failed validation. */\n readonly issues: ReadonlyArray<Issue>;\n }\n\n /** The issue interface of the failure output. */\n export interface Issue {\n /** The error message of the issue. */\n readonly message: string;\n /** The path of the issue, if any. */\n readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;\n }\n\n /** The path segment interface of the issue. */\n export interface PathSegment {\n /** The key representing a path segment. */\n readonly key: PropertyKey;\n }\n\n /** The Standard Schema types interface. */\n export interface Types<Input = unknown, Output = Input> {\n /** The input type of the schema. */\n readonly input: Input;\n /** The output type of the schema. */\n readonly output: Output;\n }\n\n /** Infers the input type of a Standard Schema. */\n export type InferInput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"input\"];\n\n /** Infers the output type of a Standard Schema. */\n export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"output\"];\n}\n\n/**\n * Validates a value.\n * @param entry The Standard Schema validator.\n * @param value The value to validate.\n * @returns The validated value.\n */\nexport async function validate<T extends StandardSchemaV1<any, any>>(\n entry: T,\n value: any,\n): Promise<T extends StandardSchemaV1<any, infer Out> ? Out : never> {\n const result = await entry[\"~standard\"].validate(value);\n if (result.issues) {\n const msgs = result.issues.map((i) => i.message);\n throw new InputValidationError(msgs);\n }\n\n return result.value;\n}\n"],"mappings":";;;;AAGA,IAAa,uBAAb,cAA0C,MAAM;;;;;CAU9C,YAAY,UAAoB;AAC9B,QAAM,sBAAsB,SAAS,KAAK,KAAK,GAAG;AAClD,OAAK,WAAW;;;;;;;;;;;;ACmEpB,eAAsB,SACpB,OACA,OACmE;CACnE,MAAM,SAAS,MAAM,MAAM,aAAa,SAAS,MAAM;AACvD,KAAI,OAAO,OAET,OAAM,IAAI,qBADG,OAAO,OAAO,KAAK,MAAM,EAAE,QAAQ,CACZ;AAGtC,QAAO,OAAO"}
@@ -0,0 +1,59 @@
1
+ //#region src/input/standard-schema.d.ts
2
+ /** The Standard Schema interface. */
3
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
4
+ /** The Standard Schema properties. */
5
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
6
+ }
7
+ declare namespace StandardSchemaV1 {
8
+ /** The Standard Schema properties interface. */
9
+ interface Props<Input = unknown, Output = Input> {
10
+ /** The version number of the standard. */
11
+ readonly version: 1;
12
+ /** The vendor name of the schema library. */
13
+ readonly vendor: string;
14
+ /** Validates unknown input values. */
15
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
16
+ /** Inferred types associated with the schema. */
17
+ readonly types?: Types<Input, Output> | undefined;
18
+ }
19
+ /** The result interface of the validate function. */
20
+ type Result<Output> = SuccessResult<Output> | FailureResult;
21
+ /** The result interface if validation succeeds. */
22
+ interface SuccessResult<Output> {
23
+ /** The typed output value. */
24
+ readonly value: Output;
25
+ /** The non-existent issues. */
26
+ readonly issues?: undefined;
27
+ }
28
+ /** The result interface if validation fails. */
29
+ interface FailureResult {
30
+ /** The issues of failed validation. */
31
+ readonly issues: ReadonlyArray<Issue>;
32
+ }
33
+ /** The issue interface of the failure output. */
34
+ interface Issue {
35
+ /** The error message of the issue. */
36
+ readonly message: string;
37
+ /** The path of the issue, if any. */
38
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
39
+ }
40
+ /** The path segment interface of the issue. */
41
+ interface PathSegment {
42
+ /** The key representing a path segment. */
43
+ readonly key: PropertyKey;
44
+ }
45
+ /** The Standard Schema types interface. */
46
+ interface Types<Input = unknown, Output = Input> {
47
+ /** The input type of the schema. */
48
+ readonly input: Input;
49
+ /** The output type of the schema. */
50
+ readonly output: Output;
51
+ }
52
+ /** Infers the input type of a Standard Schema. */
53
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
54
+ /** Infers the output type of a Standard Schema. */
55
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
56
+ }
57
+ //#endregion
58
+ export { StandardSchemaV1 as t };
59
+ //# sourceMappingURL=standard-schema-DXS-QnwX.d.mts.map
package/package.json CHANGED
@@ -1,41 +1,37 @@
1
1
  {
2
2
  "name": "convoker",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "A simple, type safe CLI framework for TypeScript.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/trailfrost/convoker"
7
+ "url": "git+https://github.com/sprucepad/convoker"
8
8
  },
9
- "main": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
9
+ "main": "./dist/index.mjs",
10
+ "types": "./dist/index.d.mts",
11
11
  "exports": {
12
12
  ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js"
13
+ "types": "./dist/index.d.mts",
14
+ "import": "./dist/index.mjs"
15
15
  },
16
16
  "./command": {
17
- "types": "./dist/command.d.ts",
18
- "import": "./dist/command.js"
17
+ "types": "./dist/command/index.d.mts",
18
+ "import": "./dist/command/index.mjs"
19
19
  },
20
20
  "./input": {
21
- "types": "./dist/types.d.ts",
22
- "import": "./dist/input.js"
21
+ "types": "./dist/input/index.d.mts",
22
+ "import": "./dist/input/index.mjs"
23
23
  },
24
24
  "./color": {
25
- "types": "./dist/color.d.ts",
26
- "import": "./dist/color.js"
25
+ "types": "./dist/color/index.d.mts",
26
+ "import": "./dist/color/index.mjs"
27
27
  },
28
28
  "./prompt": {
29
- "types": "./dist/prompt/index.d.ts",
30
- "import": "./dist/prompt/index.js"
29
+ "types": "./dist/prompt/index.d.mts",
30
+ "import": "./dist/prompt/index.mjs"
31
31
  },
32
32
  "./prompt/raw": {
33
- "types": "./dist/prompt/raw.d.ts",
34
- "import": "./dist/prompt/raw.js"
35
- },
36
- "./error": {
37
- "types": "./dist/error.d.ts",
38
- "import": "./dist/error.js"
33
+ "types": "./dist/prompt/raw.d.mts",
34
+ "import": "./dist/prompt/raw.mjs"
39
35
  }
40
36
  },
41
37
  "type": "module",
@@ -49,25 +45,27 @@
49
45
  "argv",
50
46
  "option"
51
47
  ],
52
- "author": "trailfrost",
48
+ "author": "sprucepad",
53
49
  "license": "MIT",
54
50
  "devDependencies": {
55
51
  "@eslint/js": "^9.36.0",
52
+ "@types/node": "~20.19.30",
56
53
  "eslint": "^9.36.0",
57
54
  "globals": "^16.4.0",
58
55
  "prettier": "^3.6.2",
59
- "tsc-alias": "^1.8.16",
56
+ "tsdown": "^0.16.0",
60
57
  "typescript": "^5.9.2",
61
58
  "typescript-eslint": "^8.45.0",
62
59
  "valibot": "^1.1.0",
63
60
  "vitest": "^3.2.4"
64
61
  },
65
62
  "scripts": {
66
- "test": "vitest tests",
67
- "build": "tsc -b tsconfig.app.json && tsc-alias -p tsconfig.app.json",
63
+ "test": "vitest",
64
+ "build": "tsdown",
65
+ "check": "tsc",
68
66
  "format": "prettier --check .",
69
- "format!": "prettier --write .",
67
+ "format:fix": "prettier --write .",
70
68
  "lint": "eslint .",
71
- "lint!": "eslint --fix ."
69
+ "lint:fix": "eslint --fix ."
72
70
  }
73
71
  }