@node-cli/logger 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,11 @@
11
11
  > npm install --save-dev @node-cli/logger
12
12
  ```
13
13
 
14
+ 2 classes are available:
15
+
16
+ - `Logger` which is a facade for `console` and with added methods, such as `printBox()`
17
+ - `Spinner` is an "elegant terminal spinner", relying behind the scenes on the excellent [ora](https://github.com/sindresorhus/ora)
18
+
14
19
  ## Usage
15
20
 
16
21
  ```js
@@ -22,9 +27,37 @@ log.warn("this is a warning log");
22
27
  log.error("this is an error log");
23
28
  ```
24
29
 
30
+ ```js
31
+ import { Spinner } from "@node-cli/logger";
32
+ const spinner = new Spinner("Updating package.json...");
33
+
34
+ // assuming a long running process here...
35
+ spinner.text = "Git stage and commit, please wait...";
36
+ // assuming a long running process here...
37
+ spinner.text = "Almost there...";
38
+ // assuming a long running process here... returning some result
39
+ if (result === "success") {
40
+ spinner.stop("Process completed successfully!");
41
+ } else {
42
+ spinner.stop("Process failed miserably...", Spinner.ERROR);
43
+ }
44
+ ```
45
+
25
46
  ## API
26
47
 
27
- ### Methods
48
+ ### Spinner methods
49
+
50
+ | Method | Arguments | Description |
51
+ | ----------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52
+ | constructor | options | Initialize a Spinner instance with [ora](https://github.com/sindresorhus/ora) options |
53
+ | start | text | Starts the spinner on the terminal and append a string to it |
54
+ | stop | text, status | Stop the spinner, change it to a green, red, yellow or blue marker, and persist the current text, or text if provided. The argument `status` can be one of `Spinner.SUCCESS`, `Spinner.ERROR`, `Spinner.WARNING` or `Spinner.INFO` |
55
+
56
+ | Setter | Description |
57
+ | ------ | ----------------------------------------------------------------------------------- |
58
+ | text | Set the text of the spinner. If the spinner is stopped, the text will be persisted. |
59
+
60
+ ### Logger methods
28
61
 
29
62
  Logger relies on `console` behind the scenes, and therefore supports the same [string substitution](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions) capabilities and uses the following methods:
30
63
 
@@ -35,6 +68,7 @@ Logger relies on `console` behind the scenes, and therefore supports the same [s
35
68
  | info | Informative logging of information. | blue |
36
69
  | warn | Outputs a message to the console with the log level debug | yellow |
37
70
  | error | Outputs an error message. | red |
71
+ | printBox | Output message(s) in a box | custom |
38
72
  | printErrorsAndExit | Output error message(s) and exit | red |
39
73
 
40
74
  ### Options
@@ -153,6 +187,52 @@ log.timestamp = false;
153
187
  log.info("this will be NOT be logged with a timestamp");
154
188
  ```
155
189
 
