@@ -41,7 +41,7 @@ export class TaskTree {
41
41
}
42
42
43
43
/** Fail active task or adds a new subtask and call fail on it */
44
- static fail ( error : string | Error , active = true ) : never {
44
+ static fail ( error : string | Error | unknown , active = true ) : never {
45
45
return TaskTree . tree ( ) . fail ( error , active ) ;
46
46
}
47
47
@@ -50,7 +50,7 @@ export class TaskTree {
50
50
*
51
51
* @param theme - Theme properties. The field name is a modifier the value is options
52
52
* @example
53
- * ```javascript
53
+ * ```typescript
54
54
* const theme = {
55
55
* default: '#ffffff',
56
56
* success: ['#008000', '✔'],
@@ -60,21 +60,26 @@ export class TaskTree {
60
60
* error: ['#ff0000', '✖', '[error]'],
61
61
* ...
62
62
* };
63
+ *
64
+ * const tree = TaskTree.tree();
65
+ *
66
+ * // start task tree log update in terminal
67
+ * tree.start();
63
68
* ```
64
69
* @description
65
- * | option | color | symbol | badge | description |
66
- * | ----------- | ----------------- | ------ | ----- | - ------------------------------------------- |
67
- * | ** default** | text | ✖ | ✖ | default color |
68
- * | ** active** | symbol | ✔ | ✖ | spinner, progress bar color |
69
- * | ** success** | symbol, text, bar | ✔ | ✖ | task symbol, progress bar color |
70
- * | ** skip** | symbol, text, bar | ✔ | ✔ | task symbol, progress bar color |
71
- * | ** error** | symbol, text, bar | ✔ | ✔ | task symbol, error title, progress bar color |
72
- * | ** message** | symbol | ✔ | ✖ | dim pointer to task information |
73
- * | ** info** | symbol | ✔ | ✖ | information message symbol |
74
- * | ** warning** | symbol | ✔ | ✖ | warning message symbol |
75
- * | ** subtask** | symbol, text | ✔ | ✖ | dim pointer to subtask |
76
- * | ** list** | symbol | ✔ | ✖ | list symbol |
77
- * | ** dim** | symbol, bar | ✖ | ✖ | dim color |
70
+ * | Type | `badge` | ` color` | ` symbol` | Description |
71
+ * | : ------ | : ------: | : ---------------------------- | : ---------: | : ------------------------------------------- |
72
+ * | default | ✖ | `[default]` - text | `-` | default color |
73
+ * | active | ✖ | `#4285f4` - symbol | `frame (⠧)` | spinner, progress bar color |
74
+ * | success | ✖ | `#00c851` - symbol, text, bar | ✔ | task symbol, progress bar color |
75
+ * | skip | `[skip]` | `#ff8800` - symbol, text, bar | ↓ | task symbol, progress bar color |
76
+ * | error | `[fail]` | `#ff4444` - symbol, text, bar | ✖ | task symbol, error title, progress bar color |
77
+ * | message | ✖ | `#2e2e2e` - symbol | ─ | dim pointer to task information |
78
+ * | info | ✖ | `#33b5e5` - symbol | ℹ | information message symbol |
79
+ * | warning | ✖ | `#ffbb33` - symbol | ⚠ | warning message symbol |
80
+ * | subtask | ✖ | `#2e2e2e` - symbol, text | › | dim pointer to subtask |
81
+ * | list | ✖ | `#4285f4` - symbol | ❯ | list symbol |
82
+ * | dim | ✖ | `#838584` - symbol, bar | `-` | dim color |
78
83
*
79
84
* > If you use a gradient fill for the progress bar - the color will change from `active` to `success`
80
85
*/
@@ -102,18 +107,18 @@ export class TaskTree {
102
107
}
103
108
104
109
/** Force the process to exit (see process.exit). Do nothing in "silent mode" */
105
- exit ( code : ExitCode = ExitCode . Success , error ?: string | Error ) : void | never {
110
+ exit ( code : ExitCode = ExitCode . Success , error ?: string | Error | unknown ) : void | never {
106
111
if ( this . #started) {
107
112
this . stop ( ) ;
108
113
109
114
if ( this . #silent) {
110
- if ( code === ExitCode . Error ) throw error instanceof Error ? error : new Error ( error ) ;
115
+ if ( code === ExitCode . Error ) throw this . getError ( error ) ;
111
116
} else {
112
117
// eslint-disable-next-line no-process-exit
113
118
process . exit ( code ) ;
114
119
}
115
120
} else if ( code === ExitCode . Error ) {
116
- throw error instanceof Error ? error : new Error ( error ) ;
121
+ throw this . getError ( error ) ;
117
122
}
118
123
}
119
124
@@ -122,8 +127,8 @@ export class TaskTree {
122
127
* @param error - Text or Error object for display
123
128
* @param active - If `true` - call failed for active task, else create new task and call fail on it
124
129
*/
125
- fail ( error : string | Error , active = true ) : never {
126
- const errorObject = error instanceof Error ? error : new Error ( error ) ;
130
+ fail ( error : string | Error | unknown , active = true ) : never {
131
+ const errorObject = this . getError ( error ) ;
127
132
128
133
if ( ! this . #started || this . #silent) {
129
134
throw errorObject ;
@@ -192,6 +197,12 @@ export class TaskTree {
192
197
return this ;
193
198
}
194
199
200
+ private getError ( error : string | Error | unknown ) : Error {
201
+ const obj = error instanceof Error ? error : new Error ( typeof error === 'string' ? error : '' ) ;
202
+
203
+ return obj ;
204
+ }
205
+
195
206
private log ( ) : void {
196
207
const offset = this . #offset;
197
208
0 commit comments