From ebd3517511fe6252993f48b9481f7b602ec9ce17 Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Thu, 10 May 2018 17:05:31 +0200 Subject: [PATCH] WSH definitions --- types/windows-script-host/index.d.ts | 201 ++++++++++++++++++ types/windows-script-host/package.json | 6 + types/windows-script-host/tsconfig.json | 23 ++ types/windows-script-host/tslint.json | 1 + .../windows-script-host-tests.ts | 1 + 5 files changed, 232 insertions(+) create mode 100644 types/windows-script-host/index.d.ts create mode 100644 types/windows-script-host/package.json create mode 100644 types/windows-script-host/tsconfig.json create mode 100644 types/windows-script-host/tslint.json create mode 100644 types/windows-script-host/windows-script-host-tests.ts diff --git a/types/windows-script-host/index.d.ts b/types/windows-script-host/index.d.ts new file mode 100644 index 0000000000..2130ecc805 --- /dev/null +++ b/types/windows-script-host/index.d.ts @@ -0,0 +1,201 @@ +// Type definitions for Windows Script Host 5.8 +// Project: https://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx +// Definitions by: Zev Spitz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// tslint:disable-next-line interface-name +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. + */ + 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 TextStreamWriter extends TextStreamBase { + /** + * 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 TextStreamReader extends TextStreamBase { + /** + * Returns a specified number of characters from an input stream, starting 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.exe). + */ + Echo(s: any): void; + + /** + * Exposes the write-only error output stream for the current script. + * Can be accessed only while using CScript.exe. + */ + StdErr: TextStreamWriter; + + /** + * Exposes the write-only output stream for the current script. + * Can be accessed only while using CScript.exe. + */ + StdOut: TextStreamWriter; + 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: TextStreamReader; + + /** + * 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; +}; + +/** + * WSH is an alias for WScript under Windows Script Host + */ +declare var WSH: typeof WScript; diff --git a/types/windows-script-host/package.json b/types/windows-script-host/package.json new file mode 100644 index 0000000000..731af0072b --- /dev/null +++ b/types/windows-script-host/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "activex-interop": "*" + } +} \ No newline at end of file diff --git a/types/windows-script-host/tsconfig.json b/types/windows-script-host/tsconfig.json new file mode 100644 index 0000000000..d53dad8a20 --- /dev/null +++ b/types/windows-script-host/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "windows-script-host-tests.ts" + ] +} diff --git a/types/windows-script-host/tslint.json b/types/windows-script-host/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/windows-script-host/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/windows-script-host/windows-script-host-tests.ts b/types/windows-script-host/windows-script-host-tests.ts new file mode 100644 index 0000000000..7bd4e876b5 --- /dev/null +++ b/types/windows-script-host/windows-script-host-tests.ts @@ -0,0 +1 @@ +WScript.Echo(WScript.Arguments.length);