Files
jsowell-charger-web/jsowell-ui/node_modules/listr2/dist/manager.js
Lemon f5e6e29f00 Merge branch 'dev-zza' into dev
# Conflicts:
#	jsowell-ui/.env.development
#	jsowell-ui/.env.staging
#	jsowell-ui/bin/build-sit.bat
#	jsowell-ui/bin/build.bat
#	jsowell-ui/src/api/adapayMember/adapayMember.js
#	jsowell-ui/src/api/pile/merchant.js
#	jsowell-ui/src/router/index.js
#	jsowell-ui/src/views/financial/financeDetail.vue
#	jsowell-ui/src/views/financial/merchant.vue
#	jsowell-ui/src/views/homeIndex/homeIndex.vue
#	jsowell-ui/src/views/login.vue
#	jsowell-ui/src/views/pile/basic/detail.vue
#	jsowell-ui/src/views/pile/station/components/SiteInfo.vue
#	jsowell-ui/src/views/pile/station/detail.vue
#	jsowell-ui/src/views/pile/station/orderReport.vue
2025-06-03 14:26:37 +08:00

68 lines
1.9 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Manager = void 0;
const listr_1 = require("./listr");
/**
* Creates a new Listr2 task manager.
*
* Useful for creating a single instace of Listr2 with pre-set settings.
*/
class Manager {
constructor(options) {
this.options = options;
this.err = [];
this.tasks = [];
}
set ctx(ctx) {
this.options.ctx = ctx;
}
add(tasks, options) {
options = { ...this.options, ...options };
this.tasks = [...this.tasks, this.indent(tasks, options)];
}
async runAll(options) {
options = { ...this.options, ...options };
const ctx = await this.run(this.tasks, options);
// clear out queues
this.tasks = [];
return ctx;
}
newListr(tasks, options) {
return new listr_1.Listr(tasks, options);
}
indent(tasks, options, taskOptions) {
options = { ...this.options, ...options };
let newTask;
// type function or directly
if (typeof tasks === 'function') {
newTask = {
...taskOptions,
task: (ctx) => this.newListr(tasks(ctx), options)
};
}
else {
newTask = {
...taskOptions,
task: () => this.newListr(tasks, options)
};
}
return newTask;
}
async run(tasks, options) {
options = { ...this.options, ...options };
// create task
const task = this.newListr(tasks, options);
// run task
const ctx = await task.run();
// reset error queue
this.err = task.err;
return ctx;
}
// general utils
/* istanbul ignore next */
getRuntime(pipetime) {
return `${Math.round(Date.now() - pipetime) / 1000}s`;
}
}
exports.Manager = Manager;