mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
[console-ui] Add declarations for console-ui (#29343)
This commit is contained in:
committed by
Wesley Wigham
parent
9b1b3dbc5d
commit
b4529f27c1
60
types/console-ui/console-ui-tests.ts
Normal file
60
types/console-ui/console-ui-tests.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Question } from 'inquirer';
|
||||
import UI = require('console-ui');
|
||||
|
||||
new UI({
|
||||
inputStream: process.stdin,
|
||||
outputStream: process.stderr,
|
||||
errorStream: process.stdout,
|
||||
writeLevel: 'DEBUG',
|
||||
ci: false
|
||||
});
|
||||
|
||||
const ui = new UI();
|
||||
|
||||
ui.write(); // $ExpectError
|
||||
ui.write('hello');
|
||||
ui.write('hello', 'DEBUG');
|
||||
ui.write('hello', 'INFO');
|
||||
ui.write('hello', 'WARNING');
|
||||
ui.write('hello', 'ERROR');
|
||||
ui.write('hello', 'NONEXISTENT'); // $ExpectError
|
||||
|
||||
ui.writeLine(); // $ExpectError
|
||||
ui.writeLine('hello');
|
||||
ui.writeLine('hello', 'DEBUG');
|
||||
ui.writeLine('hello', 'INFO');
|
||||
ui.writeLine('hello', 'WARNING');
|
||||
ui.writeLine('hello', 'ERROR');
|
||||
ui.writeLine('hello', 'NONEXISTENT'); // $ExpectError
|
||||
|
||||
ui.writeDebugLine('hello');
|
||||
|
||||
ui.writeWarnLine('hello');
|
||||
ui.writeWarnLine('hello', true);
|
||||
ui.writeWarnLine('hello', false, true);
|
||||
|
||||
ui.writeDeprecateLine('hello');
|
||||
ui.writeDeprecateLine('hello', true);
|
||||
ui.writeDeprecateLine('hello', false, true);
|
||||
|
||||
ui.writeError(new Error('boom!'));
|
||||
ui.writeError('boom!'); // $ExpectError
|
||||
|
||||
ui.setWriteLevel('DEBUG');
|
||||
ui.setWriteLevel('INFO');
|
||||
ui.setWriteLevel('WARNING');
|
||||
ui.setWriteLevel('ERROR');
|
||||
ui.setWriteLevel('NONEXISTENT'); // $ExpectError
|
||||
|
||||
ui.startProgress('hello');
|
||||
ui.stopProgress();
|
||||
ui.stopProgress('hello'); // $ExpectError
|
||||
|
||||
const question: Question<{ answer: boolean }> = {
|
||||
message: 'Yes / No?',
|
||||
type: 'confirm'
|
||||
};
|
||||
|
||||
ui.prompt(question).then(result => {
|
||||
result.answer; // $ExpectType boolean
|
||||
});
|
||||
93
types/console-ui/index.d.ts
vendored
Normal file
93
types/console-ui/index.d.ts
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
// Type definitions for console-ui 2.2
|
||||
// Project: https://github.com/ember-cli/console-ui#readme
|
||||
// Definitions by: Dan Freeman <https://github.com/dfreeman>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { Readable, Writable } from 'stream';
|
||||
import { Questions } from 'inquirer';
|
||||
|
||||
type WriteLevel = 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
||||
|
||||
export = UI;
|
||||
|
||||
/**
|
||||
* The UI provides the CLI with a unified mechanism for providing output and
|
||||
* requesting input from the user. This becomes useful when wanting to adjust
|
||||
* logLevels, or mock input/output for tests.
|
||||
*/
|
||||
declare class UI {
|
||||
constructor(options?: {
|
||||
inputStream?: Readable;
|
||||
outputStream?: Writable;
|
||||
errorStream?: Writable;
|
||||
writeLevel?: WriteLevel;
|
||||
ci?: boolean;
|
||||
});
|
||||
|
||||
/**
|
||||
* Unified mechanism to write a string to the console.
|
||||
* Optionally include a writeLevel, this is used to decide if the specific
|
||||
* logging mechanism should or should not be printed.
|
||||
*/
|
||||
write(message: string, level?: WriteLevel): void;
|
||||
|
||||
/**
|
||||
* Unified mechanism to write a string and new line to the console.
|
||||
* Optionally include a writeLevel, this is used to decide if the specific
|
||||
* logging mechanism should or should not be printed.
|
||||
*/
|
||||
writeLine(message: string, level?: WriteLevel): void;
|
||||
|
||||
/**
|
||||
* Helper method to write a string with the DEBUG writeLevel and gray chalk
|
||||
*/
|
||||
writeDebugLine(message: string): void;
|
||||
|
||||
/**
|
||||
* Helper method to write a string with the INFO writeLevel and cyan chalk
|
||||
*/
|
||||
writeInfoLine(message: string): void;
|
||||
|
||||
/**
|
||||
* Helper method to write a string with the WARNING writeLevel and yellow chalk.
|
||||
* Optionally include a test. If falsy, the warning will be printed. By default, warnings
|
||||
* will be prepended with WARNING text when printed.
|
||||
*/
|
||||
writeWarnLine(message: string, test?: boolean, prepend?: boolean): void;
|
||||
|
||||
/**
|
||||
* Helper method to write a string with the WARNING writeLevel and yellow chalk.
|
||||
* Optionally include a test. If falsy, the deprecation will be printed. By default deprecations
|
||||
* will be prepended with DEPRECATION text when printed.
|
||||
*/
|
||||
writeDeprecateLine(message: string, test?: boolean, prepend?: boolean): void;
|
||||
|
||||
/**
|
||||
* Unified mechanism to an Error to the console.
|
||||
* This will occure at a writeLevel of ERROR
|
||||
*/
|
||||
writeError(error: object): void;
|
||||
|
||||
/**
|
||||
* Sets the write level for the UI. Valid write levels are 'DEBUG', 'INFO',
|
||||
* 'WARNING', and 'ERROR'.
|
||||
*/
|
||||
setWriteLevel(level: WriteLevel): void;
|
||||
|
||||
/**
|
||||
* Begins a progress spinner with a message (only if the INFO write level is visible).
|
||||
*/
|
||||
startProgress(message: string): void;
|
||||
|
||||
/**
|
||||
* Ends the current progress spinner.
|
||||
*/
|
||||
stopProgress(): void;
|
||||
|
||||
/**
|
||||
* Launch the prompt interface (inquiry session) with (Array of Questions || Question)
|
||||
* See [Inquirer.js#question](https://github.com/SBoudrias/Inquirer.js#question) for Question properties
|
||||
*/
|
||||
prompt<T>(questions: Questions<T>, callback?: (answers: T) => void): Promise<T>;
|
||||
}
|
||||
23
types/console-ui/tsconfig.json
Normal file
23
types/console-ui/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"console-ui-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/console-ui/tslint.json
Normal file
1
types/console-ui/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user