From d53e0c2ac2c0655cb656b02c774684bd52c5072b Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 12:59:50 +0300 Subject: [PATCH 1/4] Added properties/methods for WScript - https://msdn.microsoft.com/en-us/library/2795740w(v=vs.84).aspx per #2540 --- src/lib/scriptHost.d.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index bfa562a9300dd..ec5d5cca57aa3 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -10,10 +10,26 @@ interface ActiveXObject { } declare var ActiveXObject: ActiveXObject; -interface ITextWriter { +interface ITextStreamBase { + Column: number; + Line: number; + Close(): void; +} + +interface ITextWriter extends ITextStreamBase { Write(s: string): void; + WriteBlankLines(intLines: number): void; WriteLine(s: string): void; - Close(): void; +} + +interface ITextReader extends ITextStreamBase { + Read(characters: number): string; + ReadAll(): string; + ReadLine(): string; + Skip(characters: number): void; + SkipLine(): void; + AtEndOfLine: boolean; + AtEndOfStream: boolean; } declare var WScript: { @@ -23,4 +39,17 @@ declare var WScript: { Arguments: { length: number; Item(n: number): string; }; ScriptFullName: string; Quit(exitCode?: number): number; + BuildVersion: number; + FullName: string; + Interactive: boolean; + Name: string; + Path: string; + ScriptName: string; + StdIn: ITextReader; + Version: string; + ConnectObject(objEventSource: any, strPrefix: string): void; + CreateObject(strProgID: string, strPrefix?: string): any; + DisconnectObject(obj: any): void; + GetObject(strPathname: string, strProgID?: string, strPrefix?: string): any; + Sleep(intTime: number): void; } From 41547dc2f26d5fc6583ff8c9a53cd0541b56338e Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 14:09:43 +0300 Subject: [PATCH 2/4] JSDoc for WScript members --- src/lib/scriptHost.d.ts | 111 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index ec5d5cca57aa3..9f7b773b318b6 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -11,45 +11,156 @@ interface ActiveXObject { declare var ActiveXObject: ActiveXObject; interface ITextStreamBase { + /** + * The column number of the current character position in an input stream. + */ Column: number; + /** + * The current line number in an input stream. + */ Line: number; + /** + * Closes a text stream. + * It is not necessary to close standard streams; they close automatically when the process ends. If you close a standard stream, be aware that any other pointers to that standard stream become invalid. + */ Close(): void; } interface ITextWriter extends ITextStreamBase { + /** + * Sends a string to an output stream. + */ Write(s: string): void; + /** + * Sends a specified number of blank lines (newline characters) to an output stream. + */ WriteBlankLines(intLines: number): void; + /** + * Sends a string followed by a newline character to an output stream. + */ WriteLine(s: string): void; } interface ITextReader extends ITextStreamBase { + /** + * Returns a specified number of characters from an input stream, beginning at the current pointer position. + * Does not return until the ENTER key is pressed. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + */ Read(characters: number): string; + /** + * Returns all characters from an input stream. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + */ ReadAll(): string; + /** + * Returns an entire line from an input stream. + * Although this method extracts the newline character, it does not add it to the returned string. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + */ ReadLine(): string; + /** + * Skips a specified number of characters when reading from an input text stream. + * Can only be used on a stream in reading mode; causes an error in writing or appending mode. + * @param characters Positive number of characters to skip forward. (Backward skipping is not supported.) + */ Skip(characters: number): void; + /** + * Skips the next line when reading from an input text stream. + * Can only be used on a stream in reading mode, not writing or appending mode. + */ SkipLine(): void; + /** + * Indicates whether the stream pointer position is at the end of a line. + */ AtEndOfLine: boolean; + /** + * Indicates whether the stream pointer position is at the end of a stream. + */ AtEndOfStream: boolean; } declare var WScript: { + /** + * Outputs text to either a message box (under WScript.exe) or the command console window followed by a newline (under CScript.ext). + */ Echo(s: any): void; + /** + * Exposes the write-only error output stream for the current script. + * Can be accessed only while using CScript.exe. + */ StdErr: ITextWriter; + /** + * Exposes the write-only output stream for the current script. + * Can be accessed only while using CScript.exe. + */ StdOut: ITextWriter; Arguments: { length: number; Item(n: number): string; }; + /** + * The full path of the currently running script. + */ ScriptFullName: string; + /** + * Forces the script to stop immediately, with an optional exit code. + */ Quit(exitCode?: number): number; + /** + * The Windows Script Host build version number. + */ BuildVersion: number; + /** + * Fully qualified path of the host executable. + */ FullName: string; + /** + * Gets/sets the script mode - interactive(true) or batch(false). + */ Interactive: boolean; + /** + * The name of the host executable (WScript.exe or CScript.exe). + */ Name: string; + /** + * Path of the directory containing the host executable. + */ Path: string; + /** + * The filename of the currently running script. + */ ScriptName: string; + /** + * Exposes the read-only input stream for the current script. + * Can be accessed only while using CScript.exe. + */ StdIn: ITextReader; + /** + * Windows Script Host version + */ Version: string; + /** + * Connects a COM object's event sources to functions named with a given prefix, in the form prefix_event. + */ ConnectObject(objEventSource: any, strPrefix: string): void; + /** + * Creates a COM object. + * @param strProgiID + * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events. + */ CreateObject(strProgID: string, strPrefix?: string): any; + /** + * Disconnects a COM object from its event sources. + */ DisconnectObject(obj: any): void; + /** + * Retrieves an existing object with the specified ProgID from memory, or creates a new one from a file. + * @param strPathname Fully qualified path to the file containing the object persisted to disk. For objects in memory, pass a zero-length string. + * @param strProgID + * @param strPrefix Function names in the form prefix_event will be bound to this object's COM events. + */ GetObject(strPathname: string, strProgID?: string, strPrefix?: string): any; + /** + * Suspends script execution for a specified length of time, then continues execution. + * @param intTime Interval (in milliseconds) to suspend script execution. + */ Sleep(intTime: number): void; } From b06e19bee86bd1049c92ed1bf8cae30e14c24766 Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 14:43:10 +0300 Subject: [PATCH 3/4] Missing ; --- src/lib/scriptHost.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index 9f7b773b318b6..eaf3cfc2d9968 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -82,8 +82,8 @@ interface ITextReader extends ITextStreamBase { declare var WScript: { /** - * Outputs text to either a message box (under WScript.exe) or the command console window followed by a newline (under CScript.ext). - */ + * Outputs text to either a message box (under WScript.exe) or the command console window followed by a newline (under CScript.ext). + */ Echo(s: any): void; /** * Exposes the write-only error output stream for the current script. @@ -163,4 +163,4 @@ declare var WScript: { * @param intTime Interval (in milliseconds) to suspend script execution. */ Sleep(intTime: number): void; -} +}; From 7890a6894c5ada8ac3582538748d4f53c7804d2b Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Tue, 31 Mar 2015 16:56:30 +0300 Subject: [PATCH 4/4] Nre TextStreamWriter interface with JSDoc and additional members (ITextWriter is being used by the compiler and cannot be safely modified).. --- src/lib/scriptHost.d.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib/scriptHost.d.ts b/src/lib/scriptHost.d.ts index eaf3cfc2d9968..decf813bc2d45 100644 --- a/src/lib/scriptHost.d.ts +++ b/src/lib/scriptHost.d.ts @@ -10,7 +10,13 @@ interface ActiveXObject { } declare var ActiveXObject: ActiveXObject; -interface ITextStreamBase { +interface ITextWriter { + Write(s: string): void; + WriteLine(s: string): void; + Close(): void; +} + +interface TextStreamBase { /** * The column number of the current character position in an input stream. */ @@ -26,7 +32,7 @@ interface ITextStreamBase { Close(): void; } -interface ITextWriter extends ITextStreamBase { +interface TextStreamWriter extends TextStreamBase { /** * Sends a string to an output stream. */ @@ -41,7 +47,7 @@ interface ITextWriter extends ITextStreamBase { WriteLine(s: string): void; } -interface ITextReader extends ITextStreamBase { +interface TextStreamReader extends TextStreamBase { /** * Returns a specified number of characters from an input stream, beginning at the current pointer position. * Does not return until the ENTER key is pressed. @@ -89,12 +95,12 @@ declare var WScript: { * Exposes the write-only error output stream for the current script. * Can be accessed only while using CScript.exe. */ - StdErr: ITextWriter; + StdErr: TextStreamWriter; /** * Exposes the write-only output stream for the current script. * Can be accessed only while using CScript.exe. */ - StdOut: ITextWriter; + StdOut: TextStreamWriter; Arguments: { length: number; Item(n: number): string; }; /** * The full path of the currently running script. @@ -132,7 +138,7 @@ declare var WScript: { * Exposes the read-only input stream for the current script. * Can be accessed only while using CScript.exe. */ - StdIn: ITextReader; + StdIn: TextStreamReader; /** * Windows Script Host version */