task.d.ts 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { Subject } from 'rxjs';
  2. import { TaskWrapper } from './task-wrapper';
  3. import { ListrTaskState } from '../constants/state.constants';
  4. import { PromptError } from '../interfaces/listr-error.interface';
  5. import { ListrEvent, ListrOptions, ListrTask, ListrTaskResult } from '../interfaces/listr.interface';
  6. import { ListrGetRendererOptions, ListrGetRendererTaskOptions, ListrRendererFactory } from '../interfaces/renderer.interface';
  7. import { Listr } from '../listr';
  8. import { PromptInstance } from '../utils/prompt.interface';
  9. /**
  10. * Create a task from the given set of variables and make it runnable.
  11. */
  12. export declare class Task<Ctx, Renderer extends ListrRendererFactory> extends Subject<ListrEvent> {
  13. listr: Listr<Ctx, any, any>;
  14. tasks: ListrTask<Ctx, any>;
  15. options: ListrOptions;
  16. rendererOptions: ListrGetRendererOptions<Renderer>;
  17. /** Unique id per task, randomly generated in the uuid v4 format */
  18. id: string;
  19. /** The current state of the task. */
  20. state: string;
  21. /** The task object itself, to further utilize it. */
  22. task: (ctx: Ctx, task: TaskWrapper<Ctx, Renderer>) => void | ListrTaskResult<Ctx>;
  23. /** Extend current task with multiple subtasks. */
  24. subtasks: Task<Ctx, any>[];
  25. /** Title of the task */
  26. title?: string;
  27. /** Untouched unchanged title of the task */
  28. initialTitle?: string;
  29. /** Output data from the task. */
  30. output?: string;
  31. /** Skip current task. */
  32. skip: boolean | string | ((ctx: Ctx) => boolean | string | Promise<boolean | string>);
  33. /** Current retry number of the task if retrying */
  34. retry?: {
  35. count: number;
  36. withError?: any;
  37. };
  38. /**
  39. * A channel for messages.
  40. *
  41. * This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
  42. */
  43. message: {
  44. /** Run time of the task, if it has been successfully resolved. */
  45. duration?: number;
  46. /** Error message of the task, if it has been failed. */
  47. error?: string;
  48. /** Skip message of the task, if it has been skipped. */
  49. skip?: string;
  50. /** Rollback message of the task, if the rollback finishes */
  51. rollback?: string;
  52. /** Retry messages */
  53. retry?: {
  54. count: number;
  55. withError?: any;
  56. };
  57. };
  58. /** Per task options for the current renderer of the task. */
  59. rendererTaskOptions: ListrGetRendererTaskOptions<Renderer>;
  60. /** This will be triggered each time a new render should happen. */
  61. renderHook$: Subject<void>;
  62. prompt: undefined | PromptInstance | PromptError;
  63. private enabled;
  64. private enabledFn;
  65. constructor(listr: Listr<Ctx, any, any>, tasks: ListrTask<Ctx, any>, options: ListrOptions, rendererOptions: ListrGetRendererOptions<Renderer>);
  66. set state$(state: ListrTaskState);
  67. set output$(data: string);
  68. set message$(data: Task<Ctx, Renderer>['message']);
  69. set title$(title: string);
  70. /**
  71. * A function to check whether this task should run at all via enable.
  72. */
  73. check(ctx: Ctx): Promise<void>;
  74. /** Returns whether this task has subtasks. */
  75. hasSubtasks(): boolean;
  76. /** Returns whether this task is in progress. */
  77. isPending(): boolean;
  78. /** Returns whether this task is skipped. */
  79. isSkipped(): boolean;
  80. /** Returns whether this task has been completed. */
  81. isCompleted(): boolean;
  82. /** Returns whether this task has been failed. */
  83. hasFailed(): boolean;
  84. /** Returns whether this task has an active rollback task going on. */
  85. isRollingBack(): boolean;
  86. /** Returns whether the rollback action was successful. */
  87. hasRolledBack(): boolean;
  88. /** Returns whether this task has an actively retrying task going on. */
  89. isRetrying(): boolean;
  90. /** Returns whether enabled function resolves to true. */
  91. isEnabled(): boolean;
  92. /** Returns whether this task actually has a title. */
  93. hasTitle(): boolean;
  94. /** Returns whether this task has a prompt inside. */
  95. isPrompt(): boolean;
  96. /** Run the current task. */
  97. run(context: Ctx, wrapper: TaskWrapper<Ctx, Renderer>): Promise<void>;
  98. }