diff --git a/dist/index.d.ts b/dist/index.d.ts index ccdff1e..54a4f17 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,5 +1,6 @@ export declare class SmartDebug { private _debugEnabled; + constructor(debugTopic?: string); readonly debugEnabled: boolean; /** * enables debugging output diff --git a/dist/index.js b/dist/index.js index 58960e4..2e17092 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,8 +1,12 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class SmartDebug { - constructor() { + constructor(debugTopic) { this._debugEnabled = false; + if (process.env.SMARTDEBUG === 'true' || + (debugTopic && process.env.SMARTDEBUG_TOPIC === debugTopic)) { + this.enableDebugging(); + } } get debugEnabled() { return this._debugEnabled; @@ -11,6 +15,7 @@ class SmartDebug { * enables debugging output */ enableDebugging() { + console.log('Enabled Debugging!'); this._debugEnabled = true; } /** @@ -36,4 +41,4 @@ class SmartDebug { } } exports.SmartDebug = SmartDebug; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBO0lBQUE7UUFDVSxrQkFBYSxHQUFZLEtBQUssQ0FBQztJQW1DekMsQ0FBQztJQWxDQyxJQUFJLFlBQVk7UUFDZCxPQUFPLElBQUksQ0FBQyxhQUFhLENBQUM7SUFDNUIsQ0FBQztJQUVEOztPQUVHO0lBQ0ksZUFBZTtRQUNwQixJQUFJLENBQUMsYUFBYSxHQUFHLElBQUksQ0FBQztJQUM1QixDQUFDO0lBRUQ7O09BRUc7SUFDSSxnQkFBZ0I7UUFDckIsSUFBSSxDQUFDLGFBQWEsR0FBRyxLQUFLLENBQUM7SUFDN0IsQ0FBQztJQUVEOztPQUVHO0lBQ0ksR0FBRyxDQUFDLFNBQWM7UUFDdkIsSUFBSSxJQUFJLENBQUMsYUFBYSxFQU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DdEIsc0NBQXNDO1lBQ3RDLE9BQU8sQ0FBQyxHQUFHLENBQUMsU0FBUyxDQUFDLENBQUM7U0FDeEI7SUFDSCxDQUFDO0lBRUQ7O09BRUc7SUFDSSxXQUFXO1FBQ2hCLE9BQU8sSUFBSSxDQUFDLGFBQWEsQ0FBQztJQUM1QixDQUFDO0NBQ0Y7QUEvQ0QsZ0NBK0NDIn0= \ No newline at end of file diff --git a/readme.md b/readme.md index fc871ea..6c6f496 100644 --- a/readme.md +++ b/readme.md @@ -1,13 +1,16 @@ # smartdebug + debug the smart way ## Availabililty + [![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/@pushrocks/smartdebug) [![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartdebug) [![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartdebug) [![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartdebug/) ## Status for master + [![build status](https://GitLab.com/pushrocks/smartdebug/badges/master/build.svg)](https://GitLab.com/pushrocks/smartdebug/commits/master) [![coverage report](https://GitLab.com/pushrocks/smartdebug/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartdebug/commits/master) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartdebug.svg)](https://www.npmjs.com/package/@pushrocks/smartdebug) @@ -19,23 +22,24 @@ debug the smart way [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) ## Usage + Use TypeScript for best in class instellisense. ```typescript import * as smartdebug from '@pushrocks/smartdebug'; -smartdebug.log('a cool message') // won't log +smartdebug.log('a cool message'); // won't log smartdebug.enableDebugging(); -smartdebug.log('another cool message') // this message will log +smartdebug.log('another cool message'); // this message will log -if(smartdebug.debugEnabled) { - console.log('Hi there!') // will also log since debugging is enabled +if (smartdebug.debugEnabled) { + console.log('Hi there!'); // will also log since debugging is enabled } ``` For further information read the linked docs at the top of this README. -> licensed | **©** [Lossless GmbH](https://lossless.gmbh) -| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) +> 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://push.rocks) diff --git a/test/test.ts b/test/test.ts index 7bf39b9..68ed224 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,3 +1,4 @@ +// tslint:disable-next-line:no-implicit-dependencies import { expect, tap } from 'tapbundle'; import * as smartdebug from '../ts/index'; diff --git a/ts/index.ts b/ts/index.ts index 00cac52..ffd4426 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -2,7 +2,17 @@ import * as plugins from './smartdebug.plugins'; export class SmartDebug { private _debugEnabled: boolean = false; - get debugEnabled () { + + constructor(debugTopic?: string) { + if ( + process.env.SMARTDEBUG === 'true' || + (debugTopic && process.env.SMARTDEBUG_TOPIC === debugTopic) + ) { + this.enableDebugging(); + } + } + + get debugEnabled() { return this._debugEnabled; } @@ -10,6 +20,7 @@ export class SmartDebug { * enables debugging output */ public enableDebugging() { + console.log('Enabled Debugging!'); this._debugEnabled = true; } @@ -31,7 +42,7 @@ export class SmartDebug { } /** - * a function returning + * a function returning */ public isDebugMode() { return this._debugEnabled; diff --git a/ts/smartdebug.plugins.ts b/ts/smartdebug.plugins.ts index 8cec2e9..cb0ff5c 100644 --- a/ts/smartdebug.plugins.ts +++ b/ts/smartdebug.plugins.ts @@ -1 +1 @@ -export {}; \ No newline at end of file +export {};