@wocker/utils 1.0.11 → 2.0.0-beta.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.
Files changed (63) hide show
  1. package/README.md +73 -2
  2. package/lib/index.d.ts +3 -8
  3. package/lib/index.js +3 -8
  4. package/lib/messages.d.ts +15 -0
  5. package/lib/messages.js +18 -0
  6. package/lib/prompts/index.d.ts +3 -0
  7. package/lib/prompts/index.js +19 -0
  8. package/lib/prompts/promptConfirm.d.ts +4 -0
  9. package/lib/prompts/promptConfirm.js +75 -0
  10. package/lib/prompts/promptInput.d.ts +15 -0
  11. package/lib/prompts/promptInput.js +179 -0
  12. package/lib/prompts/promptSelect.d.ts +15 -0
  13. package/lib/prompts/promptSelect.js +162 -0
  14. package/lib/tools/index.d.ts +4 -0
  15. package/lib/tools/index.js +20 -0
  16. package/lib/{normalizeOptions.d.ts → tools/normalizeOptions.d.ts} +6 -8
  17. package/lib/tools/normalizeOptions.js +26 -0
  18. package/lib/{volumeFormat.js → tools/volumeFormat.js} +1 -1
  19. package/lib/types/KeypressEvent.d.ts +5 -0
  20. package/lib/types/KeypressEvent.js +2 -0
  21. package/lib/types/PromptConfig.d.ts +8 -0
  22. package/lib/types/PromptConfig.js +2 -0
  23. package/lib/types/PromptValidationConfig.d.ts +10 -0
  24. package/lib/types/PromptValidationConfig.js +2 -0
  25. package/lib/types/Theme.d.ts +6 -0
  26. package/lib/types/Theme.js +2 -0
  27. package/lib/types/Validation.d.ts +2 -0
  28. package/lib/types/Validation.js +2 -0
  29. package/lib/types/ValidationError.d.ts +4 -0
  30. package/lib/types/ValidationError.js +2 -0
  31. package/lib/types/ValidationResult.d.ts +1 -0
  32. package/lib/types/ValidationResult.js +2 -0
  33. package/lib/types/ValidationRule.d.ts +3 -0
  34. package/lib/types/ValidationRule.js +2 -0
  35. package/lib/types/ValidationValue.d.ts +1 -0
  36. package/lib/types/ValidationValue.js +2 -0
  37. package/lib/types/ValidationValueMessage.d.ts +5 -0
  38. package/lib/types/ValidationValueMessage.js +2 -0
  39. package/lib/validation/normalizeRule.d.ts +3 -0
  40. package/lib/validation/normalizeRule.js +16 -0
  41. package/lib/validation/validatePrompt.d.ts +3 -0
  42. package/lib/validation/validatePrompt.js +101 -0
  43. package/lib/validators/index.d.ts +1 -0
  44. package/lib/validators/index.js +17 -0
  45. package/lib/validators/validateVolume.d.ts +2 -0
  46. package/lib/validators/validateVolume.js +20 -0
  47. package/package.json +18 -7
  48. package/lib/normalizeOptions.js +0 -23
  49. package/lib/promptConfig.d.ts +0 -14
  50. package/lib/promptConfig.js +0 -76
  51. package/lib/promptConfirm.d.ts +0 -6
  52. package/lib/promptConfirm.js +0 -27
  53. package/lib/promptGroup.d.ts +0 -14
  54. package/lib/promptGroup.js +0 -55
  55. package/lib/promptSelect.d.ts +0 -14
  56. package/lib/promptSelect.js +0 -58
  57. package/lib/promptText.d.ts +0 -11
  58. package/lib/promptText.js +0 -62
  59. /package/lib/{demuxOutput.d.ts → tools/demuxOutput.d.ts} +0 -0
  60. /package/lib/{demuxOutput.js → tools/demuxOutput.js} +0 -0
  61. /package/lib/{volumeFormat.d.ts → tools/volumeFormat.d.ts} +0 -0
  62. /package/lib/{volumeParse.d.ts → tools/volumeParse.d.ts} +0 -0
  63. /package/lib/{volumeParse.js → tools/volumeParse.js} +0 -0
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ const normalizeOptions = (rawOptions) => {
5
+ if (Array.isArray(rawOptions)) {
6
+ return rawOptions.map((option) => {
7
+ if (typeof option === "string") {
8
+ return {
9
+ label: option,
10
+ value: option
11
+ };
12
+ }
13
+ return {
14
+ label: option.label || option.value || "",
15
+ value: option.value || ""
16
+ };
17
+ });
18
+ }
19
+ return Object.keys(rawOptions).map((value) => {
20
+ return {
21
+ label: rawOptions[value],
22
+ value
23
+ };
24
+ });
25
+ };
26
+ exports.normalizeOptions = normalizeOptions;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.volumeFormat = void 0;
4
4
  const volumeFormat = (volume) => {
5
- const { source, destination, options } = volume;
5
+ const { source = "/", destination = "/", options } = volume;
6
6
  return `${source}:${destination}` + (options ? `:${options}` : "");
7
7
  };
