Socket
Socket
Sign inDemoInstall

listr2

Package Overview
Dependencies
14
Maintainers
1
Versions
231
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.8 to 1.2.0

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# 20200303, v1.2.0
* Removed task manager options since it was making things complicated. It shall now be executed after each initiation.
# 20200302, v1.1.1

@@ -2,0 +5,0 @@ * Fixed time measuring.

29

dist/interfaces/manager.interface.d.ts

@@ -0,26 +1,17 @@

import { Listr } from '../listr';
import { ListrContext, ListrTask, ListrOptions } from './listr.interface';
export declare class ManagerClass<Ctx = ListrContext> {
constructor(options?: ManagerOptions);
addInitial<Ctx>(tasks: ListrTask<Ctx>[]): void;
add<Ctx>(tasks: ListrTask<Ctx>[]): void;
addFinal<Ctx>(tasks: ListrTask<Ctx>[]): void;
runAll<Ctx>(options?: Exclude<ListrOptions<Ctx>, {
export declare class ManagerClass<InjectCtx = ListrContext> {
constructor(options?: ManagerOptions, listrOptions?: ListrOptions<InjectCtx>);
add<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[]): void;
injectOptions<Ctx = InjectCtx>(options?: ManagerOptions, ListrOptions?: ListrOptions<Ctx>): void;
runAll<Ctx = InjectCtx>(options?: Exclude<ListrOptions<Ctx>, {
concurrent: any;
}>): Promise<Ctx>;
run<Ctx>(tasks: ListrTask<Ctx>[], options?: ListrOptions): Promise<Ctx>;
run<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[], options?: ListrOptions): Promise<Ctx>;
newListr<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[], options?: ListrOptions<Ctx>): Listr<Ctx>;
getRunTime(pipetime: number): string;
}
export interface ManagerInjectOptions<Ctx = ListrContext> {
initial?: Exclude<ListrOptions<Ctx>, {
concurrent: any;
}>;
parallel?: Exclude<ListrOptions<Ctx>, {
concurrent: any;
}>;
final?: Exclude<ListrOptions<Ctx>, {
concurrent: any;
}>;
}
export interface ManagerOptions {
export interface ManagerOptions<Ctx = ListrContext> {
showRunTime?: boolean;
listr: ListrOptions<Ctx>;
}

@@ -68,3 +68,3 @@ "use strict";

buffer += data;
const deleteMultiLineRegexp = new RegExp(/.*\u001b\[.*G.*/);
const deleteMultiLineRegexp = new RegExp(/.*(\u001b\[.*G|\u0007).*/m);
if (deleteMultiLineRegexp.test(buffer.toString())) {

@@ -71,0 +71,0 @@ buffer = Buffer.alloc(64);

import { ListrContext, ListrOptions, ListrTask } from './interfaces/listr.interface';
import { ManagerOptions, ManagerInjectOptions } from './interfaces/manager.interface';
import { ManagerOptions } from './interfaces/manager.interface';
import { Listr } from './listr';
export declare class Manager<InjectCtx = ListrContext> {
private options?;
private initially;
private initialOptions;
private listrOptions?;
private tasks;
private parallelOptions;
private finally;
private finalOptions;
constructor(options?: ManagerOptions);
addInitial<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[]): void;
constructor(options?: ManagerOptions, listrOptions?: ListrOptions<InjectCtx>);
add<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[]): void;
addFinal<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[]): void;
injectOptions(options: ManagerInjectOptions): void;
runAll<Ctx = InjectCtx>(options?: Exclude<ListrOptions, {
concurrent: any;
}>): Promise<Ctx>;
run<Ctx>(tasks: ListrTask<Ctx>[], options?: ListrOptions<Ctx>): Promise<Ctx>;
injectOptions<Ctx = InjectCtx>(options?: ManagerOptions, ListrOptions?: ListrOptions<Ctx>): void;
runAll<Ctx>(options?: ListrOptions<Ctx> & {
showRunTime?: boolean;
}): Promise<Ctx>;
newListr<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[], options?: ListrOptions<Ctx>): Listr<Ctx>;
run<Ctx = InjectCtx>(tasks: ListrTask<Ctx>[], options?: ListrOptions<Ctx>): Promise<Ctx>;
getRuntime(pipetime: number): string;
}

