@simplysf/simply-plugin-kit 1.0.11 → 1.2.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 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/prompts/prompts.d.ts +57 -0
- package/lib/prompts/prompts.js +82 -0
- package/lib/prompts/prompts.js.map +1 -0
- package/messages/simply.plugin-kit.md +8 -0
- package/package.json +3 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +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';
|
package/lib/index.js
CHANGED
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"}
|
|
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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** One choice in a {@link select} prompt. */
|
|
2
|
+
export type SelectOption<T> = {
|
|
3
|
+
value: T;
|
|
4
|
+
/** The text shown for the option. Defaults to `String(value)`. */
|
|
5
|
+
label?: string;
|
|
6
|
+
/** Extra text shown beside the option while it is highlighted. */
|
|
7
|
+
hint?: string;
|
|
8
|
+
};
|
|
9
|
+
export type SelectPromptOptions<T> = {
|
|
10
|
+
message: string;
|
|
11
|
+
options: Array<SelectOption<T>>;
|
|
12
|
+
initialValue?: T;
|
|
13
|
+
/** How many options to show at once before the list scrolls. */
|
|
14
|
+
maxItems?: number;
|
|
15
|
+
};
|
|
16
|
+
export type ConfirmPromptOptions = {
|
|
17
|
+
message: string;
|
|
18
|
+
/** How long to wait for an answer before resolving `defaultAnswer`. Defaults to 10 seconds. */
|
|
19
|
+
ms?: number;
|
|
20
|
+
defaultAnswer?: boolean;
|
|
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>;
|
|
43
|
+
/**
|
|
44
|
+
* Ask the user to pick one option.
|
|
45
|
+
*
|
|
46
|
+
* @returns The `value` of the chosen option.
|
|
47
|
+
* @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
|
|
48
|
+
*/
|
|
49
|
+
export declare function select<T>({ message, options, initialValue, maxItems }: SelectPromptOptions<T>): Promise<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Ask a yes/no question. Same contract as `SfCommand.confirm()`: if nobody answers within `ms`, it
|
|
52
|
+
* resolves `defaultAnswer`, so an unattended run declines instead of hanging.
|
|
53
|
+
*
|
|
54
|
+
* @returns The user's answer, or `defaultAnswer` on timeout.
|
|
55
|
+
* @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
|
|
56
|
+
*/
|
|
57
|
+
export declare function confirm({ message, ms, defaultAnswer }: ConfirmPromptOptions): Promise<boolean>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026, SimplySF.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as clack from '@clack/prompts';
|
|
17
|
+
import { Messages } from '@salesforce/core';
|
|
18
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
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
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Ask the user to pick one option.
|
|
46
|
+
*
|
|
47
|
+
* @returns The `value` of the chosen option.
|
|
48
|
+
* @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
|
|
49
|
+
*/
|
|
50
|
+
export async function select({ message, options, initialValue, maxItems }) {
|
|
51
|
+
const answer = await clack.select({
|
|
52
|
+
message,
|
|
53
|
+
// clack's Option<T> type is conditional on T being a primitive; ours is the common shape of both branches.
|
|
54
|
+
options: options,
|
|
55
|
+
initialValue,
|
|
56
|
+
maxItems,
|
|
57
|
+
});
|
|
58
|
+
if (clack.isCancel(answer)) {
|
|
59
|
+
throw messages.createError('error.promptCancelled');
|
|
60
|
+
}
|
|
61
|
+
return answer;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Ask a yes/no question. Same contract as `SfCommand.confirm()`: if nobody answers within `ms`, it
|
|
65
|
+
* resolves `defaultAnswer`, so an unattended run declines instead of hanging.
|
|
66
|
+
*
|
|
67
|
+
* @returns The user's answer, or `defaultAnswer` on timeout.
|
|
68
|
+
* @throws {SfError} `PromptCancelledError` if the user cancels (Ctrl+C / Esc).
|
|
69
|
+
*/
|
|
70
|
+
export async function confirm({ message, ms = 10_000, defaultAnswer = false }) {
|
|
71
|
+
const signal = AbortSignal.timeout(ms);
|
|
72
|
+
const answer = await clack.confirm({ message, initialValue: defaultAnswer, signal });
|
|
73
|
+
if (clack.isCancel(answer)) {
|
|
74
|
+
// clack reports an aborted prompt as a cancel; the signal says which one it was.
|
|
75
|
+
if (signal.aborted) {
|
|
76
|
+
return defaultAnswer;
|
|
77
|
+
}
|
|
78
|
+
throw messages.createError('error.promptCancelled');
|
|
79
|
+
}
|
|
80
|
+
return answer;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +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;YAChD,CAAC;YACD,OAAO,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;KACF,CA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|
|
|
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.0
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"author": "@ClayChipps",
|
|
6
6
|
"homepage": "https://github.com/SimplySF/simply-plugins",
|
|
7
7
|
"bugs": "https://github.com/SimplySF/simply-plugins/issues",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"exports": "./lib/index.js",
|
|
31
31
|
"type": "module",
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"@clack/prompts": "^1.8.1",
|
|
33
34
|
"@oclif/core": "^4.11.2",
|
|
34
35
|
"@salesforce/core": "^8.30.0",
|
|
35
36
|
"@salesforce/sf-plugins-core": "^12.2.16"
|
|
@@ -124,5 +125,5 @@
|
|
|
124
125
|
"output": []
|
|
125
126
|
}
|
|
126
127
|
},
|
|
127
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "37ad65c53848845230f4d40a4ef513ab935f09ef"
|
|
128
129
|
}
|