mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Merge pull request #24047 from durad/master
Added type definitions for listr module
This commit is contained in:
commit
cbee400a4b
48
types/listr/index.d.ts
vendored
Normal file
48
types/listr/index.d.ts
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
// Type definitions for listr 0.13
|
||||
// Project: https://github.com/samverschueren/listr#readme
|
||||
// Definitions by: Dusan Radovanovic <https://github.com/durad>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as stream from "stream";
|
||||
|
||||
declare namespace Listr {
|
||||
interface ListrRenderer {
|
||||
nonTTY: boolean;
|
||||
render(): void;
|
||||
end(): void;
|
||||
}
|
||||
|
||||
interface ListrOptions {
|
||||
concurrent?: boolean | number;
|
||||
exitOnError?: boolean;
|
||||
renderer?: "silent" | "default" | "verbose" | ListrRenderer;
|
||||
nonTTYRenderer?: "silent" | "default" | "verbose" | ListrRenderer;
|
||||
}
|
||||
|
||||
interface ListrTask {
|
||||
title: string;
|
||||
output?: string;
|
||||
task: (ctx: any, task: ListrTaskWrapper) => void | string | Promise<any> | stream.Readable | Listr;
|
||||
skip?: (ctx: any, task: ListrTaskWrapper) => boolean | Promise<boolean> | string | void;
|
||||
enabled?: (ctx: any, task: ListrTaskWrapper) => boolean | Promise<boolean>;
|
||||
}
|
||||
|
||||
interface ListrTaskWrapper {
|
||||
title: string;
|
||||
output: any;
|
||||
report(error: Error): void;
|
||||
skip(message: string): void;
|
||||
run(ctx?: any): Promise<any>;
|
||||
}
|
||||
}
|
||||
|
||||
declare class Listr {
|
||||
constructor(tasks?: ReadonlyArray<Listr.ListrTask>, options?: Listr.ListrOptions);
|
||||
constructor(options?: Listr.ListrOptions);
|
||||
add(tasks: Listr.ListrTask | ReadonlyArray<Listr.ListrTask>): void;
|
||||
run(ctx?: any): Promise<any>;
|
||||
}
|
||||
|
||||
export = Listr;
|
||||
167
types/listr/listr-tests.ts
Normal file
167
types/listr/listr-tests.ts
Normal file
@ -0,0 +1,167 @@
|
||||
import * as Listr from "listr";
|
||||
import * as fs from "fs";
|
||||
|
||||
const tasks = new Listr([
|
||||
{
|
||||
title: 'Git',
|
||||
task: () => {
|
||||
return new Listr([
|
||||
{
|
||||
title: 'Checking git status',
|
||||
task: () => new Promise(resolve => resolve())
|
||||
.then(result => {
|
||||
if (result !== '') {
|
||||
throw new Error('Unclean working tree. Commit or stash changes first.');
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Checking remote history',
|
||||
task: () => new Promise(resolve => resolve())
|
||||
.then(result => {
|
||||
if (result !== '0') {
|
||||
throw new Error('Remote history differ. Please pull changes.');
|
||||
}
|
||||
})
|
||||
}
|
||||
],
|
||||
{ concurrent: true });
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Install package dependencies with Yarn',
|
||||
task: (ctx, task) => new Promise(resolve => resolve())
|
||||
.catch(() => {
|
||||
ctx.yarn = false;
|
||||
|
||||
task.skip('Yarn not available, install it via `npm install -g yarn`');
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Install package dependencies with npm',
|
||||
enabled: ctx => ctx.yarn === false,
|
||||
task: () => new Promise(resolve => resolve())
|
||||
},
|
||||
{
|
||||
title: 'Run tests',
|
||||
task: () => new Promise(resolve => resolve())
|
||||
},
|
||||
{
|
||||
title: 'Publish package',
|
||||
task: () => new Promise(resolve => resolve())
|
||||
}
|
||||
]);
|
||||
|
||||
tasks.run().catch(err => {
|
||||
});
|
||||
|
||||
const tasks21 = new Listr([
|
||||
{
|
||||
title: 'Success',
|
||||
task: () => 'Foo'
|
||||
},
|
||||
{
|
||||
title: 'Failure',
|
||||
task: () => {
|
||||
throw new Error('Bar');
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
const taskA: Listr.ListrTask = {
|
||||
title: 'Success',
|
||||
task: () => 'Foo'
|
||||
};
|
||||
|
||||
const taskB: Listr.ListrTask = {
|
||||
title: 'Failure',
|
||||
task: () => {
|
||||
throw new Error('Bar');
|
||||
}
|
||||
};
|
||||
|
||||
const tasks22 = new Listr([taskA, taskB]);
|
||||
|
||||
const tasks3 = new Listr([
|
||||
{
|
||||
title: 'Success',
|
||||
task: () => Promise.resolve('Foo')
|
||||
},
|
||||
{
|
||||
title: 'Failure',
|
||||
task: () => Promise.reject(new Error('Bar'))
|
||||
}
|
||||
]);
|
||||
|
||||
const tasks4 = new Listr([
|
||||
{
|
||||
title: 'File',
|
||||
task: () => fs.createReadStream('data.txt', 'utf8')
|
||||
}
|
||||
]);
|
||||
|
||||
const tasks5 = new Listr([
|
||||
{
|
||||
title: 'Task 1',
|
||||
task: () => Promise.resolve('Foo')
|
||||
},
|
||||
{
|
||||
title: 'Can be skipped',
|
||||
skip: () => {
|
||||
if (Math.random() > 0.5) {
|
||||
return 'Reason for skipping';
|
||||
}
|
||||
},
|
||||
task: () => 'Bar'
|
||||
},
|
||||
{
|
||||
title: 'Task 3',
|
||||
task: () => Promise.resolve('Bar')
|
||||
}
|
||||
]);
|
||||
|
||||
const tasks6 = new Listr([
|
||||
{
|
||||
title: 'Install package dependencies with Yarn',
|
||||
task: (ctx, task) => new Promise(resolve => resolve())
|
||||
.catch(() => {
|
||||
ctx.yarn = false;
|
||||
|
||||
task.skip('Yarn not available, install it via `npm install -g yarn`');
|
||||
})
|
||||
},
|
||||
{
|
||||
title: 'Install package dependencies with npm',
|
||||
enabled: ctx => ctx.yarn === false,
|
||||
task: () => new Promise(resolve => resolve())
|
||||
}
|
||||
]);
|
||||
|
||||
const tasks7 = new Listr([
|
||||
{
|
||||
title: 'Task 1',
|
||||
skip: ctx => ctx.foo === 'bar',
|
||||
task: () => Promise.resolve('Foo')
|
||||
},
|
||||
{
|
||||
title: 'Can be skipped',
|
||||
skip: () => {
|
||||
if (Math.random() > 0.5) {
|
||||
return 'Reason for skipping';
|
||||
}
|
||||
},
|
||||
task: ctx => {
|
||||
ctx.unicorn = 'rainbow';
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Task 3',
|
||||
task: ctx => Promise.resolve(`${ctx.foo} ${ctx.bar}`)
|
||||
}
|
||||
]);
|
||||
|
||||
tasks.run({
|
||||
foo: 'bar'
|
||||
}).then(ctx => {
|
||||
console.log(ctx);
|
||||
});
|
||||
24
types/listr/tsconfig.json
Normal file
24
types/listr/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"listr-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/listr/tslint.json
Normal file
1
types/listr/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user