From c8b9d48923795415d222a38d73f3c15bfd2bd276 Mon Sep 17 00:00:00 2001 From: Shun Takahashi Date: Fri, 27 Jan 2017 10:03:54 -0800 Subject: [PATCH] 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[]}); +}