diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8321aed..1c84099 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -109,10 +109,10 @@ pages: image: hosttoday/ht-docker-node:npmci stage: metadata script: - - npmci command npm install -g typedoc typescript + - npmci command npm install -g @gitzone/tsdoc - npmci npm prepare - npmci npm install - - npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ + - npmci command tsdoc tags: - docker - notpriv diff --git a/npmextra.json b/npmextra.json index 270df81..28c7cb1 100644 --- a/npmextra.json +++ b/npmextra.json @@ -14,4 +14,4 @@ "npmGlobalTools": [], "npmAccessLevel": "public" } -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4227078..83a0b44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -107,7 +107,6 @@ "version": "3.0.5", "resolved": "https://verdaccio.lossless.one/@pushrocks%2flik/-/lik-3.0.5.tgz", "integrity": "sha512-pc5Nq0WUysS34qPpyiZXiX254kL3vyRVbt3D36Q5QU+eHhxAThHofSzgOdyVHUZU2WFoaMlKowIVsyUFzIkfdw==", - "dev": true, "requires": { "@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartpromise": "^2.0.5", @@ -121,8 +120,7 @@ "@pushrocks/smartpromise": { "version": "2.0.5", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz", - "integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==", - "dev": true + "integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==" } } }, @@ -153,7 +151,6 @@ "version": "2.0.3", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.3.tgz", "integrity": "sha512-TXKDDqsc7sBTLl+oiYNaF6IdNk1n70i8ur8QfwcUU6tegTnrEkvMWy9h5Zdty/fq1ioCNpKLvuXoA+fgYVwKGQ==", - "dev": true, "requires": { "@pushrocks/smartpromise": "^3.0.2" } @@ -162,7 +159,6 @@ "version": "2.0.3", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartevent/-/smartevent-2.0.3.tgz", "integrity": "sha512-x4B1mzzE6LrMATXsRLNuZpMTlB2JodL44MA4bF4FucU3SBBiWhFv3CFJRlO9B23SKZ1fwdJQrk2lT7YTUHXXJQ==", - "dev": true, "requires": { "@pushrocks/smartpromise": "^2.0.5" }, @@ -170,8 +166,7 @@ "@pushrocks/smartpromise": { "version": "2.0.5", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz", - "integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==", - "dev": true + "integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==" } } }, @@ -235,8 +230,7 @@ "@pushrocks/smartpromise": { "version": "3.0.2", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz", - "integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ==", - "dev": true + "integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ==" }, "@pushrocks/smartrequest": { "version": "1.1.15", @@ -253,7 +247,6 @@ "version": "2.0.3", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrx/-/smartrx-2.0.3.tgz", "integrity": "sha512-OWxagu+CBdPaq76AIg91hJyrNhDTlEpesj01ooWCeVIaLY3G7yvFkqHsEKNOwPUG1LzCWmjq1l1dHQx9p2vJ9A==", - "dev": true, "requires": { "@pushrocks/lik": "^3.0.2", "@pushrocks/smartevent": "^2.0.3", @@ -264,8 +257,7 @@ "@pushrocks/smartpromise": { "version": "2.0.5", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz", - "integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==", - "dev": true + "integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==" } } }, @@ -284,7 +276,6 @@ "version": "3.0.7", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmarttime/-/smarttime-3.0.7.tgz", "integrity": "sha512-IL/+lgVQLvZvoMSbOpT3JSGjogGzpNbWdzfFZAjjxrTtwxAN1FNWGcCESCvq1BPlUGECPTBeyyaURXhhhLfihA==", - "dev": true, "requires": { "@pushrocks/smartpromise": "^3.0.2", "@types/cron": "^1.7.0", @@ -334,7 +325,6 @@ "version": "1.7.1", "resolved": "https://verdaccio.lossless.one/@types%2fcron/-/cron-1.7.1.tgz", "integrity": "sha512-48brwgU18DqA0mQX1As5OcJEo1yNjaXMM6Mk4r8K1dOzLJRQ37FE/kCivKx7ClKEHfhX2FdcxKzJ1B744a+V3A==", - "dev": true, "requires": { "@types/node": "*", "moment": ">=2.14.0" @@ -367,20 +357,17 @@ "@types/luxon": { "version": "1.13.0", "resolved": "https://verdaccio.lossless.one/@types%2fluxon/-/luxon-1.13.0.tgz", - "integrity": "sha512-XmDiRVoJWgVdqX9x1a/GU4p9bSgZY7q8SOyMLs3fx1AdQcxLYAPIt/jfZm2e+PBVRWuEx1FqYNJ37kBZ53TMqA==", - "dev": true + "integrity": "sha512-XmDiRVoJWgVdqX9x1a/GU4p9bSgZY7q8SOyMLs3fx1AdQcxLYAPIt/jfZm2e+PBVRWuEx1FqYNJ37kBZ53TMqA==" }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://verdaccio.lossless.one/@types%2fminimatch/-/minimatch-3.0.3.tgz", - "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", - "dev": true + "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==" }, "@types/node": { - "version": "10.14.6", - "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-10.14.6.tgz", - "integrity": "sha512-Fvm24+u85lGmV4hT5G++aht2C5I4Z4dYlWZIh62FAfFO/TfzXtPpoLI6I7AuBWkIFqZCnhFOoTT7RjjaIL5Fjg==", - "dev": true + "version": "12.0.2", + "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.0.2.tgz", + "integrity": "sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==" }, "@types/vinyl": { "version": "2.0.3", @@ -454,8 +441,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://verdaccio.lossless.one/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "bindings": { "version": "1.5.0", @@ -470,7 +456,6 @@ "version": "1.1.11", "resolved": "https://verdaccio.lossless.one/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -619,8 +604,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://verdaccio.lossless.one/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "core-util-is": { "version": "1.0.2", @@ -632,7 +616,6 @@ "version": "1.7.1", "resolved": "https://verdaccio.lossless.one/cron/-/cron-1.7.1.tgz", "integrity": "sha512-gmMB/pJcqUVs/NklR1sCGlNYM7TizEw+1gebz20BMc/8bTm/r7QUp3ZPSPlG8Z5XRlvb7qhjEjq/+bdIfUCL2A==", - "dev": true, "requires": { "moment-timezone": "^0.5.x" } @@ -957,8 +940,7 @@ "luxon": { "version": "1.13.2", "resolved": "https://verdaccio.lossless.one/luxon/-/luxon-1.13.2.tgz", - "integrity": "sha512-U7i2AE+/VWeB8PZZkIeEcxJCZvBA8LegCHufaIFYx3qRQdw2UJw3fuaL/Fqi9Q+2MeFYu+gYqIzr5hWOvAMHBQ==", - "dev": true + "integrity": "sha512-U7i2AE+/VWeB8PZZkIeEcxJCZvBA8LegCHufaIFYx3qRQdw2UJw3fuaL/Fqi9Q+2MeFYu+gYqIzr5hWOvAMHBQ==" }, "make-error": { "version": "1.3.5", @@ -1011,7 +993,6 @@ "version": "3.0.4", "resolved": "https://verdaccio.lossless.one/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1042,14 +1023,12 @@ "moment": { "version": "2.24.0", "resolved": "https://verdaccio.lossless.one/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==", - "dev": true + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" }, "moment-timezone": { "version": "0.5.25", "resolved": "https://verdaccio.lossless.one/moment-timezone/-/moment-timezone-0.5.25.tgz", "integrity": "sha512-DgEaTyN/z0HFaVcVbSyVCUU6HeFdnNC3vE4c9cgu2dgMTvjBUBdBzWfasTBmAW45u5OIMeCJtU8yNjM22DHucw==", - "dev": true, "requires": { "moment": ">= 2.9.0" } @@ -1253,7 +1232,6 @@ "version": "6.5.2", "resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.5.2.tgz", "integrity": "sha512-HUb7j3kvb7p7eCUHE3FqjoDsC1xfZQ4AHFWfTKSpZ+sAhhz5X1WX0ZuUqWbzB2QhSLp3DoLUG+hMdEDKqWo2Zg==", - "dev": true, "requires": { "tslib": "^1.9.0" } @@ -1407,8 +1385,7 @@ "symbol-tree": { "version": "3.2.2", "resolved": "https://verdaccio.lossless.one/symbol-tree/-/symbol-tree-3.2.2.tgz", - "integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=", - "dev": true + "integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=" }, "ts-node": { "version": "8.1.0", @@ -1426,8 +1403,7 @@ "tslib": { "version": "1.9.3", "resolved": "https://verdaccio.lossless.one/tslib/-/tslib-1.9.3.tgz", - "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", - "dev": true + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" }, "tslint": { "version": "5.16.0", diff --git a/package.json b/package.json index 6f01b40..997fbaf 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,11 @@ "@gitzone/tsbuild": "^2.0.22", "@gitzone/tstest": "^1.0.15", "@pushrocks/tapbundle": "^3.0.7", - "@types/node": "^10.11.7", + "@types/node": "^12.0.2", "tslint": "^5.11.0", "tslint-config-prettier": "^1.15.0" }, - "dependencies": {} + "dependencies": { + "@pushrocks/lik": "^3.0.5" + } } diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..3aa23f6 --- /dev/null +++ b/readme.md @@ -0,0 +1,26 @@ +# @pushrocks/smartexit +do things before one exists a process + +## Availabililty and Links +* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartexit) +* [gitlab.com (source)](https://gitlab.com/pushrocks/smartexit) +* [github.com (source mirror)](https://github.com/pushrocks/smartexit) +* [docs (typedoc)](https://pushrocks.gitlab.io/smartexit/) + +## Status for master +[![build status](https://gitlab.com/pushrocks/smartexit/badges/master/build.svg)](https://gitlab.com/pushrocks/smartexit/commits/master) +[![coverage report](https://gitlab.com/pushrocks/smartexit/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartexit/commits/master) +[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartexit.svg)](https://www.npmjs.com/package/@pushrocks/smartexit) +[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartexit/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartexit) +[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) +[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) +[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) + +## Usage + +For further information read the linked docs at the top of this readme. + +> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) +| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) + +[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) diff --git a/test/test.ts b/test/test.ts index 33d208e..3c2da5c 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,12 @@ import { expect, tap } from '@pushrocks/tapbundle'; -import * as smartexit from '../ts/index' +import * as smartexit from '../ts/index'; tap.test('first test', async () => { - console.log(smartexit.standardExport) -}) + smartexit; +}); -tap.start() +tap.test('should end processes upon SIGINT', async tools => { + await tools.delayFor(5000); +}); + +tap.start(); diff --git a/ts/index.ts b/ts/index.ts index 46a2ba3..e63129a 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1,40 @@ import * as plugins from './smartexit.plugins'; -export let standardExport = 'Hi there! :) This is an exported string'; +export class SmartExit { + public static processesToEnd = new plugins.lik.Objectmap(); + public static async addProcess(childProcessArg: plugins.childProcess.ChildProcess) { + SmartExit.processesToEnd.add(childProcessArg); + } + + public static async killAll() { + console.log('Checking for remaining child processes before exit...'); + if (this.processesToEnd.getArray().length > 0) { + console.log('found remaining child processes'); + let counter = 1; + SmartExit.processesToEnd.forEach(async childProcessArg => { + console.log(`killing process #${counter}`); + childProcessArg.kill('SIGINT'); + counter++; + }); + } else { + console.log(`Everything looks clean. Ready to exit!`); + } + } +} + +// do app specific cleaning before exiting +process.on('exit', async () => { + await SmartExit.killAll(); +}); + +// catch ctrl+c event and exit normally +process.on('SIGINT', async () => { + console.log('Ctrl-C...'); + await SmartExit.killAll(); +}); + +//catch uncaught exceptions, trace, then exit normally +process.on('uncaughtException', async err => { + console.log('Ctrl-C...'); + await SmartExit.killAll(); +}); diff --git a/ts/smartexit.plugins.ts b/ts/smartexit.plugins.ts index d00ae0c..6ad743d 100644 --- a/ts/smartexit.plugins.ts +++ b/ts/smartexit.plugins.ts @@ -1,4 +1,9 @@ -const removeme = {}; -export { - removeme -} +// node native +import * as childProcess from 'child_process'; + +export { childProcess }; + +// pushrocks scope +import * as lik from '@pushrocks/lik'; + +export { lik };