1 |
|
2 |
|
3 | import { Observable } from "rxjs";
|
4 | import * as stream from "stream";
|
5 |
|
6 | declare namespace Listr {
|
7 | type ListrContext = any;
|
8 | type ListrRendererValue<Ctx> = "silent" | "default" | "verbose" | ListrRendererClass<Ctx>;
|
9 | type ListrTaskResult<Ctx> = string | Promise<any> | Listr<Ctx> | stream.Readable | Observable<any>;
|
10 |
|
11 | interface ListrOptions<Ctx = ListrContext> {
|
12 | concurrent?: boolean | number | undefined;
|
13 | exitOnError?: boolean | undefined;
|
14 | renderer?: ListrRendererValue<Ctx> | undefined;
|
15 | nonTTYRenderer?: ListrRendererValue<Ctx> | undefined;
|
16 | }
|
17 |
|
18 | interface ListrEvent {
|
19 | type: string;
|
20 | data?: string | boolean | undefined;
|
21 | }
|
22 |
|
23 | interface ListrTask<Ctx = ListrContext> {
|
24 | title: string;
|
25 |
|
26 | task: (ctx: Ctx, task: ListrTaskWrapper<Ctx>) => void | ListrTaskResult<Ctx>;
|
27 |
|
28 | skip?: ((ctx: Ctx) => void | boolean | string | Promise<undefined | boolean | string>) | undefined;
|
29 | enabled?: ((ctx: Ctx) => boolean | Promise<boolean> | Observable<boolean>) | undefined;
|
30 | }
|
31 |
|
32 | interface ListrTaskObject<Ctx> extends Observable<ListrEvent> {
|
33 | title: string;
|
34 | output?: string | undefined;
|
35 | // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
36 | task: (ctx: Ctx, task: ListrTaskWrapper<Ctx>) => void | ListrTaskResult<Ctx>;
|
37 |
|
38 | skip: (ctx: Ctx) => void | boolean | string | Promise<undefined | boolean | string>;
|
39 | subtasks: ReadonlyArray<ListrTaskWrapper<Ctx>>;
|
40 | state: string;
|
41 | check: (ctx: Ctx) => void;
|
42 | hasSubtasks(): boolean;
|
43 | isPending(): boolean;
|
44 | isSkipped(): boolean;
|
45 | isCompleted(): boolean;
|
46 | isEnabled(): boolean;
|
47 | hasFailed(): boolean;
|
48 | run: (ctx: Ctx, wrapper: ListrTaskWrapper<Ctx>) => Promise<void>;
|
49 | }
|
50 |
|
51 | interface ListrTaskWrapper<Ctx = ListrContext> {
|
52 | title: string;
|
53 | output: string;
|
54 | report(error: Error): void;
|
55 | skip(message: string): void;
|
56 | run(ctx?: Ctx): Promise<void>;
|
57 | }
|
58 |
|
59 | interface ListrError<Ctx> extends Error {
|
60 | context: Ctx;
|
61 | }
|
62 |
|
63 | interface ListrRenderer {
|
64 | render(): void;
|
65 | end(err: Error): void;
|
66 | }
|
67 | interface ListrRendererClass<Ctx> {
|
68 | nonTTY: boolean;
|
69 | new(tasks: ReadonlyArray<ListrTaskObject<Ctx>>, options: ListrOptions<Ctx>): ListrRenderer;
|
70 | }
|
71 | }
|
72 |
|
73 | declare class Listr<Ctx = Listr.ListrContext> {
|
74 | constructor(tasks?: ReadonlyArray<Listr.ListrTask<Ctx>>, options?: Listr.ListrOptions<Ctx>);
|
75 | constructor(options?: Listr.ListrOptions<Ctx>);
|
76 | tasks: ReadonlyArray<Listr.ListrTaskWrapper<Ctx>>;
|
77 | setRenderer(value: Listr.ListrRendererValue<Ctx>): void;
|
78 | add(tasks: Listr.ListrTask<Ctx> | ReadonlyArray<Listr.ListrTask<Ctx>>): void;
|
79 | render(): void;
|
80 | run(ctx?: Ctx): Promise<Ctx>;
|
81 | }
|
82 |
|
83 | export = Listr;
|