From 086916085691570c93785f63f6448107cd927da0 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Sun, 10 Jun 2018 13:19:06 +0700 Subject: [PATCH 1/5] [signale] Add typings for signale --- types/signale/index.d.ts | 134 +++++++++++++++++++++++++++++++++ types/signale/signale-tests.ts | 129 +++++++++++++++++++++++++++++++ types/signale/tsconfig.json | 23 ++++++ types/signale/tslint.json | 1 + 4 files changed, 287 insertions(+) create mode 100644 types/signale/index.d.ts create mode 100644 types/signale/signale-tests.ts create mode 100644 types/signale/tsconfig.json create mode 100644 types/signale/tslint.json diff --git a/types/signale/index.d.ts b/types/signale/index.d.ts new file mode 100644 index 0000000000..b9cca921a8 --- /dev/null +++ b/types/signale/index.d.ts @@ -0,0 +1,134 @@ +// Type definitions for signale 1.1 +// Project: https://github.com/klauscfhq/signale +// Definitions by: Resi Respati +// Kingdaro +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare namespace Signale { + type DefaultMethods = + | "await" + | "complete" + | "error" + | "debug" + | "fatal" + | "fav" + | "info" + | "note" + | "pause" + | "pending" + | "star" + | "start" + | "success" + | "warn" + | "watch" + | "log"; + + interface CommandType { + /** The icon corresponding to the logger. */ + badge: string; + /** + * The color of the label, can be any of the foreground colors supported by + * [chalk](https://github.com/chalk/chalk#colors). + */ + color: string; + /** The label used to identify the type of the logger. */ + label: string; + } + + interface SignaleConfig { + /** Display the scope name of the logger. */ + displayScope?: boolean; + /** Display the badge of the logger. */ + displayBadge?: boolean; + /** Display the current local date in `YYYY-MM-DD` format. */ + displayDate?: boolean; + /** Display the name of the file that the logger is reporting from. */ + displayFilename?: boolean; + /** Display the label of the logger. */ + displayLabel?: boolean; + /** Display the current local time in `HH:MM:SS` format. */ + displayTimestamp?: boolean; + /** Underline the logger label. */ + underlineLabel?: boolean; + /** Underline the logger message. */ + underlineMessage?: boolean; + } + + interface SignaleOptions { + /** Sets the configuration of an instance overriding any existing global or local configuration. */ + config?: SignaleConfig; + /** + * Name of the scope. + */ + scope?: string; + /** + * Holds the configuration of the custom and default loggers. + */ + types?: Partial>; + interactive?: boolean; + timers?: Map; + /** + * Destination to which the data is written, can be any valid + * [Writable stream](https://nodejs.org/api/stream.html#stream_writable_streams). + */ + stream?: NodeJS.WriteStream; + } + + interface SignaleConstructor { + new ( + options?: SignaleOptions + ): Signale; + } + + interface SignaleBase { + /** + * Sets the configuration of an instance overriding any existing global or local configuration. + * + * @param configObj Can hold any of the documented options. + */ + config(configObj: SignaleConfig): Signale; + /** + * Defines the scope name of the logger. + * + * @param name Can be one or more comma delimited strings. + */ + scope(...name: string[]): Signale; + /** Clears the scope name of the logger. */ + unscope(): void; + /** + * Sets a timers and accepts an optional label. If none provided the timer will receive a unique label automatically. + * + * @param label Label corresponding to the timer. Each timer must have its own unique label. + * @returns {string} a string corresponding to the timer label. + */ + time(label?: string): string; + /** + * Deactivates the timer to which the given label corresponds. If no label + * is provided the most recent timer, that was created without providing a + * label, will be deactivated. + * + * @param label Label corresponding to the timer, each timer has its own unique label. + * @param span Total running time. + */ + timeEnd( + label?: string, + span?: number + ): { label: string; span?: number }; + } + + type LoggerFunc = (message?: any, ...optionalArgs: any[]) => void; + type Signale = SignaleBase & + Record & + Record; +} + +declare const Signale: Signale.Signale & { + Signale: Signale.SignaleConstructor; + SignaleConfig: Signale.SignaleConfig; + SignaleOptions: Signale.SignaleOptions; + DefaultMethods: Signale.DefaultMethods; +}; +export = Signale; +export as namespace Signale; diff --git a/types/signale/signale-tests.ts b/types/signale/signale-tests.ts new file mode 100644 index 0000000000..9d4ab8fa27 --- /dev/null +++ b/types/signale/signale-tests.ts @@ -0,0 +1,129 @@ +/// + +import signale, { Signale, SignaleOptions } from "signale"; + +// --- Test 1: Basic Usage --- // + +signale.success("Operation successful"); +signale.debug("Hello", "from", "L59"); +signale.pending("Write release notes for 1.2.0"); +signale.fatal(new Error("Unable to acquire lock")); +signale.watch("Recursively watching build directory..."); +signale.complete({ + prefix: "[task]", + message: "Fix issue #59", + suffix: "(@klauscfhq)" +}); + +// --- Test 2: Custom Loggers --- // + +type CustomLogger = "remind" | "santa"; + +const optionsCustom: SignaleOptions = { + stream: process.stdout, + scope: "custom", + types: { + remind: { + badge: "**", + color: "yellow", + label: "reminder" + }, + santa: { + badge: "🎅", + color: "red", + label: "santa" + } + } +}; + +const custom = new Signale(optionsCustom); +custom.remind("Improve documentation."); +custom.santa("Hoho! You have an unused variable on L45."); +custom.debug("This should still work"); + +// --- Test 3: Overriding Default Loggers --- // + +const optionsOverride: SignaleOptions = { + types: { + error: { + badge: "!!", + color: "red", + label: "fatal error" + }, + success: { + badge: "++", + color: "green", + label: "huge success" + } + } +}; + +signale.error("Default Error Log"); +signale.success("Default Success Log"); + +const customOverride = new Signale(optionsOverride); +customOverride.error("Custom Error Log"); +customOverride.success("Custom Success Log"); + +// --- Test 4: Scoped Loggers --- // + +const optionsScope: SignaleOptions = { + scope: "global scope" +}; + +const global = new Signale(optionsScope); +global.success("Successful Operation"); + +const global2 = signale.scope("global scope"); +global2.success("Hello from the global scope"); + +function scopedTest() { + const outer = global2.scope("outer", "scope"); + outer.success("Hello from the outer scope"); + + setTimeout(() => { + const inner = outer.scope("inner", "scope"); + inner.success("Hello from the inner scope"); + }, 500); +} + +scopedTest(); + +// --- Test 5: Timers --- // + +signale.time("test"); +signale.time(); +signale.time(); + +setTimeout(() => { + signale.timeEnd(); + signale.timeEnd(); + signale.timeEnd("test"); +}, 500); + +// --- Test 6: Configuration --- // + +// Overrides any existing `package.json` config +signale.config({ + displayFilename: true, + displayTimestamp: true, + displayDate: false +}); + +signale.success("Hello from the Global scope"); + +function scopedConfigTest() { + // `fooLogger` inherits the config of `signale` + const fooLogger = signale.scope("foo scope"); + + // Overrides both `signale` and `package.json` configs + fooLogger.config({ + displayFilename: true, + displayTimestamp: false, + displayDate: true + }); + + fooLogger.success("Hello from the Local scope"); +} + +scopedConfigTest(); diff --git a/types/signale/tsconfig.json b/types/signale/tsconfig.json new file mode 100644 index 0000000000..172a154db7 --- /dev/null +++ b/types/signale/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "signale-tests.ts" + ] +} diff --git a/types/signale/tslint.json b/types/signale/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/signale/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 7ccf7974a6d4b3d0844bcda7ad6f51613da9c743 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Sun, 10 Jun 2018 13:24:13 +0700 Subject: [PATCH 2/5] [signale] added strictFunctionTypes in tsconfig, run dtslint --- types/signale/index.d.ts | 3 ++- types/signale/tsconfig.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/types/signale/index.d.ts b/types/signale/index.d.ts index b9cca921a8..4bca64397d 100644 --- a/types/signale/index.d.ts +++ b/types/signale/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Resi Respati // Kingdaro // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.7 /// @@ -101,7 +102,7 @@ declare namespace Signale { * Sets a timers and accepts an optional label. If none provided the timer will receive a unique label automatically. * * @param label Label corresponding to the timer. Each timer must have its own unique label. - * @returns {string} a string corresponding to the timer label. + * @returns a string corresponding to the timer label. */ time(label?: string): string; /** diff --git a/types/signale/tsconfig.json b/types/signale/tsconfig.json index 172a154db7..ef5b67d941 100644 --- a/types/signale/tsconfig.json +++ b/types/signale/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From bb008afbdb920b8974b83e32f1744001280e2c22 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Sun, 10 Jun 2018 13:32:28 +0700 Subject: [PATCH 3/5] [signale] remove unnecessary reference to node in tests --- types/signale/signale-tests.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/types/signale/signale-tests.ts b/types/signale/signale-tests.ts index 9d4ab8fa27..d4c867b018 100644 --- a/types/signale/signale-tests.ts +++ b/types/signale/signale-tests.ts @@ -1,5 +1,3 @@ -/// - import signale, { Signale, SignaleOptions } from "signale"; // --- Test 1: Basic Usage --- // From ff48240ce0f8a8ad49dff72880780dde64b66eb1 Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Mon, 11 Jun 2018 12:09:40 +0700 Subject: [PATCH 4/5] [signale] renamed Signale namespace, minor fixes to tests --- types/signale/index.d.ts | 18 ++++++++++-------- types/signale/signale-tests.ts | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/types/signale/index.d.ts b/types/signale/index.d.ts index 4bca64397d..8690a4dcef 100644 --- a/types/signale/index.d.ts +++ b/types/signale/index.d.ts @@ -2,12 +2,13 @@ // Project: https://github.com/klauscfhq/signale // Definitions by: Resi Respati // Kingdaro +// Joydip Roy // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.7 /// -declare namespace Signale { +declare namespace signale { type DefaultMethods = | "await" | "complete" @@ -125,11 +126,12 @@ declare namespace Signale { Record; } -declare const Signale: Signale.Signale & { - Signale: Signale.SignaleConstructor; - SignaleConfig: Signale.SignaleConfig; - SignaleOptions: Signale.SignaleOptions; - DefaultMethods: Signale.DefaultMethods; +declare const signale: signale.Signale & { + Signale: signale.SignaleConstructor; + SignaleConfig: signale.SignaleConfig; + SignaleOptions: signale.SignaleOptions; + DefaultMethods: signale.DefaultMethods; }; -export = Signale; -export as namespace Signale; + +export = signale; +export as namespace signale; diff --git a/types/signale/signale-tests.ts b/types/signale/signale-tests.ts index d4c867b018..7fd96638a8 100644 --- a/types/signale/signale-tests.ts +++ b/types/signale/signale-tests.ts @@ -1,7 +1,9 @@ -import signale, { Signale, SignaleOptions } from "signale"; +import { Signale, SignaleOptions } from "signale"; // --- Test 1: Basic Usage --- // +const signale = new Signale(); + signale.success("Operation successful"); signale.debug("Hello", "from", "L59"); signale.pending("Write release notes for 1.2.0"); From 6c9f3c8f96047621445db6357b7cea415ea2380c Mon Sep 17 00:00:00 2001 From: Resi Respati Date: Mon, 11 Jun 2018 15:29:45 +0700 Subject: [PATCH 5/5] [signale] remove `export as namespace` declaration No globals is exported, actually. --- types/signale/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/signale/index.d.ts b/types/signale/index.d.ts index 8690a4dcef..d14660e5a9 100644 --- a/types/signale/index.d.ts +++ b/types/signale/index.d.ts @@ -134,4 +134,3 @@ declare const signale: signale.Signale & { }; export = signale; -export as namespace signale;