190
+ ### Log one or more messages in a box
191
+
192
+ The `printBox` method is a wrapper around the excellent [Boxen](https://github.com/sindresorhus/boxen), with sensible defaults.
193
+
194
+ ```js
195
+ import { Logger } from "@node-cli/logger";
196
+ const log = new Logger();
197
+
198
+ log.printBox(["Message One!", "Message Two!"]);
199
+
200
+ ┌──────────────────┐
201
+ │ │
202
+ │ Message One! │
203
+ │ Message Two! │
204
+ │ │
205
+ └──────────────────┘
206
+
207
+ ```
208
+
209
+ `printBox` accepts the following options as a second argument:
210
+
211
+ - `printLineAfter` (default to `true`)
212
+ - `printLineBefore` (default to `true`)
213
+ - As well as all the options available with [Boxen](https://github.com/sindresorhus/boxen)
214
+
215
+ Here is a custom example with:
216
+
217
+ - a red border color
218
+ - no extra line after the box
219
+ - no padding (no space between the border and the text)
220
+ - text is justified to the right
221
+ - there is a title injected at the top of the box
222
+
223
+ ```js
224
+ import { Logger } from "@node-cli/logger";
225
+ const log = new Logger();
226
+
227
+ log.printBox(["Message One!", "Message Two!"], {
228
+ borderColor: "red",
229
+ newLineAfter: false,
230
+ padding: 0,
231
+ textAlignment: "right",
232
+ title: "Hello World Box Title",
233
+ });
234
+ ```
235
+
156
236
  ### Log multiple errors and optionally exit the main program
157
237
 
158
238
  The following will print 2 error messages and exit with error code 666.
package/dist/Logger.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Options as BoxenOptions } from "boxen";
2
+ import { Ora, Options as OraOptions } from "ora";
2
3
  export type PrintBoxOptions = {
3
4
  newLineAfter?: boolean;
4
5
  newLineBefore?: boolean;
@@ -33,3 +34,14 @@ export declare class Logger {
33
34
  */
34
35
  printBox(messages: string | string[], options?: PrintBoxOptions): void;
35
36
  }
37
+ export declare class Spinner {
38
+ spinner: Ora;
39
+ constructor(options?: OraOptions);
40
+ set text(message: string);
41
+ start(message?: string): void;
42
+ stop(message?: string, type?: string): void;
43
+ static SUCCESS: string;
44
+ static ERROR: string;
45
+ static WARNING: string;
46
+ static INFO: string;
47
+ }
package/dist/Logger.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import boxen from "boxen";
2
- import kleur from "kleur";
2
+ import ora from "ora";
3
3
  import util from "node:util";
4
+ import kleur from "kleur";
4
5
  export class Logger {
5
6
  #shouldLog;
6
7
  #globalPrefix;
@@ -43,6 +44,7 @@ export class Logger {
43
44
  }
44
45
  message = util.formatWithOptions(this.#printOptions, prefix.join(" "), ...arguments_);
45
46
  }
47
+ // eslint-disable-next-line no-console
46
48
  console[type.method](this.#printOptions.colors ? `${type.color(message)}` : message);
47
49
  }
48
50
  }
@@ -123,5 +125,50 @@ export class Logger {
123
125
  this.#globalPrefix = oldPrefix;
124
126
  }
125
127
  }
128
+ /* istanbul ignore next */ export class Spinner {
129
+ spinner;
130
+ constructor(options){
131
+ this.spinner = ora({
132
+ ...options,
133
+ isSilent: process.env.NODE_ENV === "test"
134
+ });
135
+ }
136
+ set text(message) {
137
+ this.spinner.text = message;
138
+ }
139
+ start(message) {
140
+ this.spinner.start(message);
141
+ }
142
+ stop(message, type) {
143
+ switch(type){
144
+ case Spinner.ERROR:
145
+ {
146
+ this.spinner.fail(message);
147
+ break;
148
+ }
149
+ case Spinner.WARNING:
150
+ {
151
+ this.spinner.warn(message);
152
+ break;
153
+ }
154
+ case Spinner.INFO:
155
+ {
156
+ this.spinner.info(message);
157
+ break;
158
+ }
159
+ default:
160
+ {
161
+ setTimeout(()=>{
162
+ this.spinner.succeed(message);
163
+ }, 1000);
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ static SUCCESS = "success";
169
+ static ERROR = "fail";
170
+ static WARNING = "warn";
171
+ static INFO = "info";
172
+ }
126
173
 
127
174
  //# sourceMappingURL=Logger.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Logger.ts"],"sourcesContent":["import boxen, { Options as BoxenOptions } from \"boxen\";\n\nimport kleur from \"kleur\";\nimport util from \"node:util\";\n\nexport type PrintBoxOptions = {\n\tnewLineAfter?: boolean;\n\tnewLineBefore?: boolean;\n} & BoxenOptions;\n\nexport class Logger {\n\t#shouldLog: boolean;\n\t#globalPrefix: string;\n\t#showTimestamp: boolean;\n\t#printOptions: { colors: boolean; compact: boolean; depth: number };\n\n\tconstructor({\n\t\tboring = false,\n\t\tsilent = false,\n\t\tprefix = \"\",\n\t\ttimestamp = false,\n\t} = {}) {\n\t\tthis.#shouldLog = !silent;\n\t\tthis.#globalPrefix = prefix;\n\t\tthis.#showTimestamp = timestamp;\n\t\tthis.#printOptions = {\n\t\t\tcolors: !boring,\n\t\t\tcompact: false,\n\t\t\tdepth: 5,\n\t\t};\n\t}\n\n\tset silent(flag: boolean) {\n\t\tthis.#shouldLog = !flag;\n\t}\n\n\tset boring(flag: boolean) {\n\t\tthis.#printOptions.colors = !flag;\n\t}\n\n\tset prefix(prefix: string) {\n\t\tthis.#globalPrefix = prefix;\n\t}\n\n\tset timestamp(flag: boolean) {\n\t\tthis.#showTimestamp = flag;\n\t}\n\n\t#_log(\n\t\ttype: { method: string | number; color: (argument0: any) => any },\n\t\t...arguments_: string[]\n\t) {\n\t\tif (this.#shouldLog) {\n\t\t\tlet message: string;\n\t\t\tif (!this.#showTimestamp && !this.#globalPrefix) {\n\t\t\t\tmessage = util.formatWithOptions(this.#printOptions, ...arguments_);\n\t\t\t} else {\n\t\t\t\tconst prefix = this.#globalPrefix ? [this.#globalPrefix] : [];\n\t\t\t\tif (this.#showTimestamp) {\n\t\t\t\t\tconst now = new Date();\n\t\t\t\t\tprefix.push(\n\t\t\t\t\t\tthis.#printOptions.colors\n\t\t\t\t\t\t\t? `${kleur.grey(\n\t\t\t\t\t\t\t\t\t`[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`\n\t\t\t\t\t\t\t )}`\n\t\t\t\t\t\t\t: `[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tmessage = util.formatWithOptions(\n\t\t\t\t\tthis.#printOptions,\n\t\t\t\t\tprefix.join(\" \"),\n\t\t\t\t\t...arguments_\n\t\t\t\t);\n\t\t\t}\n\t\t\tconsole[type.method](\n\t\t\t\tthis.#printOptions.colors ? `${type.color(message)}` : message\n\t\t\t);\n\t\t}\n\t}\n\n\tinfo(...arguments_: any) {\n\t\tthis.#_log({ method: \"info\", color: kleur.blue }, ...arguments_);\n\t}\n\n\tlog(...arguments_: any) {\n\t\tthis.#_log({ method: \"log\", color: kleur.white }, ...arguments_);\n\t}\n\n\tdebug(...arguments_: any) {\n\t\tthis.#_log({ method: \"debug\", color: kleur.grey }, ...arguments_);\n\t}\n\n\twarn(...arguments_: any) {\n\t\tthis.#_log({ method: \"warn\", color: kleur.yellow }, ...arguments_);\n\t}\n\n\terror(...arguments_: any) {\n\t\tthis.#_log({ method: \"error\", color: kleur.red }, ...arguments_);\n\t}\n\n\t/**\n\t * Log multiple error messages at the prompt using `console.error` behind the scenes.\n\t * @param {string[]} errorMessages array of error message to display line by line\n\t * @param {number} [exitStatus] the process will exit with this value if provided\n\t */\n\tprintErrorsAndExit(errorMessages: string[], exitStatus?: number) {\n\t\tif (errorMessages && errorMessages.length > 0) {\n\t\t\tthis.log();\n\t\t\tfor (const message of errorMessages) {\n\t\t\t\tthis.error(message);\n\t\t\t}\n\t\t\tthis.log();\n\n\t\t\tif (typeof exitStatus === \"number\") {\n\t\t\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\t\t\tprocess.exit(exitStatus);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Print sets of logs in a box (wrapper to Boxen)\n\t * @param messages Messages to print\n\t * @param options\n\t */\n\tprintBox(messages: string | string[], options: PrintBoxOptions = {}) {\n\t\tconst { newLineAfter, newLineBefore } = {\n\t\t\tnewLineAfter: true,\n\t\t\tnewLineBefore: true,\n\t\t\t...options,\n\t\t};\n\n\t\t/**\n\t\t * Setting some sensible Boxen options if\n\t\t * not provided by the user.\n\t\t */\n\t\tconst boxenOptions: BoxenOptions = {\n\t\t\t...options,\n\t\t\tborderColor:\n\t\t\t\toptions.borderColor || (this.#printOptions.colors ? \"yellow\" : \"white\"),\n\t\t\tpadding: typeof options.padding === \"number\" ? options.padding : 1,\n\t\t\ttextAlignment: options.textAlignment || \"center\",\n\t\t};\n\n\t\tconst oldPrefix = this.#globalPrefix;\n\t\tconst oldTimestamp = this.#showTimestamp;\n\n\t\tthis.#globalPrefix = \"\";\n\t\tthis.#showTimestamp = false;\n\n\t\tnewLineBefore && this.log();\n\t\tthis.log(\n\t\t\tboxen(\n\t\t\t\ttypeof messages === \"string\" ? messages : messages.join(\"\\n\"),\n\t\t\t\tboxenOptions\n\t\t\t)\n\t\t);\n\t\tnewLineAfter && this.log();\n\n\t\tthis.#showTimestamp = oldTimestamp;\n\t\tthis.#globalPrefix = oldPrefix;\n\t}\n}\n"],"names":["boxen","kleur","util","Logger","shouldLog","globalPrefix","showTimestamp","printOptions","constructor","boring","silent","prefix","timestamp","colors","compact","depth","flag","_log","type","arguments_","message","formatWithOptions","now","Date","push","grey","toDateString","toLocaleTimeString","join","console","method","color","info","blue","log","white","debug","warn","yellow","error","red","printErrorsAndExit","errorMessages","exitStatus","length","process","exit","printBox","messages","options","newLineAfter","newLineBefore","boxenOptions","borderColor","padding","textAlignment","oldPrefix","oldTimestamp"],"mappings":"AAAA,OAAOA,WAAwC,QAAQ;AAEvD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,UAAU,YAAY;AA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d,WAAWsB,cAAe;gBACpC,IAAI,CAACH,MAAMnB;YACZ;YACA,IAAI,CAACc;YAEL,IAAI,OAAOS,eAAe,UAAU;gBACnC,mDAAmD;gBACnDE,QAAQC,KAAKH;YACd;QACD;IACD;IAEA;;;;EAIC,GACDI,SAASC,QAA2B,EAAEC,UAA2B,CAAC,CAAC,EAAE;QACpE,MAAM,EAAEC,aAAY,EAAEC,cAAa,EAAE,GAAG;YACvCD,cAAc;YACdC,eAAe;YACf,GAAGF,OAAO;QACX;QAEA;;;GAGC,GACD,MAAMG,eAA6B;YAClC,GAAGH,OAAO;YACVI,aACCJ,QAAQI,eAAgB,CAAA,IAAI,CAAC,CAAC9C,YAAY,CAACM,SAAS,WAAW,OAAM;YACtEyC,SAAS,OAAOL,QAAQK,YAAY,WAAWL,QAAQK,UAAU;YACjEC,eAAeN,QAAQM,iBAAiB;QACzC;QAEA,MAAMC,YAAY,IAAI,CAAC,CAACnD,YAAY;QACpC,MAAMoD,eAAe,IAAI,CAAC,CAACnD,aAAa;QAExC,IAAI,CAAC,CAACD,YAAY,GAAG;QACrB,IAAI,CAAC,CAACC,aAAa,GAAG;QAEtB6C,iBAAiB,IAAI,CAACjB;QACtB,IAAI,CAACA,IACJlC,MACC,OAAOgD,aAAa,WAAWA,WAAWA,SAASpB,KAAK,OACxDwB;QAGFF,gBAAgB,IAAI,CAAChB;QAErB,IAAI,CAAC,CAAC5B,aAAa,GAAGmD;QACtB,IAAI,CAAC,CAACpD,YAAY,GAAGmD;IACtB;AACD"}
1
+ {"version":3,"sources":["../src/Logger.ts"],"sourcesContent":["import boxen, { Options as BoxenOptions } from \"boxen\";\nimport ora, { Ora, Options as OraOptions } from \"ora\";\nimport util, { types } from \"node:util\";\n\nimport kleur from \"kleur\";\n\nexport type PrintBoxOptions = {\n\tnewLineAfter?: boolean;\n\tnewLineBefore?: boolean;\n} & BoxenOptions;\n\nexport class Logger {\n\t#shouldLog: boolean;\n\t#globalPrefix: string;\n\t#showTimestamp: boolean;\n\t#printOptions: { colors: boolean; compact: boolean; depth: number };\n\n\tconstructor({\n\t\tboring = false,\n\t\tsilent = false,\n\t\tprefix = \"\",\n\t\ttimestamp = false,\n\t} = {}) {\n\t\tthis.#shouldLog = !silent;\n\t\tthis.#globalPrefix = prefix;\n\t\tthis.#showTimestamp = timestamp;\n\t\tthis.#printOptions = {\n\t\t\tcolors: !boring,\n\t\t\tcompact: false,\n\t\t\tdepth: 5,\n\t\t};\n\t}\n\n\tset silent(flag: boolean) {\n\t\tthis.#shouldLog = !flag;\n\t}\n\n\tset boring(flag: boolean) {\n\t\tthis.#printOptions.colors = !flag;\n\t}\n\n\tset prefix(prefix: string) {\n\t\tthis.#globalPrefix = prefix;\n\t}\n\n\tset timestamp(flag: boolean) {\n\t\tthis.#showTimestamp = flag;\n\t}\n\n\t#_log(\n\t\ttype: { method: string | number; color: (argument0: any) => any },\n\t\t...arguments_: string[]\n\t) {\n\t\tif (this.#shouldLog) {\n\t\t\tlet message: string;\n\t\t\tif (!this.#showTimestamp && !this.#globalPrefix) {\n\t\t\t\tmessage = util.formatWithOptions(this.#printOptions, ...arguments_);\n\t\t\t} else {\n\t\t\t\tconst prefix = this.#globalPrefix ? [this.#globalPrefix] : [];\n\t\t\t\tif (this.#showTimestamp) {\n\t\t\t\t\tconst now = new Date();\n\t\t\t\t\tprefix.push(\n\t\t\t\t\t\tthis.#printOptions.colors\n\t\t\t\t\t\t\t? `${kleur.grey(\n\t\t\t\t\t\t\t\t\t`[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`\n\t\t\t\t\t\t\t )}`\n\t\t\t\t\t\t\t: `[ ${now.toDateString()} ${now.toLocaleTimeString()} ]`\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tmessage = util.formatWithOptions(\n\t\t\t\t\tthis.#printOptions,\n\t\t\t\t\tprefix.join(\" \"),\n\t\t\t\t\t...arguments_\n\t\t\t\t);\n\t\t\t}\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole[type.method](\n\t\t\t\tthis.#printOptions.colors ? `${type.color(message)}` : message\n\t\t\t);\n\t\t}\n\t}\n\n\tinfo(...arguments_: any) {\n\t\tthis.#_log({ method: \"info\", color: kleur.blue }, ...arguments_);\n\t}\n\n\tlog(...arguments_: any) {\n\t\tthis.#_log({ method: \"log\", color: kleur.white }, ...arguments_);\n\t}\n\n\tdebug(...arguments_: any) {\n\t\tthis.#_log({ method: \"debug\", color: kleur.grey }, ...arguments_);\n\t}\n\n\twarn(...arguments_: any) {\n\t\tthis.#_log({ method: \"warn\", color: kleur.yellow }, ...arguments_);\n\t}\n\n\terror(...arguments_: any) {\n\t\tthis.#_log({ method: \"error\", color: kleur.red }, ...arguments_);\n\t}\n\n\t/**\n\t * Log multiple error messages at the prompt using `console.error` behind the scenes.\n\t * @param {string[]} errorMessages array of error message to display line by line\n\t * @param {number} [exitStatus] the process will exit with this value if provided\n\t */\n\tprintErrorsAndExit(errorMessages: string[], exitStatus?: number) {\n\t\tif (errorMessages && errorMessages.length > 0) {\n\t\t\tthis.log();\n\t\t\tfor (const message of errorMessages) {\n\t\t\t\tthis.error(message);\n\t\t\t}\n\t\t\tthis.log();\n\n\t\t\tif (typeof exitStatus === \"number\") {\n\t\t\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\t\t\tprocess.exit(exitStatus);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Print sets of logs in a box (wrapper to Boxen)\n\t * @param messages Messages to print\n\t * @param options\n\t */\n\tprintBox(messages: string | string[], options: PrintBoxOptions = {}) {\n\t\tconst { newLineAfter, newLineBefore } = {\n\t\t\tnewLineAfter: true,\n\t\t\tnewLineBefore: true,\n\t\t\t...options,\n\t\t};\n\n\t\t/**\n\t\t * Setting some sensible Boxen options if\n\t\t * not provided by the user.\n\t\t */\n\t\tconst boxenOptions: BoxenOptions = {\n\t\t\t...options,\n\t\t\tborderColor:\n\t\t\t\toptions.borderColor || (this.#printOptions.colors ? \"yellow\" : \"white\"),\n\t\t\tpadding: typeof options.padding === \"number\" ? options.padding : 1,\n\t\t\ttextAlignment: options.textAlignment || \"center\",\n\t\t};\n\n\t\tconst oldPrefix = this.#globalPrefix;\n\t\tconst oldTimestamp = this.#showTimestamp;\n\n\t\tthis.#globalPrefix = \"\";\n\t\tthis.#showTimestamp = false;\n\n\t\tnewLineBefore && this.log();\n\t\tthis.log(\n\t\t\tboxen(\n\t\t\t\ttypeof messages === \"string\" ? messages : messages.join(\"\\n\"),\n\t\t\t\tboxenOptions\n\t\t\t)\n\t\t);\n\t\tnewLineAfter && this.log();\n\n\t\tthis.#showTimestamp = oldTimestamp;\n\t\tthis.#globalPrefix = oldPrefix;\n\t}\n}\n\n/* istanbul ignore next */\nexport class Spinner {\n\tspinner: Ora;\n\n\tconstructor(options?: OraOptions) {\n\t\tthis.spinner = ora({\n\t\t\t...options,\n\t\t\tisSilent: process.env.NODE_ENV === \"test\",\n\t\t});\n\t}\n\n\tset text(message: string) {\n\t\tthis.spinner.text = message;\n\t}\n\n\tstart(message?: string) {\n\t\tthis.spinner.start(message);\n\t}\n\n\tstop(message?: string, type?: string) {\n\t\tswitch (type) {\n\t\t\tcase Spinner.ERROR: {\n\t\t\t\tthis.spinner.fail(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Spinner.WARNING: {\n\t\t\t\tthis.spinner.warn(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Spinner.INFO: {\n\t\t\t\tthis.spinner.info(message);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis.spinner.succeed(message);\n\t\t\t\t}, 1000);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic SUCCESS = \"success\";\n\tstatic ERROR = \"fail\";\n\tstatic WARNING = \"warn\";\n\tstatic INFO = \"info\";\n}\n"],"names":["boxen","ora","util","kleur","Logger","shouldLog","globalPrefix","showTimestamp","printOptions","constructor","boring","silent","prefix","timestamp","colors","compact","depth","flag","_log","type","arguments_","message","formatWithOptions","now","Date","push","grey","toDateString","toLocaleTimeString","join","console","method","color","info","blue","log","white","debug","warn","yellow","error","red","printErrorsAndExit","errorMessages","exitStatus","length","process","exit","printBox","messages","options","newLineAfter","newLineBefore","boxenOptions","borderColor","padding","textAlignment","oldPrefix","oldTimestamp","Spinner","spinner","isSilent","env","NODE_ENV","text","start","stop","ERROR","fail","WARNING","INFO","setTimeout","succeed","SUCCESS"],"mappings":"AAAA,OAAOA,WAAwC,QAAQ;AACvD,OAAOC,SAAyC,MAAM;AACtD,OAAOC,UAAqB,YAAY;AAExC,OAAOC,WAAW,QAAQ;AAO1B,OAAO,MAAMC;IACZ,CAACC,SAAS,CAAU;IACpB,CAACC,YAAY,CAAS;IACtB,CAACC,aAAa,CAAU;IACxB,CAACC,YAAY,CAAuD;IAEpEC,YAAY,EACXC,QAAS,MAAK,EACdC,QAAS,MAAK,EACdC,QAAS,GAAE,EACXC,WAAY,MAAK,EACjB,GAAG,CAAC,CAAC,CAAE;QACP,IAAI,CAAC,CAACR,SAAS,GAAG,CAACM;QACnB,IAAI,CAAC,CAACL,YAAY,GAAGM;QACrB,IAAI,CAAC,CAACL,aAAa,GAAGM;QACtB,IAAI,CAAC,CAACL,YAAY,GAAG;YACpBM,QAAQ,CAACJ;YACTK,SAAS;YACTC,OAAO;QACR;IACD;IAEA,IAAIL,OAAOM,IAAa,EAAE;QACzB,IAAI,CAAC,CAACZ,SAAS,GAAG,CAACY;IACpB;IAEA,IAAIP,OAAOO,IAAa,EAAE;QACzB,IAAI,CAAC,CAACT,YAAY,CAACM,SAAS,CAACG;IAC9B;IAEA,IAAIL,OAAOA,MAAc,EAAE;QAC1B,IAAI,CAAC,CAACN,YAAY,GAAGM;IACtB;IAEA,IAAIC,UAAUI,IAAa,EAAE;QAC5B,IAAI,CAAC,CAACV,aAAa,GAAGU;IACvB;IAEA,CAACC,IAAI,CACJC,IAAiE,EACjE,GAAGC,U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WA,SAASpB,KAAK,OACxDwB;QAGFF,gBAAgB,IAAI,CAAChB;QAErB,IAAI,CAAC,CAAC5B,aAAa,GAAGmD;QACtB,IAAI,CAAC,CAACpD,YAAY,GAAGmD;IACtB;AACD;AAEA,wBAAwB,GACxB,OAAO,MAAME;IACZC,QAAa;IAEbnD,YAAYyC,OAAoB,CAAE;QACjC,IAAI,CAACU,UAAU3D,IAAI;YAClB,GAAGiD,OAAO;YACVW,UAAUf,QAAQgB,IAAIC,aAAa;QACpC;IACD;IAEA,IAAIC,KAAK3C,OAAe,EAAE;QACzB,IAAI,CAACuC,QAAQI,OAAO3C;IACrB;IAEA4C,MAAM5C,OAAgB,EAAE;QACvB,IAAI,CAACuC,QAAQK,MAAM5C;IACpB;IAEA6C,KAAK7C,OAAgB,EAAEF,IAAa,EAAE;QACrC,OAAQA;YACP,KAAKwC,QAAQQ;gBAAO;oBACnB,IAAI,CAACP,QAAQQ,KAAK/C;oBAClB;gBACD;YACA,KAAKsC,QAAQU;gBAAS;oBACrB,IAAI,CAACT,QAAQtB,KAAKjB;oBAClB;gBACD;YACA,KAAKsC,QAAQW;gBAAM;oBAClB,IAAI,CAACV,QAAQ3B,KAAKZ;oBAClB;gBACD;YACA;gBAAS;oBACRkD,WAAW;wBACV,IAAI,CAACX,QAAQY,QAAQnD;oBACtB,GAAG;oBACH;gBACD;QACD;IACD;IAEA,OAAOoD,UAAU,UAAU;IAC3B,OAAON,QAAQ,OAAO;IACtB,OAAOE,UAAU,OAAO;IACxB,OAAOC,OAAO,OAAO;AACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/logger",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "A tiny console logger for nodejs CLI apps",
@@ -12,7 +12,8 @@
12
12
  "node": ">=16",
13
13
  "dependencies": {
14
14
  "boxen": "7.1.0",
15
- "kleur": "4.1.5"
15
+ "kleur": "4.1.5",
16
+ "ora": "6.3.1"
16
17
  },
17
18
  "scripts": {
18
19
  "build": "yarn run clean && yarn run build:types && yarn run build:js && yarn run build:barrel",
@@ -20,7 +21,7 @@
20
21
  "build:js": "swc --source-maps --out-dir dist src",
21
22
  "build:types": "tsc",
22
23
  "clean": "rimraf dist types coverage",
23
- "lint": "eslint \"src/*.ts\"",
24
+ "lint": "prettier --write \"src/*.ts\" && eslint --fix \"src/*.ts\"",
24
25
  "test": "cross-env-shell NODE_OPTIONS=--experimental-vm-modules jest",
25
26
  "test:coverage": "npm run test -- --coverage",
26
27
  "watch": "swc --watch --out-dir dist src"
@@ -28,5 +29,5 @@
28
29
  "publishConfig": {
29
30
  "access": "public"
30
31
  },
31
- "gitHead": "d1d89854e385600edfd9c2aead7c9bc568bcc657"
32
+ "gitHead": "04fc495165a21ef51a94175dac632e733759eab4"
32
33
  }