8
8
  exports.volumeFormat = volumeFormat;
@@ -0,0 +1,5 @@
1
+ export type KeypressEvent = {
2
+ name: string;
3
+ shift?: boolean;
4
+ ctrl?: boolean;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { PartialDeep } from "@inquirer/type";
2
+ import { Theme } from "./Theme";
3
+ import { PromptValidationConfig } from "./PromptValidationConfig";
4
+ export type PromptConfig<V = unknown, C = object, T extends Theme = Theme> = C & PromptValidationConfig<V> & {
5
+ message?: string;
6
+ default?: V;
7
+ theme?: PartialDeep<T>;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { ValidationRule } from "./ValidationRule";
2
+ import { Validation } from "./Validation";
3
+ export type PromptValidationConfig<V = unknown> = {
4
+ required?: boolean | string;
5
+ min?: ValidationRule<number>;
6
+ max?: ValidationRule<number>;
7
+ minLength?: ValidationRule<number>;
8
+ maxLength?: ValidationRule<number>;
9
+ validate?: Validation<V> | Record<string, Validation<V>>;
10
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { Theme as InquirerTheme, Status } from "@inquirer/core";
2
+ export type Theme<T extends object = object> = InquirerTheme<T & {
3
+ style: {
4
+ value: (value: string, status: Status) => string;
5
+ };
6
+ }>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { ValidationResult } from "./ValidationResult";
2
+ export type Validation<T> = (value: T) => ValidationResult | Promise<ValidationResult>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type ValidationError = {
2
+ message: string;
3
+ type: string;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type ValidationResult = string | string[] | boolean | undefined;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { ValidationValue } from "./ValidationValue";
2
+ import { ValidationValueMessage } from "./ValidationValueMessage";
3
+ export type ValidationRule<T extends ValidationValue = ValidationValue> = T | ValidationValueMessage<T>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type ValidationValue = boolean | number | string | RegExp;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { ValidationValue } from "./ValidationValue";
2
+ export type ValidationValueMessage<T extends ValidationValue = ValidationValue> = {
3
+ message: string;
4
+ value: T;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { ValidationRule } from "../types/ValidationRule";
2
+ import { ValidationValue } from "../types/ValidationValue";
3
+ export declare const normalizeRule: <T extends ValidationValue = ValidationValue>(rule?: ValidationRule<T>) => [T | undefined, string | undefined];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeRule = void 0;
4
+ const normalizeRule = (rule) => {
5
+ if (typeof rule === "undefined") {
6
+ return [undefined, undefined];
7
+ }
8
+ if (typeof rule === "object" && rule !== null && !(rule instanceof RegExp)) {
9
+ return [rule.value, rule.message];
10
+ }
11
+ return [
12
+ rule,
13
+ undefined
14
+ ];
15
+ };
16
+ exports.normalizeRule = normalizeRule;
@@ -0,0 +1,3 @@
1
+ import { PromptValidationConfig } from "../types/PromptValidationConfig";
2
+ import { ValidationError } from "../types/ValidationError";
3
+ export declare const validatePrompt: <T = unknown>(value: any, config: PromptValidationConfig<T>) => Promise<undefined | ValidationError>;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validatePrompt = void 0;
13
+ const normalizeRule_1 = require("./normalizeRule");
14
+ const messages_1 = require("../messages");
15
+ const validatePrompt = (value, config) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const { required, min, max, minLength, maxLength, validate } = config;
17
+ const isEmpty = typeof value === "undefined" ||
18
+ (typeof value === "boolean" && !value) ||
19
+ (typeof value === "string" && value === "") ||
20
+ (typeof value === "object" && value === null) ||
21
+ (typeof value === "number" && isNaN(value)) ||
22
+ (Array.isArray(value) && value.length === 0);
23
+ const isRequired = (typeof required === "boolean" && required) ||
24
+ typeof required === "string";
25
+ if (isRequired && isEmpty) {
26
+ return {
27
+ type: "required",
28
+ message: typeof required === "string" ? required : messages_1.messages.required
29
+ };
30
+ }
31
+ const [minValue, minMessage] = (0, normalizeRule_1.normalizeRule)(min);
32
+ if (!isEmpty && typeof minValue !== "undefined") {
33
+ if (typeof value === "number" && value < minValue) {
34
+ return {
35
+ type: "min",
36
+ message: minMessage || messages_1.messages.min(minValue)
37
+ };
38
+ }
39
+ }
40
+ const [maxValue, maxMessage] = (0, normalizeRule_1.normalizeRule)(max);
41
+ if (!isEmpty && typeof maxValue !== "undefined") {
42
+ if (typeof value === "number" && value > maxValue) {
43
+ return {
44
+ type: "max",
45
+ message: maxMessage || messages_1.messages.max(maxValue)
46
+ };
47
+ }
48
+ }
49
+ const [minLengthValue, minLengthMessage] = (0, normalizeRule_1.normalizeRule)(minLength);
50
+ if (!isEmpty && typeof minLengthValue !== "undefined") {
51
+ const validateValue = typeof value === "number"
52
+ ? value.toString()
53
+ : value;
54
+ if (typeof validateValue === "string" && validateValue.length < minLengthValue) {
55
+ return {
56
+ type: "minLength",
57
+ message: minLengthMessage || messages_1.messages.minLength(minLengthValue)
58
+ };
59
+ }
60
+ if (Array.isArray(value) && value.length < minLengthValue) {
61
+ return {
62
+ type: "minLength",
63
+ message: minLengthMessage || messages_1.messages.minArrayLength(minLengthValue)
64
+ };
65
+ }
66
+ }
67
+ const [maxLengthValue, maxLengthMessage = ""] = (0, normalizeRule_1.normalizeRule)(maxLength);
68
+ if (!isEmpty && typeof maxLengthValue === "number") {
69
+ const validateValue = typeof value === "number"
70
+ ? value.toString()
71
+ : value;
72
+ if (typeof validateValue === "string" && validateValue.length > maxLengthValue) {
73
+ return {
74
+ type: "maxLength",
75
+ message: maxLengthMessage || messages_1.messages.maxLength(maxLengthValue)
76
+ };
77
+ }
78
+ if (Array.isArray(value) && value.length > maxLengthValue) {
79
+ return {
80
+ type: "maxLength",
81
+ message: maxLengthMessage || messages_1.messages.maxArrayLength(maxLengthValue)
82
+ };
83
+ }
84
+ }
85
+ if (validate) {
86
+ const rules = typeof validate === "function"
87
+ ? { validate }
88
+ : validate;
89
+ for (const name in rules) {
90
+ const result = yield rules[name](value);
91
+ if (result === false || typeof result === "string") {
92
+ return {
93
+ message: typeof result === "string" ? result : messages_1.messages.custom,
94
+ type: "custom"
95
+ };
96
+ }
97
+ }
98
+ }
99
+ return undefined;
100
+ });
101
+ exports.validatePrompt = validatePrompt;
@@ -0,0 +1 @@
1
+ export * from "./validateVolume";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./validateVolume"), exports);
@@ -0,0 +1,2 @@
1
+ import { Validation } from "../types/Validation";
2
+ export declare const validateVolume: Validation<unknown>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateVolume = void 0;
4
+ const messages_1 = require("../messages");
5
+ const validateVolume = (value) => {
6
+ if (typeof value === "undefined" || value === null || value === "") {
7
+ return true;
8
+ }
9
+ if (typeof value !== "string") {
10
+ return messages_1.messages.volume.notAString;
11
+ }
12
+ if (value.length > 255) {
13
+ return messages_1.messages.volume.tooLong;
14
+ }
15
+ if (!/^[A-Za-z0-9]+(?:[-_]+[A-Za-z0-9]+)*$/.test(value)) {
16
+ return messages_1.messages.volume.invalidCharacters;
17
+ }
18
+ return true;
19
+ };
20
+ exports.validateVolume = validateVolume;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/utils",
3
- "version": "1.0.11",
3
+ "version": "2.0.0-beta.1",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Utils for @wocker",
6
6
  "license": "MIT",
@@ -20,16 +20,27 @@
20
20
  "url": "https://github.com/kearisp/wocker-utils/issues"
21
21
  },
22
22
  "scripts": {
23
- "prepare": "npm run build",
24
- "watch": "tsc -w",
25
- "build": "tsc",
26
- "test": "echo \"Error: no test specified\" && exit 1"
23
+ "prepublishOnly": "npm run build",
24
+ "build": "tsc --project tsconfig.build.json",
25
+ "watch": "tsc -w --project tsconfig.build.json",
26
+ "test": "jest",
27
+ "posttest": "jest-coverage-badges --output ./coverage/badges",
28
+ "test-watch": "jest --watchAll"
27
29
  },
28
30
  "dependencies": {
29
- "inquirer": "^7.3.3"
31
+ "@inquirer/core": "^10.1.10"
30
32
  },
31
33
  "devDependencies": {
32
- "@types/inquirer": "^7.3.3",
34
+ "@inquirer/testing": "^2.1.46",
35
+ "@inquirer/type": "^3.0.6",
36
+ "@types/jest": "^29.5.14",
37
+ "@types/mute-stream": "^0.0.4",
38
+ "@types/node": "^22.14.1",
39
+ "jest": "^29.7.0",
40
+ "jest-coverage-badges": "^1.1.2",
41
+ "mute-stream": "^2.0.0",
42
+ "ts-jest": "^29.3.2",
43
+ "ts-node": "^10.9.2",
33
44
  "typescript": "^5.8.3"
34
45
  }
35
46
  }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeOptions = void 0;
4
- const normalizeOptions = (rawOptions) => {
5
- return Array.isArray(rawOptions)
6
- ? rawOptions.map((option) => {
7
- return {
8
- label: typeof option === "string"
9
- ? option
10
- : option.label || option.value || "",
11
- value: typeof option === "string"
12
- ? option
13
- : option.value || ""
14
- };
15
- })
16
- : Object.keys(rawOptions).map((value) => {
17
- return {
18
- label: rawOptions[value],
19
- value
20
- };
21
- });
22
- };
23
- exports.normalizeOptions = normalizeOptions;
@@ -1,14 +0,0 @@
1
- import { PromptConfirmOptions } from "./promptConfirm";
2
- import { PromptSelectOptions } from "./promptSelect";
3
- import { PromptTextOptions } from "./promptText";
4
- type ConfirmOptions = PromptConfirmOptions & {
5
- type: "boolean";
6
- };
7
- type SelectOptions = PromptSelectOptions & {
8
- type: "select";
9
- };
10
- type Options = {
11
- [key: string]: PromptTextOptions | ConfirmOptions | SelectOptions;
12
- };
13
- export declare const promptConfig: (options: Options, values?: any) => Promise<any>;
14
- export {};
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.promptConfig = void 0;
24
- const normalizeOptions_1 = require("./normalizeOptions");
25
- const promptConfirm_1 = require("./promptConfirm");
26
- const promptSelect_1 = require("./promptSelect");
27
- const promptText_1 = require("./promptText");
28
- const promptConfig = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...args_1], void 0, function* (options, values = {}) {
29
- for (const key in options) {
30
- const params = options[key];
31
- switch (params.type) {
32
- case "boolean": {
33
- const { type } = params, rest = __rest(params, ["type"]);
34
- values[key] = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] === "boolean"
35
- ? values[key]
36
- : typeof values[key] !== "undefined"
37
- ? values[key] === "true"
38
- : params.default }));
39
- break;
40
- }
41
- case "select": {
42
- if (params.multiple) {
43
- const { type, multiple } = params, rest = __rest(params, ["type", "multiple"]);
44
- const options = (0, normalizeOptions_1.normalizeOptions)(params.options);
45
- const selected = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { multiple: true, default: options.map((option) => {
46
- return option.value;
47
- }).filter((name) => {
48
- return values[name];
49
- }) }));
50
- for (const option of options) {
51
- if (selected.includes(option.value)) {
52
- values[option.value] = true;
53
- }
54
- else if (option.value in values) {
55
- delete values[option.value];
56
- }
57
- }
58
- }
59
- else {
60
- const { type, multiple } = params, rest = __rest(params, ["type", "multiple"]);
61
- values[key] = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { multiple: false, default: values[key] || params.default }));
62
- }
63
- break;
64
- }
65
- case "number":
66
- case "int":
67
- case "string":
68
- default: {
69
- values[key] = yield (0, promptText_1.promptText)(Object.assign(Object.assign({}, params), { default: values[key] || params.default }));
70
- break;
71
- }
72
- }
73
- }
74
- return values;
75
- });
76
- exports.promptConfig = promptConfig;
@@ -1,6 +0,0 @@
1
- type Options = {
2
- message?: string;
3
- default?: boolean;
4
- };
5
- export declare const promptConfirm: (options: Options) => Promise<boolean>;
6
- export { Options as PromptConfirmOptions };
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.promptConfirm = void 0;
16
- const inquirer_1 = __importDefault(require("inquirer"));
17
- const promptConfirm = (options) => __awaiter(void 0, void 0, void 0, function* () {
18
- const { message, default: defaultValue = true } = options;
19
- const { confirm } = yield inquirer_1.default.prompt({
20
- type: "confirm",
21
- name: "confirm",
22
- message,
23
- default: defaultValue
24
- });
25
- return confirm;
26
- });
27
- exports.promptConfirm = promptConfirm;
@@ -1,14 +0,0 @@
1
- import { PromptConfirmOptions } from "./promptConfirm";
2
- import { PromptSelectOptions } from "./promptSelect";
3
- import { PromptTextOptions } from "./promptText";
4
- type ConfirmOptions = PromptConfirmOptions & {
5
- type: "boolean";
6
- };
7
- type SelectOptions = PromptSelectOptions & {
8
- type: "select";
9
- };
10
- type Options = {
11
- [key: string]: PromptTextOptions | ConfirmOptions | SelectOptions;
12
- };
13
- export declare const promptGroup: (options: Options, values?: any) => Promise<any>;
14
- export {};
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.promptGroup = void 0;
24
- const promptConfirm_1 = require("./promptConfirm");
25
- const promptSelect_1 = require("./promptSelect");
26
- const promptText_1 = require("./promptText");
27
- const promptGroup = (options_1, ...args_1) => __awaiter(void 0, [options_1, ...args_1], void 0, function* (options, values = {}) {
28
- const res = {};
29
- for (const key in options) {
30
- const params = options[key];
31
- switch (params.type) {
32
- case "boolean": {
33
- const { type } = params, rest = __rest(params, ["type"]);
34
- res[key] = yield (0, promptConfirm_1.promptConfirm)(Object.assign(Object.assign({}, rest), { default: typeof values[key] !== "undefined"
35
- ? values[key] === "true"
36
- : params.default }));
37
- break;
38
- }
39
- case "select": {
40
- const { type } = params, rest = __rest(params, ["type"]);
41
- res[key] = yield (0, promptSelect_1.promptSelect)(Object.assign(Object.assign({}, rest), { default: values[key] || params.default }));
42
- break;
43
- }
44
- case "number":
45
- case "int":
46
- case "string":
47
- default: {
48
- res[key] = yield (0, promptText_1.promptText)(Object.assign(Object.assign({}, params), { default: values[key] || params.default }));
49
- break;
50
- }
51
- }
52
- }
53
- return res;
54
- });
55
- exports.promptGroup = promptGroup;
@@ -1,14 +0,0 @@
1
- import { RawOptions } from "./normalizeOptions";
2
- type Options = {
3
- message?: string;
4
- options: RawOptions;
5
- } & ({
6
- multiple?: false;
7
- default?: string;
8
- } | {
9
- multiple: true;
10
- default?: string[];
11
- });
12
- type ResultType<T extends Options> = T['multiple'] extends true ? string[] : string;
13
- export declare const promptSelect: <R extends ResultType<T>, T extends Options = any>(props: T) => Promise<R>;
14
- export { Options as PromptSelectOptions };