Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 4fa565c

Browse files
Use TypeScript 2.0
Update the TS related dependencies to use TS 2.0 and fix the errors from the update
1 parent a650ccc commit 4fa565c

10 files changed

+381
-90
lines changed

bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $injector.require("errors", "./errors");
1010
$injector.requirePublic("fs", "./file-system");
1111
$injector.require("sysInfoBase", "./sys-info-base");
1212
$injector.require("hostInfo", "./host-info");
13+
$injector.require("osInfo", "./os-info");
1314

1415
$injector.require("dispatcher", "./dispatchers");
1516
$injector.require("commandDispatcher", "./dispatchers");

declarations.d.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ interface Error {
704704
* Error's stack trace
705705
* @type {string}
706706
*/
707-
stack: string;
707+
stack?: string;
708708
/**
709709
* Error's code - could be a string ('ENOENT'), as well as a number (127)
710710
* @type {string|number}
@@ -1370,3 +1370,20 @@ interface IProxySettings {
13701370
*/
13711371
port: string;
13721372
}
1373+
1374+
/**
1375+
* Describes operating system-related utility methods
1376+
*/
1377+
interface IOsInfo {
1378+
/**
1379+
* Returns a string identifying the operating system name.
1380+
* @return {string} A string identifying the operating system name.
1381+
*/
1382+
type(): string;
1383+
1384+
/**
1385+
* Returns a string identifying the operating system release.
1386+
* @return {string} A string identifying the operating system release.
1387+
*/
1388+
release(): string;
1389+
}

definitions/prompt.d.ts

Lines changed: 287 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,295 @@
1+
// WARNING: There original definition file is modified in order to use the current prompter in the CLI.
2+
3+
// Type definitions for Inquirer.js
4+
// Project: https://github.com/SBoudrias/Inquirer.js
5+
// Definitions by: Qubo <https://github.com/tkQubo>
6+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7+
8+
type Prompts = { [name: string]: PromptModule };
9+
type ChoiceType = string | objects.ChoiceOption | objects.Separator;
10+
type Questions = IPromptSchema | IPromptSchema[];
11+
12+
interface Inquirer {
13+
restoreDefaultPrompts(): void;
14+
/**
15+
* Expose helper functions on the top level for easiest usage by common users
16+
* @param name
17+
* @param prompt
18+
*/
19+
registerPrompt(name: string, prompt: PromptModule): void;
20+
/**
21+
* Create a new self-contained prompt module.
22+
*/
23+
createPromptModule(): PromptModule;
24+
/**
25+
* Public CLI helper interface
26+
* @param questions Questions settings array
27+
* @param cb Callback being passed the user answers
28+
* @return
29+
*/
30+
prompt(questions: Questions, cb: (answers: Answers) => any): ui.Prompt;
31+
prompt(questions: Questions): Promise<Answers>;
32+
prompts: Prompts;
33+
Separator: objects.SeparatorStatic;
34+
ui: {
35+
BottomBar: ui.BottomBar;
36+
Prompt: ui.Prompt;
37+
}
38+
}
39+
40+
interface PromptModule {
41+
(questions: Questions, cb: (answers: Answers) => any): ui.Prompt;
42+
/**
43+
* Register a prompt type
44+
* @param name Prompt type name
45+
* @param prompt Prompt constructor
46+
*/
47+
registerPrompt(name: string, prompt: PromptModule): ui.Prompt;
48+
/**
49+
* Register the defaults provider prompts
50+
*/
51+
restoreDefaultPrompts(): void;
52+
}
53+
154
interface IPromptSchema {
2-
type: string;
3-
name: string;
4-
message: any;
5-
default?: any;
6-
choices?: any[];
7-
filter?: (userInput: any) => any;
8-
when?: (userAnswers: any) => boolean;
9-
validate?: (userInput: any) => string|boolean;
55+
/**
56+
* Type of the prompt.
57+
* Possible values:
58+
* <ul>
59+
* <li>input</li>
60+
* <li>confirm</li>
61+
* <li>list</li>
62+
* <li>rawlist</li>
63+
* <li>password</li>
64+
* </ul>
65+
* @defaults: 'input'
66+
*/
67+
type?: string;
68+
/**
69+
* The name to use when storing the answer in the anwers hash.
70+
*/
71+
name?: string;
72+
/**
73+
* The question to print. If defined as a function,
74+
* the first parameter will be the current inquirer session answers.
75+
*/
76+
message?: string | ((answers: Answers) => string);
77+
/**
78+
* Default value(s) to use if nothing is entered, or a function that returns the default value(s).
79+
* If defined as a function, the first parameter will be the current inquirer session answers.
80+
*/
81+
default?: any | ((answers: Answers) => any);
82+
/**
83+
* Choices array or a function returning a choices array. If defined as a function,
84+
* the first parameter will be the current inquirer session answers.
85+
* Array values can be simple strings, or objects containing a name (to display) and a value properties
86+
* (to save in the answers hash). Values can also be a Separator.
87+
*/
88+
choices?: ChoiceType[] | ((answers: Answers) => ChoiceType[]);
89+
/**
90+
* Receive the user input and should return true if the value is valid, and an error message (String)
91+
* otherwise. If false is returned, a default error message is provided.
92+
*/
93+
validate?(input: string): boolean | string;
94+
/**
95+
* Receive the user input and return the filtered value to be used inside the program.
96+
* The value returned will be added to the Answers hash.
97+
*/
98+
filter?(input: string): string;
99+
/**
100+
* Receive the current user answers hash and should return true or false depending on whether or
101+
* not this question should be asked. The value can also be a simple boolean.
102+
*/
103+
when?: boolean | ((answers: Answers) => boolean);
104+
paginated?: boolean;
10105
}
11106

