amplify-prompts
Advanced tools
Comparing version 2.1.1-alpha.41 to 2.2.0-beta.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [2.2.0-beta.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.1.0...amplify-prompts@2.2.0-beta.0) (2022-06-03) | ||
### Features | ||
* prompt interaction time ([#10435](https://github.com/aws-amplify/amplify-cli/issues/10435)) ([a064ae2](https://github.com/aws-amplify/amplify-cli/commit/a064ae2e1a3a8d4e84a1fcb3ec9fc8b4491966d6)) | ||
# [2.1.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.0.1...amplify-prompts@2.1.0) (2022-05-10) | ||
@@ -8,0 +19,0 @@ |
@@ -13,2 +13,3 @@ import { IFlowData } from 'amplify-cli-shared-interfaces'; | ||
setFlowData: (flowData: IFlowData) => void; | ||
getTotalPromptElapsedTime: () => number; | ||
}; | ||
@@ -15,0 +16,0 @@ declare type MaybeAvailableHiddenInputOption<RS extends ReturnSize> = RS extends 'many' ? unknown : { |
@@ -31,2 +31,3 @@ "use strict"; | ||
const printer_1 = require("./printer"); | ||
const stopwatch_1 = require("./stopwatch"); | ||
class AmplifyPrompter { | ||
@@ -47,3 +48,3 @@ constructor(prompter = enquirer_1.prompt, print = printer_1.printer) { | ||
if (this.flowData && input) { | ||
const finalInput = (redact) ? "*".repeat(input.length) : input; | ||
const finalInput = (redact) ? '*'.repeat(input.length) : input; | ||
this.flowData.pushInteractiveFlow(promptString, finalInput); | ||
@@ -75,2 +76,3 @@ } | ||
let submitted = false; | ||
this.stopWatch.start(); | ||
const { result } = await this.prompter({ | ||
@@ -87,2 +89,3 @@ type: 'confirm', | ||
}); | ||
this.stopWatch.pause(); | ||
this.pushInteractiveFlow(message, result); | ||
@@ -97,3 +100,3 @@ return result; | ||
if (opts.initial !== undefined) { | ||
this.pushInteractiveFlow(message, opts.initial, enquirerPromptType == EnquirerPromptType.INVISIBLE); | ||
this.pushInteractiveFlow(message, opts.initial, enquirerPromptType === EnquirerPromptType.INVISIBLE); | ||
return opts.initial; | ||
@@ -104,2 +107,3 @@ } | ||
const validator = (opts.returnSize === 'many' ? validateEachWith(opts.validate) : opts.validate); | ||
this.stopWatch.start(); | ||
const { result } = await this.prompter({ | ||
@@ -113,2 +117,3 @@ type: enquirerPromptType, | ||
}); | ||
this.stopWatch.pause(); | ||
if (typeof opts.transform === 'function') { | ||
@@ -145,2 +150,3 @@ let functionResult; | ||
let result = genericChoices[0].name; | ||
this.stopWatch.start(); | ||
if (choices.length === 1 && opts.returnSize !== 'many') { | ||
@@ -202,5 +208,7 @@ this.print.info(`Only one option for [${message}]. Selecting [${result}].`); | ||
} | ||
this.stopWatch.pause(); | ||
this.pushInteractiveFlow(message, loggedRet); | ||
return loggedRet; | ||
}; | ||
this.getTotalPromptElapsedTime = () => this.stopWatch.getElapsedMilliseconds(); | ||
const prompterShim = ((opts) => { | ||
@@ -213,2 +221,3 @@ if (flags_1.isInteractiveShell) { | ||
this.prompter = prompterShim; | ||
this.stopWatch = new stopwatch_1.Stopwatch(); | ||
} | ||
@@ -248,3 +257,2 @@ } | ||
})(EnquirerPromptType || (EnquirerPromptType = {})); | ||
; | ||
//# sourceMappingURL=prompter.js.map |
{ | ||
"name": "amplify-prompts", | ||
"version": "2.1.1-alpha.41+896b51833", | ||
"version": "2.2.0-beta.0", | ||
"description": "Utility functions for Amplify CLI terminal I/O", | ||
@@ -29,3 +29,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"amplify-cli-shared-interfaces": "1.1.1-alpha.41+896b51833", | ||
"amplify-cli-shared-interfaces": "1.1.0", | ||
"chalk": "^4.1.1", | ||
@@ -53,3 +53,3 @@ "enquirer": "^2.3.6" | ||
}, | ||
"gitHead": "896b51833e30daf9997d38c9229ca237ab7deda1" | ||
"gitHead": "5d16a527ec59120adeeeb0717c419491e70007c7" | ||
} |
@@ -17,2 +17,3 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
import { printer } from './printer'; | ||
import { Stopwatch } from './stopwatch'; | ||
@@ -24,2 +25,3 @@ /** | ||
flowData: IFlowData|undefined; // interactive cli flow data journal | ||
stopWatch: Stopwatch; | ||
constructor(private readonly prompter: typeof prompt = prompt, private readonly print: typeof printer = printer) { | ||
@@ -36,2 +38,3 @@ // construct a shim on top of enquirer to throw an error if it is called when stdin is non-interactive | ||
this.prompter = prompterShim; | ||
this.stopWatch = new Stopwatch(); | ||
} | ||
@@ -48,6 +51,6 @@ | ||
private pushInteractiveFlow = (promptString: string, input: unknown, redact : boolean = false) => { | ||
if ( isInteractiveShell ) { | ||
if (this.flowData && input ) { | ||
const finalInput = ( redact ) ? "*".repeat((input as string).length) : input; | ||
private pushInteractiveFlow = (promptString: string, input: unknown, redact = false) => { | ||
if (isInteractiveShell) { | ||
if (this.flowData && input) { | ||
const finalInput = (redact) ? '*'.repeat((input as string).length) : input; | ||
this.flowData.pushInteractiveFlow(promptString, finalInput); | ||
@@ -88,2 +91,3 @@ } | ||
let submitted = false; | ||
this.stopWatch.start(); | ||
const { result } = await this.prompter<{ result: boolean }>({ | ||
@@ -101,2 +105,3 @@ type: 'confirm', | ||
}); | ||
this.stopWatch.pause(); | ||
this.pushInteractiveFlow(message, result); | ||
@@ -106,4 +111,2 @@ return result; | ||
/** | ||
@@ -125,7 +128,7 @@ * Prompt for an input. | ||
const opts = options?.[0] ?? ({} as InputOptions<RS, T>); | ||
const enquirerPromptType : EnquirerPromptType = 'hidden' in opts && opts.hidden ? EnquirerPromptType.INVISIBLE : opts.returnSize === 'many' ? EnquirerPromptType.LIST : EnquirerPromptType.INPUT; | ||
const enquirerPromptType : EnquirerPromptType = 'hidden' in opts && opts.hidden ? EnquirerPromptType.INVISIBLE : opts.returnSize === 'many' ? EnquirerPromptType.LIST : EnquirerPromptType.INPUT; | ||
if (isYes) { | ||
if (opts.initial !== undefined) { | ||
this.pushInteractiveFlow(message, opts.initial, enquirerPromptType == EnquirerPromptType.INVISIBLE); | ||
this.pushInteractiveFlow(message, opts.initial, enquirerPromptType === EnquirerPromptType.INVISIBLE); | ||
return opts.initial as PromptReturn<RS, T>; | ||
@@ -137,3 +140,3 @@ } | ||
const validator = (opts.returnSize === 'many' ? validateEachWith(opts.validate) : opts.validate) as ValidatorCast; | ||
this.stopWatch.start(); | ||
const { result } = await this.prompter<{ result: RS extends 'many' ? string[] : string }>({ | ||
@@ -151,2 +154,3 @@ // eslint-disable-next-line no-nested-ternary | ||
}); | ||
this.stopWatch.pause(); | ||
@@ -160,6 +164,7 @@ if (typeof opts.transform === 'function') { | ||
} | ||
this.pushInteractiveFlow(message, functionResult, enquirerPromptType == EnquirerPromptType.INVISIBLE ); | ||
this.pushInteractiveFlow(message, functionResult, enquirerPromptType == EnquirerPromptType.INVISIBLE); | ||
return functionResult; | ||
} | ||
this.pushInteractiveFlow(message, result, enquirerPromptType == EnquirerPromptType.INVISIBLE ); | ||
this.pushInteractiveFlow(message, result, enquirerPromptType == EnquirerPromptType.INVISIBLE); | ||
return result as unknown as PromptReturn<RS, T>; | ||
@@ -216,3 +221,3 @@ }; | ||
let result = genericChoices[0].name as string | string[]; | ||
this.stopWatch.start(); | ||
if (choices.length === 1 && opts.returnSize !== 'many') { | ||
@@ -295,5 +300,8 @@ this.print.info(`Only one option for [${message}]. Selecting [${result}].`); | ||
} | ||
this.stopWatch.pause(); | ||
this.pushInteractiveFlow(message, loggedRet); | ||
return loggedRet; | ||
}; | ||
getTotalPromptElapsedTime = () : number => this.stopWatch.getElapsedMilliseconds() | ||
} | ||
@@ -310,4 +318,4 @@ | ||
export const byValues = <T>(selection: T[], equals: EqualsFunction<T> = defaultEquals): MultiFilterFunction<T> => ( | ||
choices: T[] | ||
) => selection.map(sel => choices.findIndex(choice => equals(choice, sel))).filter(idx => idx >= 0); | ||
choices: T[], | ||
) => selection.map(sel => choices.findIndex(choice => equals(choice, sel))).filter(idx => idx >= 0); | ||
@@ -366,2 +374,3 @@ /** | ||
setFlowData: (flowData: IFlowData) => void; | ||
getTotalPromptElapsedTime: () => number; | ||
}; | ||
@@ -462,2 +471,2 @@ | ||
INPUT = 'input' | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
184971
51
1711
0
+ Addedamplify-cli-shared-interfaces@1.1.0(transitive)