@@ -5,67 +5,39 @@ "use strict";

class Manager {
constructor(options) {
constructor(options, listrOptions) {
this.options = options;
this.initially = [];
this.listrOptions = listrOptions;
this.tasks = [];
this.finally = [];
this.options = Object.assign({ showRunTime: true }, this.options);
}
addInitial(tasks) {
this.initially = [...this.initially, ...tasks];
}
add(tasks) {
this.tasks = [...this.tasks, ...tasks];
}
addFinal(tasks) {
this.finally = [...this.finally, ...tasks];
}
injectOptions(options) {
if (options === null || options === void 0 ? void 0 : options.initial) {
this.initialOptions = options.initial;
injectOptions(options, ListrOptions) {
if (options) {
this.options = options;
}
if (options === null || options === void 0 ? void 0 : options.parallel) {
this.parallelOptions = options.parallel;
if (this.listrOptions) {
this.listrOptions = ListrOptions;
}
if (options === null || options === void 0 ? void 0 : options.final) {
this.finalOptions = options.final;
}
}
async runAll(options) {
let pipetime;
const managerTasks = [
{
enabled: () => this.initially.length > 0,
task: () => new listr_1.Listr(this.initially, this.initialOptions)
},
{
const pipetime = Date.now();
options = Object.assign({ showRuntime: true }, options);
const { showRunTime, ...listrOptions } = options;
const allOptions = Object.assign(this.options || {}, listrOptions);
return new listr_1.Listr([{
enabled: () => this.tasks.length > 0,
task: () => {
pipetime = Date.now();
return new listr_1.Listr(this.tasks, { concurrent: true, ...this.parallelOptions });
return new listr_1.Listr(this.tasks, listrOptions);
}
},
{
enabled: () => { var _a; return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.showRunTime) && (this.tasks.length > 0); },
enabled: () => showRunTime && (this.tasks.length > 0),
task: (ctx, task) => { task.title = `Parallel tasks are finished in ${this.getRuntime(pipetime)}.`; }
},
{
enabled: () => this.finally.length > 0,
task: () => new listr_1.Listr(this.finally, this.finalOptions)
},
{
task: () => {
this.initially = [];
this.initialOptions = {};
this.tasks = [];
this.parallelOptions = {};
this.finally = [];
this.finalOptions = {};
}
}
];
Object.assign(options || {}, { concurrent: false });
return this.run(managerTasks, options);
}], allOptions).run();
}
newListr(tasks, options) {
return new listr_1.Listr(tasks, options);
}
run(tasks, options) {
return new listr_1.Listr(tasks, options).run();
return this.newListr(tasks, options).run();
}

@@ -72,0 +44,0 @@ getRuntime(pipetime) {

{
"name": "listr2",
"version": "1.1.8",
"version": "1.2.0",
"description": "Terminal task list reborn!",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -70,27 +70,7 @@ Listr2

### Initial Tasks
* Initial tasks will be executed in order at the beginning.
* You can also inject your type through add initial interface if initiating it via defining a type is not possible. ```manager.addInitial<Ctx>([])```
### Add Tasks
```typescript
manager.addInitial([])
```
### Parallel Tasks
* This tasks will be run as async.
* If showRuntime option enabled while generating manager, it will show the run time of async part.
* You can also inject your type through add initial interface if initiating it via defining a type is not possible. ```manager.add<Ctx>([])```
```typescript
manager.add([])
```
### Final Tasks
* Final tasks will be executed in order at the end.
* You can also inject your type through add initial interface if initiating it via defining a type is not possible. ```manager.addFinal<Ctx>([])```
```typescript
manager.addFinal([])
```
### Run Tasks that are in Queue

@@ -100,3 +80,3 @@ * This will also return the context object back.

```typescript
const ctx = await manager.runAll()
const ctx = await manager.runAll<Ctx>({concurrent: true})
```

@@ -103,0 +83,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc