From a6e94fdb0a80fbeacea1786d60cc0a67deaf9d6b Mon Sep 17 00:00:00 2001 From: Shun Date: Tue, 24 Jan 2017 21:54:20 -0800 Subject: [PATCH 1/4] Add module --- forever-monitor/forever-monitor-tests.ts | 0 forever-monitor/index.d.ts | 104 +++++++++++++++++++++++ forever-monitor/tsconfig.json | 20 +++++ forever-monitor/tslint.json | 1 + 4 files changed, 125 insertions(+) create mode 100644 forever-monitor/forever-monitor-tests.ts create mode 100644 forever-monitor/index.d.ts create mode 100644 forever-monitor/tsconfig.json create mode 100644 forever-monitor/tslint.json diff --git a/forever-monitor/forever-monitor-tests.ts b/forever-monitor/forever-monitor-tests.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/forever-monitor/index.d.ts b/forever-monitor/index.d.ts new file mode 100644 index 0000000000..b22905cae2 --- /dev/null +++ b/forever-monitor/index.d.ts @@ -0,0 +1,104 @@ +// Type definitions for forever-monitor 1.7 +// Project: https://github.com/nodejitsu/forever-monitor#readme +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + +interface spawnWith { + customFds: number[]; + setsid: boolean; + uid: number; + gid: number; +} + +interface parserArgs { + command: string; + args: string[]; +} + +interface Options { + silent?: boolean; + uid?: "autogen" | string; + pidFile?: string; + max?: number; + killTree?: boolean; + minUptime?: number; + spinSleepTime?: number; + command?: "node" | string; + args?: string[]; + sourceDir?: string; + watch?: boolean; + watchIgnoreDotFiles?: boolean; + watchIgnorePatters?: string[]; + watchDirectory?: string; + spawnWith?: spawnWith; + env?: { [envKey: string]: string; }; + cwd?: string; + logFile?: string; + outFile?: string; + errFile?: string; + parser?: (command: string, args: string[]) => { command: string, args: string[] }; +} + + +export declare class Monitor extends NodeJS.EventEmitter { + + /** + * @param script - Location of the target script to run. + * @param [options] - Configuration for this instance. + */ + constructor(script: string, options?: Options); + + /** + * @description Start the process that this instance is configured for + * @param [restart] - Value indicating whether this is a restart. + */ + public start(restart?: boolean): this; + + /** + * @description Tries to spawn the target Forever child process. + */ + public trySpawn(): boolean; + + /** + * @description Restarts the target script associated with this instance. + */ + public restart(): this; + + /** + * @description Stops the target script associated with this instance. Prevents it from auto-respawning + */ + public stop(): this; + + /** + * @description Kills the ChildProcess object associated with this instance + * @param [forceStop] - Value indicating whether short circuit forever auto-restart + */ + public kill(forceStop?: boolean): this; + + /** + * @description Sends a message to a forked ChildProcess object associated with this instance + */ + public send(msg?: any): this; + + /** + * respond with JSON for this instance + */ + public toString(): string; + + /** + * @param command - Command string to parse + * @param args - Additional default arguments + */ + public parseCommand(command: string, args?: string[]): (false | { command: string, args?: string[]}); +} + +interface forever { + Monitor: Monitor; + start: (script: string, options: Options) => Monitor; + kill: (pid: number, killTree?: boolean, signal?: string, callback?: () => any) => void; + checkProcess: (pid: number) => boolean; + version: string; +} + +export default forever; diff --git a/forever-monitor/tsconfig.json b/forever-monitor/tsconfig.json new file mode 100644 index 0000000000..8c6d4986b5 --- /dev/null +++ b/forever-monitor/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "forever-monitor-tests.ts" + ] +} diff --git a/forever-monitor/tslint.json b/forever-monitor/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/forever-monitor/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 748431211f8bc7306c1384f44f4b9bbe05222cee Mon Sep 17 00:00:00 2001 From: Shun Date: Wed, 25 Jan 2017 23:37:18 -0800 Subject: [PATCH 2/4] Add typing files for forever-monitor 1.7 --- forever-monitor/forever-monitor-tests.ts | 15 +++++++++++++++ forever-monitor/index.d.ts | 18 +++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/forever-monitor/forever-monitor-tests.ts b/forever-monitor/forever-monitor-tests.ts index e69de29bb2..f679c4704a 100644 --- a/forever-monitor/forever-monitor-tests.ts +++ b/forever-monitor/forever-monitor-tests.ts @@ -0,0 +1,15 @@ +// Test from https://github.com/foreverjs/forever-monitor + +import * as forever from "forever-monitor"; + +const child = new (forever.Monitor)('your-filename.js', { + max: 3, + silent: true, + args: [] +}); + +child.on('exit', function() { + console.log('your-filename.js has exited after 3 restarts'); +}); + +child.start(); diff --git a/forever-monitor/index.d.ts b/forever-monitor/index.d.ts index b22905cae2..58c32ec5e6 100644 --- a/forever-monitor/index.d.ts +++ b/forever-monitor/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for forever-monitor 1.7 // Project: https://github.com/nodejitsu/forever-monitor#readme -// Definitions by: My Self +// Definitions by: Shun Takahashi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -53,44 +53,44 @@ export declare class Monitor extends NodeJS.EventEmitter { * @description Start the process that this instance is configured for * @param [restart] - Value indicating whether this is a restart. */ - public start(restart?: boolean): this; + start(restart?: boolean): this; /** * @description Tries to spawn the target Forever child process. */ - public trySpawn(): boolean; + trySpawn(): boolean; /** * @description Restarts the target script associated with this instance. */ - public restart(): this; + restart(): this; /** * @description Stops the target script associated with this instance. Prevents it from auto-respawning */ - public stop(): this; + stop(): this; /** * @description Kills the ChildProcess object associated with this instance * @param [forceStop] - Value indicating whether short circuit forever auto-restart */ - public kill(forceStop?: boolean): this; + kill(forceStop?: boolean): this; /** * @description Sends a message to a forked ChildProcess object associated with this instance */ - public send(msg?: any): this; + send(msg?: any): this; /** * respond with JSON for this instance */ - public toString(): string; + toString(): string; /** * @param command - Command string to parse * @param args - Additional default arguments */ - public parseCommand(command: string, args?: string[]): (false | { command: string, args?: string[]}); + parseCommand(command: string, args?: string[]): (false | { command: string, args?: string[]}); } interface forever { From 42851a78ec22ffffc1c326178fb8880acf400472 Mon Sep 17 00:00:00 2001 From: Shun Date: Thu, 26 Jan 2017 20:13:31 -0800 Subject: [PATCH 3/4] Change typing structure to namespace basis --- forever-monitor/index.d.ts | 184 ++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 96 deletions(-) diff --git a/forever-monitor/index.d.ts b/forever-monitor/index.d.ts index 58c32ec5e6..d59c446f1a 100644 --- a/forever-monitor/index.d.ts +++ b/forever-monitor/index.d.ts @@ -4,101 +4,93 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -interface spawnWith { - customFds: number[]; - setsid: boolean; - uid: number; - gid: number; +declare namespace forever { + export interface SpawnWith { + customFds: number[]; + setsid: boolean; + uid: number; + gid: number; + } + + export interface Options { + silent?: boolean; + uid?: string; + pidFile?: string; + max?: number; + killTree?: boolean; + minUptime?: number; + spinSleepTime?: number; + command?: string; + args?: string[]; + sourceDir?: string; + watch?: boolean; + watchIgnoreDotFiles?: boolean; + watchIgnorePatters?: string[]; + watchDirectory?: string; + spawnWith?: SpawnWith; + env?: { [envKey: string]: string; }; + cwd?: string; + logFile?: string; + outFile?: string; + errFile?: string; + parser?: (command: string, args: string[]) => { command: string, args: string[] }; + } + + export function start(script: string, options: Options): Monitor; + export function kill(pid: number, killTree?: boolean, signal?: string, callback?: () => any): void; + export function checkProcess(pid: number): boolean; + export const version: string; + export class Monitor extends NodeJS.EventEmitter { + + /** + * @param script - Location of the target script to run. + * @param [options] - Configuration for this instance. + */ + constructor(script: string, options?: Options); + + /** + * @description Start the process that this instance is configured for + * @param [restart] - Value indicating whether this is a restart. + */ + start(restart?: boolean): this; + + /** + * @description Tries to spawn the target Forever child process. + */ + trySpawn(): boolean; + + /** + * @description Restarts the target script associated with this instance. + */ + restart(): this; + + /** + * @description Stops the target script associated with this instance. Prevents it from auto-respawning + */ + stop(): this; + + /** + * @description Kills the ChildProcess object associated with this instance + * @param [forceStop] - Value indicating whether short circuit forever auto-restart + */ + kill(forceStop?: boolean): this; + + /** + * @description Sends a message to a forked ChildProcess object associated with this instance + */ + send(msg?: any): this; + + /** + * respond with JSON for this instance + */ + toString(): string; + + /** + * @param command - Command string to parse + * @param args - Additional default arguments + */ + parseCommand(command: string, args?: string[]): (false | { command: string, args?: string[]}); + } } -interface parserArgs { - command: string; - args: string[]; -} - -interface Options { - silent?: boolean; - uid?: "autogen" | string; - pidFile?: string; - max?: number; - killTree?: boolean; - minUptime?: number; - spinSleepTime?: number; - command?: "node" | string; - args?: string[]; - sourceDir?: string; - watch?: boolean; - watchIgnoreDotFiles?: boolean; - watchIgnorePatters?: string[]; - watchDirectory?: string; - spawnWith?: spawnWith; - env?: { [envKey: string]: string; }; - cwd?: string; - logFile?: string; - outFile?: string; - errFile?: string; - parser?: (command: string, args: string[]) => { command: string, args: string[] }; -} - - -export declare class Monitor extends NodeJS.EventEmitter { - - /** - * @param script - Location of the target script to run. - * @param [options] - Configuration for this instance. - */ - constructor(script: string, options?: Options); - - /** - * @description Start the process that this instance is configured for - * @param [restart] - Value indicating whether this is a restart. - */ - start(restart?: boolean): this; - - /** - * @description Tries to spawn the target Forever child process. - */ - trySpawn(): boolean; - - /** - * @description Restarts the target script associated with this instance. - */ - restart(): this; - - /** - * @description Stops the target script associated with this instance. Prevents it from auto-respawning - */ - stop(): this; - - /** - * @description Kills the ChildProcess object associated with this instance - * @param [forceStop] - Value indicating whether short circuit forever auto-restart - */ - kill(forceStop?: boolean): this; - - /** - * @description Sends a message to a forked ChildProcess object associated with this instance - */ - send(msg?: any): this; - - /** - * respond with JSON for this instance - */ - toString(): string; - - /** - * @param command - Command string to parse - * @param args - Additional default arguments - */ - parseCommand(command: string, args?: string[]): (false | { command: string, args?: string[]}); -} - -interface forever { - Monitor: Monitor; - start: (script: string, options: Options) => Monitor; - kill: (pid: number, killTree?: boolean, signal?: string, callback?: () => any) => void; - checkProcess: (pid: number) => boolean; - version: string; -} - -export default forever; +export = forever; From c8b9d48923795415d222a38d73f3c15bfd2bd276 Mon Sep 17 00:00:00 2001 From: Shun Takahashi Date: Fri, 27 Jan 2017 10:03:54 -0800 Subject: [PATCH 4/4] Drop namespace and change to flat export model --- forever-monitor/forever-monitor-tests.ts | 10 +- forever-monitor/index.d.ts | 173 +++++++++++------------ 2 files changed, 94 insertions(+), 89 deletions(-) diff --git a/forever-monitor/forever-monitor-tests.ts b/forever-monitor/forever-monitor-tests.ts index f679c4704a..e44a9c35b0 100644 --- a/forever-monitor/forever-monitor-tests.ts +++ b/forever-monitor/forever-monitor-tests.ts @@ -1,6 +1,10 @@ // Test from https://github.com/foreverjs/forever-monitor import * as forever from "forever-monitor"; +forever.start('script') + .on("start", () => console.log("started")); + +forever.kill(10, true); const child = new (forever.Monitor)('your-filename.js', { max: 3, @@ -12,4 +16,8 @@ child.on('exit', function() { console.log('your-filename.js has exited after 3 restarts'); }); -child.start(); +child.start() + .on("start", () => console.log("started")) + .restart() + .stop() + .on("exit", () => console.log("STOPPED")) diff --git a/forever-monitor/index.d.ts b/forever-monitor/index.d.ts index d59c446f1a..22fa4b0c61 100644 --- a/forever-monitor/index.d.ts +++ b/forever-monitor/index.d.ts @@ -4,93 +4,90 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -declare namespace forever { - export interface SpawnWith { - customFds: number[]; - setsid: boolean; - uid: number; - gid: number; - } - - export interface Options { - silent?: boolean; - uid?: string; - pidFile?: string; - max?: number; - killTree?: boolean; - minUptime?: number; - spinSleepTime?: number; - command?: string; - args?: string[]; - sourceDir?: string; - watch?: boolean; - watchIgnoreDotFiles?: boolean; - watchIgnorePatters?: string[]; - watchDirectory?: string; - spawnWith?: SpawnWith; - env?: { [envKey: string]: string; }; - cwd?: string; - logFile?: string; - outFile?: string; - errFile?: string; - parser?: (command: string, args: string[]) => { command: string, args: string[] }; - } - - export function start(script: string, options: Options): Monitor; - export function kill(pid: number, killTree?: boolean, signal?: string, callback?: () => any): void; - export function checkProcess(pid: number): boolean; - export const version: string; - export class Monitor extends NodeJS.EventEmitter { - - /** - * @param script - Location of the target script to run. - * @param [options] - Configuration for this instance. - */ - constructor(script: string, options?: Options); - - /** - * @description Start the process that this instance is configured for - * @param [restart] - Value indicating whether this is a restart. - */ - start(restart?: boolean): this; - - /** - * @description Tries to spawn the target Forever child process. - */ - trySpawn(): boolean; - - /** - * @description Restarts the target script associated with this instance. - */ - restart(): this; - - /** - * @description Stops the target script associated with this instance. Prevents it from auto-respawning - */ - stop(): this; - - /** - * @description Kills the ChildProcess object associated with this instance - * @param [forceStop] - Value indicating whether short circuit forever auto-restart - */ - kill(forceStop?: boolean): this; - - /** - * @description Sends a message to a forked ChildProcess object associated with this instance - */ - send(msg?: any): this; - - /** - * respond with JSON for this instance - */ - toString(): string; - - /** - * @param command - Command string to parse - * @param args - Additional default arguments - */ - parseCommand(command: string, args?: string[]): (false | { command: string, args?: string[]}); - } +export interface SpawnWith { + customFds: number[]; + setsid: boolean; + uid: number; + gid: number; } -export = forever; +export interface Options { + silent?: boolean; + uid?: string; + pidFile?: string; + max?: number; + killTree?: boolean; + minUptime?: number; + spinSleepTime?: number; + command?: string; + args?: string[]; + sourceDir?: string; + watch?: boolean; + watchIgnoreDotFiles?: boolean; + watchIgnorePatters?: string[]; + watchDirectory?: string; + spawnWith?: SpawnWith; + env?: { [envKey: string]: string; }; + cwd?: string; + logFile?: string; + outFile?: string; + errFile?: string; + parser?: (command: string, args: string[]) => { command: string, args: string[] }; +} + +export function start(script: string, options?: Options): Monitor; +export function kill(pid: number, killTree?: boolean, signal?: string, callback?: () => any): void; +export function checkProcess(pid: number): boolean; +export const version: string; + +export class Monitor extends NodeJS.EventEmitter { + + /** + * @param script - Location of the target script to run. + * @param [options] - Configuration for this instance. + */ + constructor(script: string, options?: Options); + + /** + * @description Start the process that this instance is configured for + * @param [restart] - Value indicating whether this is a restart. + */ + start(restart?: boolean): this; + + /** + * @description Tries to spawn the target Forever child process. + */ + trySpawn(): boolean; + + /** + * @description Restarts the target script associated with this instance. + */ + restart(): this; + + /** + * @description Stops the target script associated with this instance. Prevents it from auto-respawning + */ + stop(): this; + + /** + * @description Kills the ChildProcess object associated with this instance + * @param [forceStop] - Value indicating whether short circuit forever auto-restart + */ + kill(forceStop?: boolean): this; + + /** + * @description Sends a message to a forked ChildProcess object associated with this instance + */ + send(msg?: any): this; + + /** + * respond with JSON for this instance + */ + toString(): string; + + /** + * @param command - Command string to parse + * @param args - Additional default arguments + */ + parseCommand(command: string, args?: string[]): (false | { command: string, args?: string[]}); +}