@simplysf/simply-plugin-kit 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/prompts/prompts.d.ts +43 -0
- package/lib/prompts/prompts.js +64 -0
- package/lib/prompts/prompts.js.map +1 -1
- package/messages/simply.plugin-kit.md +4 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { targetOrgFlags } from './flags/orgFlags.js';
|
|
2
2
|
export { requireConnection, type TargetOrgFlagValues } from './org/requireConnection.js';
|
|
3
|
-
export { confirm, select, type ConfirmPromptOptions, type SelectOption, type SelectPromptOptions, } from './prompts/prompts.js';
|
|
3
|
+
export { confirm, select, spinner, text, type ConfirmPromptOptions, type SelectOption, type SelectPromptOptions, type SpinnerControl, type SpinnerOptions, type TextPromptOptions, } from './prompts/prompts.js';
|
package/lib/index.js
CHANGED
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export { targetOrgFlags } from './flags/orgFlags.js';
|
|
17
17
|
export { requireConnection } from './org/requireConnection.js';
|
|
18
|
-
export { confirm, select, } from './prompts/prompts.js';
|
|
18
|
+
export { confirm, select, spinner, text, } from './prompts/prompts.js';
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAA4B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EACL,OAAO,EACP,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAA4B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EACL,OAAO,EACP,MAAM,EACN,OAAO,EACP,IAAI,GAOL,MAAM,sBAAsB,CAAC"}
|
package/lib/prompts/prompts.d.ts
CHANGED
|
@@ -19,6 +19,27 @@ export type ConfirmPromptOptions = {
|
|
|
19
19
|
ms?: number;
|
|
20
20
|
defaultAnswer?: boolean;
|
|
21
21
|
};
|
|
22
|
+
export type TextPromptOptions = {
|
|
23
|
+
message: string;
|
|
24
|
+
/** Shown in the empty field as a hint. Not returned. */
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
/** Pre-filled, editable answer. */
|
|
27
|
+
initialValue?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Checks the trimmed answer. Return a message to show and ask again, or `undefined` to accept it.
|
|
30
|
+
* An empty answer is refused unless `allowEmpty` is set.
|
|
31
|
+
*/
|
|
32
|
+
validate?: (value: string) => string | undefined;
|
|
33
|
+
/** Accept an empty answer. Defaults to `false`. */
|
|
34
|
+
allowEmpty?: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Ask the user to type a single line.
|
|
38
|
+
*
|
|
39
|
+
* @returns The answer, trimmed.
|
|
40
|
+
* @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
|
|
41
|
+
*/
|
|
42
|
+
export declare function text({ message, placeholder, initialValue, validate, allowEmpty, }: TextPromptOptions): Promise<string>;
|
|
22
43
|
/**
|
|
23
44
|
* Ask the user to pick one option.
|
|
24
45
|
*
|
|
@@ -34,3 +55,25 @@ export declare function select<T>({ message, options, initialValue, maxItems }:
|
|
|
34
55
|
* @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
|
|
35
56
|
*/
|
|
36
57
|
export declare function confirm({ message, ms, defaultAnswer }: ConfirmPromptOptions): Promise<boolean>;
|
|
58
|
+
export type SpinnerOptions<T> = {
|
|
59
|
+
/** Shown beside the spinner while the task runs. */
|
|
60
|
+
message: string;
|
|
61
|
+
/** Shown when the task resolves, or built from its result. Defaults to the current message. */
|
|
62
|
+
doneMessage?: string | ((result: T) => string);
|
|
63
|
+
/** Draw the spinner. Pass the command's interactive guard, so `--json` output stays clean. Defaults to `true`. */
|
|
64
|
+
enabled?: boolean;
|
|
65
|
+
};
|
|
66
|
+
/** Handed to a {@link spinner} task, to change the spinner's text or step aside for a prompt. */
|
|
67
|
+
export type SpinnerControl = {
|
|
68
|
+
/** Replace the spinner's text. */
|
|
69
|
+
message(text: string): void;
|
|
70
|
+
/** Clear the spinner, run `prompt`, then restart the spinner with its current text. */
|
|
71
|
+
pause<T>(prompt: () => Promise<T>): Promise<T>;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Run `task` behind a clack spinner. The spinner stops with `doneMessage` when the task resolves,
|
|
75
|
+
* or in its error state when it throws; the error is rethrown unchanged.
|
|
76
|
+
*
|
|
77
|
+
* @returns Whatever `task` resolves.
|
|
78
|
+
*/
|
|
79
|
+
export declare function spinner<T>({ message, doneMessage, enabled }: SpinnerOptions<T>, task: (control: SpinnerControl) => Promise<T>): Promise<T>;
|
package/lib/prompts/prompts.js
CHANGED
|
@@ -17,6 +17,30 @@ import * as clack from '@clack/prompts';
|
|
|
17
17
|
import { Messages } from '@salesforce/core';
|
|
18
18
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
19
19
|
const messages = Messages.loadMessages('@simplysf/simply-plugin-kit', 'simply.plugin-kit');
|
|
20
|
+
/**
|
|
21
|
+
* Ask the user to type a single line.
|
|
22
|
+
*
|
|
23
|
+
* @returns The answer, trimmed.
|
|
24
|
+
* @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
|
|
25
|
+
*/
|
|
26
|
+
export async function text({ message, placeholder, initialValue, validate, allowEmpty = false, }) {
|
|
27
|
+
const answer = await clack.text({
|
|
28
|
+
message,
|
|
29
|
+
placeholder,
|
|
30
|
+
initialValue,
|
|
31
|
+
validate: (value) => {
|
|
32
|
+
const trimmed = (value ?? '').trim();
|
|
33
|
+
if (!trimmed && !allowEmpty) {
|
|
34
|
+
return messages.getMessage('prompt.required');
|
|
35
|
+
}
|
|
36
|
+
return validate?.(trimmed);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (clack.isCancel(answer)) {
|
|
40
|
+
throw messages.createError('error.promptCancelled');
|
|
41
|
+
}
|
|
42
|
+
return answer.trim();
|
|
43
|
+
}
|
|
20
44
|
/**
|
|
21
45
|
* Ask the user to pick one option.
|
|
22
46
|
*
|
|
@@ -55,4 +79,44 @@ export async function confirm({ message, ms = 10_000, defaultAnswer = false }) {
|
|
|
55
79
|
}
|
|
56
80
|
return answer;
|
|
57
81
|
}
|
|
82
|
+
/** Exit status for a run interrupted by Ctrl+C (128 + SIGINT). */
|
|
83
|
+
const SIGINT_EXIT_CODE = 130;
|
|
84
|
+
/**
|
|
85
|
+
* Run `task` behind a clack spinner. The spinner stops with `doneMessage` when the task resolves,
|
|
86
|
+
* or in its error state when it throws; the error is rethrown unchanged.
|
|
87
|
+
*
|
|
88
|
+
* @returns Whatever `task` resolves.
|
|
89
|
+
*/
|
|
90
|
+
export async function spinner({ message, doneMessage, enabled = true }, task) {
|
|
91
|
+
if (!enabled) {
|
|
92
|
+
return task({ message: () => { }, pause: (prompt) => prompt() });
|
|
93
|
+
}
|
|
94
|
+
// While it runs, clack's spinner listens for SIGINT, which replaces Node's default exit on Ctrl+C.
|
|
95
|
+
const spin = clack.spinner({ onCancel: () => process.exit(SIGINT_EXIT_CODE) });
|
|
96
|
+
let current = message;
|
|
97
|
+
spin.start(current);
|
|
98
|
+
try {
|
|
99
|
+
const result = await task({
|
|
100
|
+
message: (next) => {
|
|
101
|
+
current = next;
|
|
102
|
+
spin.message(next);
|
|
103
|
+
},
|
|
104
|
+
pause: async (prompt) => {
|
|
105
|
+
spin.clear();
|
|
106
|
+
try {
|
|
107
|
+
return await prompt();
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
spin.start(current);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
spin.stop(typeof doneMessage === 'function' ? doneMessage(result) : (doneMessage ?? current));
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
spin.error(current);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
58
122
|
//# sourceMappingURL=prompts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/prompts/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,6BAA6B,EAAE,mBAAmB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/prompts/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,6BAA6B,EAAE,mBAAmB,CAAC,CAAC;AAyC3F;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,EACzB,OAAO,EACP,WAAW,EACX,YAAY,EACZ,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EAAE,MAAM,EAAE,EAAE;gBACtB,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,IAAI,CAAC;oBACH,OAAO,MAAM,MAAM,EAAE,CAAC;gBACxB,CAAC;wBAAS,CAAC;oBACT,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;SACF,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,CAAC;QAC9F,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysf/simply-plugin-kit",
|
|
3
3
|
"description": "Shared oclif command building blocks for SimplySF Salesforce CLI plugins",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "@ClayChipps",
|
|
6
6
|
"homepage": "https://github.com/SimplySF/simply-plugins",
|
|
7
7
|
"bugs": "https://github.com/SimplySF/simply-plugins/issues",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"output": []
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "99348f5800f6fb7dd943806724f9a93a69175a58"
|
|
129
129
|
}
|