12-
interface IPrompt {
13-
get(properties: IPromptSchema, action: (err: Error, result: any) => any): void;
14-
message: string;
15-
delimiter: string;
16-
colors: boolean;
17-
isDefaultValueEditable: boolean;
18-
prompt(properties: IPromptSchema[], callback: (err: Error, result: any) => any): IFuture<any>;
107+
/**
108+
* A key/value hash containing the client answers in each prompt.
109+
*/
110+
interface Answers {
111+
[key: string]: any;
19112
}
20113

21-
declare var cliPrompt: IPrompt;
114+
declare namespace ui {
115+
/**
116+
* Base interface class other can inherits from
117+
*/
118+
interface Prompt extends BaseUI<Prompts> {
119+
new (promptModule: Prompts): Prompt;
120+
/**
121+
* Once all prompt are over
122+
*/
123+
onCompletion(): void;
124+
processQuestion(question: IPromptSchema): any;
125+
fetchAnswer(question: IPromptSchema): any;
126+
setDefaultType(question: IPromptSchema): any;
127+
filterIfRunnable(question: IPromptSchema): any;
128+
}
129+
130+
/**
131+
* Sticky bottom bar user interface
132+
*/
133+
interface BottomBar extends BaseUI<BottomBarOption> {
134+
new (opt?: BottomBarOption): BottomBar;
135+
/**
136+
* Render the prompt to screen
137+
* @return self
138+
*/
139+
render(): BottomBar;
140+
/**
141+
* Update the bottom bar content and rerender
142+
* @param bottomBar Bottom bar content
143+
* @return self
144+
*/
145+
updateBottomBar(bottomBar: string): BottomBar;
146+
/**
147+
* Rerender the prompt
148+
* @return self
149+
*/
150+
writeLog(data: any): BottomBar;
151+
/**
152+
* Make sure line end on a line feed
153+
* @param str Input string
154+
* @return The input string with a final line feed
155+
*/
156+
enforceLF(str: string): string;
157+
/**
158+
* Helper for writing message in Prompt
159+
* @param message The message to be output
160+
*/
161+
write(message: string): void;
162+
log: NodeJS.ReadWriteStream;
163+
}
164+
165+
interface BottomBarOption {
166+
bottomBar?: string;
167+
}
168+
/**
169+
* Base interface class other can inherits from
170+
*/
171+
interface BaseUI<TOpt> {
172+
new (opt: TOpt): void;
173+
/**
174+
* Handle the ^C exit
175+
* @return {null}
176+
*/
177+
onForceClose(): void;
178+
/**
179+
* Close the interface and cleanup listeners
180+
*/
181+
close(): void;
182+
/**
183+
* Handle and propagate keypress events
184+
*/
185+
onKeypress(s: string, key: Key): void;
186+
}
187+
188+
interface Key {
189+
sequence: string;
190+
name: string;
191+
meta: boolean;
192+
shift: boolean;
193+
ctrl: boolean;
194+
}
195+
}
196+
197+
declare namespace objects {
198+
/**
199+
* Choice object
200+
* Normalize input as choice object
201+
* @constructor
202+
* @param {String|Object} val Choice value. If an object is passed, it should contains
203+
* at least one of `value` or `name` property
204+
*/
205+
interface Choice {
206+
new (str: string): Choice;
207+
new (separator: Separator): Choice;
208+
new (option: ChoiceOption): Choice;
209+
}
210+
211+
interface ChoiceOption {
212+
name?: string;
213+
value?: string;
214+
type?: string;
215+
extra?: any;
216+
key?: string;
217+
checked?: boolean;
218+
disabled?: string | ((answers: Answers) => any);
219+
}
220+
221+
/**
222+
* Choices collection
223+
* Collection of multiple `choice` object
224+
* @constructor
225+
* @param choices All `choice` to keep in the collection
226+
*/
227+
interface Choices {
228+
new (choices: (string | Separator | ChoiceOption)[], answers?: Answers): Choices;
229+
choices: Choice[];
230+
realChoices: Choice[];
231+
length: number;
232+
realLength: number;
233+
/**
234+
* Get a valid choice from the collection
235+
* @param selector The selected choice index
236+
* @return Return the matched choice or undefined
237+
*/
238+
getChoice(selector: number): Choice;
239+
/**
240+
* Get a raw element from the collection
241+
* @param selector The selected index value
242+
* @return Return the matched choice or undefined
243+
*/
244+
get(selector: number): Choice;
245+
/**
246+
* Match the valid choices against a where clause
247+
* @param whereClause Lodash `where` clause
248+
* @return Matching choices or empty array
249+
*/
250+
where<U extends {}>(whereClause: U): Choice[];
251+
/**
252+
* Pluck a particular key from the choices
253+
* @param propertyName Property name to select
254+
* @return Selected properties
255+
*/
256+
pluck(propertyName: string): any[];
257+
forEach<T>(application: (choice: Choice) => T): T[];
258+
}
259+
260+
interface SeparatorStatic {
261+
/**
262+
* @param line Separation line content (facultative)
263+
*/
264+
new (line?: string): Separator;
265+
/**
266+
* Helper function returning false if object is a separator
267+
* @param obj object to test against
268+
* @return `false` if object is a separator
269+
*/
270+
exclude(obj: any): boolean;
271+
}
272+
273+
/**
274+
* Separator object
275+
* Used to space/separate choices group
276+
* @constructor
277+
* @param {String} line Separation line content (facultative)
278+
*/
279+
interface Separator {
280+
type: string;
281+
line: string;
282+
/**
283+
* Stringify separator
284+
* @return {String} the separator display string
285+
*/
286+
toString(): string;
287+
}
288+
}
289+
290+
291+
declare var inquirer: Inquirer;
22292

23293
declare module "inquirer" {
24-
export = cliPrompt;
294+
export = inquirer;
25295
}

helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,3 @@ export function annotate(fn: any) {
385385
}
386386

387387
//--- end part copied from AngularJS
388-

os-info.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as os from "os";
2+
3+
export class OsInfo implements IOsInfo {
4+
public type(): string {
5+
return os.type();
6+
}
7+
8+
public release(): string {
9+
return os.release();
10+
}
11+
}
12+
13+
$injector.register("osInfo", OsInfo);

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@
7979
"grunt-contrib-clean": "1.0.0",
8080
"grunt-contrib-watch": "1.0.0",
8181
"grunt-shell": "1.3.0",
82-
"grunt-ts": "5.5.1",
83-
"grunt-tslint": "3.1.0",
82+
"grunt-ts": "6.0.0-beta.3",
83+
"grunt-tslint": "3.3.0",
8484
"istanbul": "0.3.17",
8585
"mocha": "2.5.3",
8686
"mocha-fibers": "1.1.1",
8787
"spec-xunit-file": "0.0.1-3",
88-
"tslint": "3.11.0",
89-
"typescript": "1.8.10"
88+
"tslint": "3.15.1",
89+
"typescript": "2.0.7"
9090
},
9191
"bundledDependencies": [],
9292
"license": "Apache-2.0",

0 commit comments

Comments
 (0)