index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var __defProp = Object.defineProperty;
  2. var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
  3. // src/prompt.ts
  4. import { ListrPromptAdapter, ListrTaskEventType, ListrTaskState } from "listr2";
  5. var ListrInquirerPromptAdapter = class extends ListrPromptAdapter {
  6. static {
  7. __name(this, "ListrInquirerPromptAdapter");
  8. }
  9. prompt;
  10. /**
  11. * Get the current running instance of `inquirer`.
  12. */
  13. get instance() {
  14. return this.prompt;
  15. }
  16. /**
  17. * Create a new prompt with `inquirer`.
  18. */
  19. async run(prompt, ...[config, context]) {
  20. context ??= {};
  21. context.output ??= this.wrapper.stdout(ListrTaskEventType.PROMPT);
  22. this.reportStarted();
  23. this.task.on(ListrTaskEventType.STATE, (event) => {
  24. if (event === ListrTaskState.SKIPPED && this.prompt) {
  25. this.cancel();
  26. }
  27. });
  28. this.prompt = prompt(config, context);
  29. let result;
  30. try {
  31. result = await this.prompt;
  32. this.reportCompleted();
  33. } catch (e) {
  34. this.reportFailed();
  35. throw e;
  36. }
  37. return result;
  38. }
  39. /**
  40. * Cancel the ongoing prompt.
  41. */
  42. cancel() {
  43. if (!this.prompt) {
  44. return;
  45. }
  46. this.reportFailed();
  47. this.prompt.cancel();
  48. }
  49. };
  50. export {
  51. ListrInquirerPromptAdapter
  52. };