diff --git a/types/nssm/index.d.ts b/types/nssm/index.d.ts new file mode 100644 index 0000000000..09ca82e6a0 --- /dev/null +++ b/types/nssm/index.d.ts @@ -0,0 +1,54 @@ +// Type definitions for nssm 0.1 +// Project: https://github.com/alykoshin/nssm +// Definitions by: Joram van den Boezem +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type Command = + | 'install' + | 'remove' + | 'start' + | 'stop' + | 'restart' + | 'status' + | 'pause' + | 'continue' + | 'rotate' + | 'get' + | 'set' + | 'reset' + +type NssmThen = ( + onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, + onrejected?: ((reason: Error, stderr: string) => TResult2 | PromiseLike) | null | undefined +) => NssmPromise + +type NssmCatch = ( + onrejected?: ((reason: Error, stderr: string) => TResult | PromiseLike) | null | undefined +) => NssmPromise + +interface NssmPromise extends Promise { + then: NssmThen + catch: NssmCatch +} + +type CallbackFn = (error?: string, result?: string) => void +type ZeroArgCommandFn = (callback: CallbackFn) => void +type OneArgCommandFn = (arg1: string, callback: CallbackFn) => void +type TwoArgCommandFn = (arg1: string, arg2: string, callback: CallbackFn) => void +type PromiseCommandFn = (arg1?: string, arg2?: string) => NssmPromise + +type NssmCommandFn = + & ZeroArgCommandFn + & OneArgCommandFn + & TwoArgCommandFn + & PromiseCommandFn + +export type Nssm = { + [key in Command]: NssmCommandFn +} + +export interface NssmOptions { + nssmExe?: string +} + +export default function nssm (serviceName: string, options?: NssmOptions): Nssm diff --git a/types/nssm/nssm-tests.ts b/types/nssm/nssm-tests.ts new file mode 100644 index 0000000000..73733d91b7 --- /dev/null +++ b/types/nssm/nssm-tests.ts @@ -0,0 +1,50 @@ +// https://github.com/alykoshin/nssm/blob/master/examples/promise_chain.js + +import nssm from 'nssm' + +const svcName = 'test'; +const options = { nssmExe: 'nssm.exe' }; +const testService = nssm(svcName, options); + +const propertyName = 'Start'; + +let console: { + log: (...message: any[]) => void +}; + +testService.set('start', 'manual') + .then(function(stdout) { + console.log('\n*** Parameter set ok'); + console.log('stdout: \'' + stdout + '\''); + return testService.get('start') + }) + .then(function(stdout) { + console.log('\n*** Parameter retrieved ok'); + console.log('stdout: \'' + stdout + '\''); + return testService.start() + }) + .then(function(stdout) { + console.log('\n*** Service started ok'); + console.log('stdout: \'' + stdout + '\''); + return testService.stop() + }) + .then(function(stdout) { + console.log('\n*** Service stopped ok'); + console.log('stdout: \'' + stdout + '\''); + console.log('DONE'); + }) + .catch(function(error) { + console.log('\n*** catch(): error:', error); + console.log('ERROR:', error); + }) + ; + +// https://github.com/alykoshin/nssm/blob/master/examples/get_callback.js + +testService.get(propertyName, function(error, result) { + if (error) { + console.log('error:', error, ' stderr:', result); + return; + } + console.log('stdout: \'' + result + '\''); +}); diff --git a/types/nssm/tsconfig.json b/types/nssm/tsconfig.json new file mode 100644 index 0000000000..831eba6f50 --- /dev/null +++ b/types/nssm/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "nssm-tests.ts" + ] +} diff --git a/types/nssm/tslint.json b/types/nssm/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/nssm/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }