Listr
listr2
is a stateful task list, therefore it is based on classes. To create a new task list, you must create an instance of Listr first.
Generate New Class
Import and create a new task list from the prototype. It will return the created Listr class.
ts
import { Listr } from 'listr2'
interface Ctx {
/* some variables for internal use */
}
const tasks = new Listr<Ctx>(
[
/* tasks */
],
{
/* options */
}
)
Run the Generated Task List
Then you can run this task list as an async
function and as the result, it will return the context through the tasks.
ts
try {
await tasks.run()
} catch (e) {
console.error(e)
}