manager.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Manager = void 0;
  4. const listr_1 = require("./listr");
  5. class Manager {
  6. constructor(options) {
  7. this.options = options;
  8. this.err = [];
  9. this.tasks = [];
  10. }
  11. set ctx(ctx) {
  12. this.options.ctx = ctx;
  13. }
  14. add(tasks, options) {
  15. options = { ...this.options, ...options };
  16. this.tasks = [...this.tasks, this.indent(tasks, options)];
  17. }
  18. async runAll(options) {
  19. options = { ...this.options, ...options };
  20. const ctx = await this.run(this.tasks, options);
  21. this.tasks = [];
  22. return ctx;
  23. }
  24. newListr(tasks, options) {
  25. return new listr_1.Listr(tasks, options);
  26. }
  27. indent(tasks, options, taskOptions) {
  28. options = { ...this.options, ...options };
  29. let newTask;
  30. if (typeof tasks === 'function') {
  31. newTask = {
  32. ...taskOptions,
  33. task: (ctx) => this.newListr(tasks(ctx), options)
  34. };
  35. }
  36. else {
  37. newTask = {
  38. ...taskOptions,
  39. task: () => this.newListr(tasks, options)
  40. };
  41. }
  42. return newTask;
  43. }
  44. async run(tasks, options) {
  45. options = { ...this.options, ...options };
  46. const task = this.newListr(tasks, options);
  47. const ctx = await task.run();
  48. this.err = [];
  49. this.err = [...this.err, ...task.err];
  50. return ctx;
  51. }
  52. getRuntime(pipetime) {
  53. return `${Math.round(Date.now() - pipetime) / 1000}s`;
  54. }
  55. }
  56. exports.Manager = Manager;
  57. //# sourceMappingURL=manager.js.map