mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
add nssm
This commit is contained in:
parent
363cdf403a
commit
7f03fea2da
54
types/nssm/index.d.ts
vendored
Normal file
54
types/nssm/index.d.ts
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
// Type definitions for nssm 0.1
|
||||
// Project: https://github.com/alykoshin/nssm
|
||||
// Definitions by: Joram van den Boezem <https://github.com/hongaar>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
type Command =
|
||||
| 'install'
|
||||
| 'remove'
|
||||
| 'start'
|
||||
| 'stop'
|
||||
| 'restart'
|
||||
| 'status'
|
||||
| 'pause'
|
||||
| 'continue'
|
||||
| 'rotate'
|
||||
| 'get'
|
||||
| 'set'
|
||||
| 'reset'
|
||||
|
||||
type NssmThen<T> = <TResult1 = T, TResult2 = never>(
|
||||
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
|
||||
onrejected?: ((reason: Error, stderr: string) => TResult2 | PromiseLike<TResult2>) | null | undefined
|
||||
) => NssmPromise<TResult1 | TResult2>
|
||||
|
||||
type NssmCatch<T> = <TResult = never>(
|
||||
onrejected?: ((reason: Error, stderr: string) => TResult | PromiseLike<TResult>) | null | undefined
|
||||
) => NssmPromise<T | TResult>
|
||||
|
||||
interface NssmPromise<T> extends Promise<T> {
|
||||
then: NssmThen<T>
|
||||
catch: NssmCatch<T>
|
||||
}
|
||||
|
||||
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<string>
|
||||
|
||||
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
|
||||
50
types/nssm/nssm-tests.ts
Normal file
50
types/nssm/nssm-tests.ts
Normal file
@ -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 + '\'');
|
||||
});
|
||||
22
types/nssm/tsconfig.json
Normal file
22
types/nssm/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
1
types/nssm/tslint.json
Normal file
1
types/nssm/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user