@simplysf/simply-plugin-kit 1.2.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 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, text, type ConfirmPromptOptions, type SelectOption, type SelectPromptOptions, type TextPromptOptions, } 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, text, } 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,EACN,IAAI,GAKL,MAAM,sBAAsB,CAAC"}
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"}
@@ -55,3 +55,25 @@ export declare function select<T>({ message, options, initialValue, maxItems }:
55
55
  * @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
56
56
  */
57
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>;
@@ -79,4 +79,44 @@ export async function confirm({ message, ms = 10_000, defaultAnswer = false }) {
79
79
  }
80
80
  return answer;
81
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
+ }
82
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;AAyC3F;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,EACzB,OAAO,EACP,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,GAAG,KAAK,GACA;IAClB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;QAC9B,OAAO;QACP,WAAW;QACX,YAAY;QACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC5B,OAAO,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;YACh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MAAM,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,mGAAmG;IACnG,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC/E,IAAI,OAAO,GAAG,OAAO,CAAC;IACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC;YACxB,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChB,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;YACD,KAAK,EAAE,KAAK,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.2.0",
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": "37ad65c53848845230f4d40a4ef513ab935f09ef"
128
+ "gitHead": "99348f5800f6fb7dd943806724f9a93a69175a58"
129
129
  }