From 90b10cdb08663e0c8c2bf6cb9278e48fa2285978 Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Mon, 3 May 2021 12:24:35 +0200 Subject: [PATCH 01/10] pass options to Loggers constructor --- package.json | 1 + src/index.js | 42 +++++++++++++++++++++--------------------- test/chalk.js | 21 +++++++++++++++++++++ test/index.js | 5 +++-- 4 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 test/chalk.js diff --git a/package.json b/package.json index 99ee97f..49a380a 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "eslint-plugin-standard": "^4.0.0", "husky": "^6.0.0", "lint-staged": "^10.5.4", + "lodash": "^4.17.21", "travis-deploy-once": "^5.0.9" }, "dependencies": { diff --git a/src/index.js b/src/index.js index 0abe500..c813934 100644 --- a/src/index.js +++ b/src/index.js @@ -1,46 +1,46 @@ /* eslint-disable no-param-reassign */ /* eslint no-console: off */ +import _ from 'lodash' + import chalkExt from './chalkExt' class Logger { - constructor() { - this.options = { - prefix: '{yellow [StackR23]}', - debug: { - color: 'cyan' - }, - error: { - color: 'red' - }, - success: { - color: 'green', - }, - } + + // use static props -> update babel! + defaults = { + prefix: '[StackR23]', + debug: {color: 'cyan', prefix: 'DEBUG'}, + error: {color: 'red', prefix: 'ERROR'}, + success: {color: 'green', prefix: 'SUCCESS'} } + constructor(options) { + console.log('options :>> ', options) - setPrefix(prefix) { - this.options.prefix = prefix || '' + this.options = _.merge(this.defaults, options) + console.log('this.defaults :>> ', this.defaults) + console.log('this.options :>> ', this.options) } log(str, typePrefix, styleType, styleString) { if (arguments.length === 1) { - console.log(chalkExt`{bold ${this.options.prefix}} ${str}`) + console.log(chalkExt`{${this.options.prefixColor}.bold ${this.options.prefix}} ${str}`) return true } if (arguments.length === 2) { const type = typePrefix - const {color, prefix, colorType} = this.options[type] + const {color, prefix} = this.options[type] // typePrefix = prefix || type - styleType = colorType || color + // styleType = colorType || color styleString = color } console.log( - chalkExt`{${styleType} {bold ${this.options.prefix} ${typePrefix}:} {${styleString} ${str}}}` + // ${styleType} + chalkExt`{{bold ${this.options.prefix} ${typePrefix}:} {${styleString} ${str}}` ) return true @@ -50,9 +50,9 @@ class Logger { debug = str => this.log(str, 'debug') - error = str => this.log(str, 'ERROR', `${this.options.error.color}Bright.bgBlack`, this.options.error.color) + error = str => this.log(str, 'error') //, `${this.options.errorColor}Bright.bgBlack`, this.options.errorColor) - success = str => this.log(str, 'SUCCESS', `${this.options.success.color}Bright`, this.options.success.color) + success = str => this.log(str, 'success') //, `${this.options.successColor}Bright`, this.options.successColor) } export default new Logger() diff --git a/test/chalk.js b/test/chalk.js new file mode 100644 index 0000000..9dd827e --- /dev/null +++ b/test/chalk.js @@ -0,0 +1,21 @@ +// import chalk from 'chalk' +const chalk = require('chalk') +const chalkExt = require('../dist/chalkExt').default; + +// console.log( +// chalk.red('test'), +// chalk`is this blue? {blue TEST}` +// ) + +console.log( + // chalk('is this {blue blue?}') + // chalk`{red TEST}` +); + +let color = 'red' + +console.log( + chalkExt`{${color}Bright.bgBlack TEST}` +) + + diff --git a/test/index.js b/test/index.js index 3d54f76..3507c80 100644 --- a/test/index.js +++ b/test/index.js @@ -1,7 +1,8 @@ /* eslint-disable-next-line import/no-unresolved */ -import Logger from '../dist' +import Logger from '../src' Logger.success('logger running!') Logger.error('unexpected bahavior') -Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}') +// Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}') Logger.debug('standard debug info') + From 2ffb8ba4227e956c2c67651b1daf36947e5fa199 Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 12:11:10 +0200 Subject: [PATCH 02/10] stash commit before dep updates --- src/index.js | 30 +++++++++++------------------- test/index.js | 20 +++++++++++++++++--- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/index.js b/src/index.js index c813934..3e8eb93 100644 --- a/src/index.js +++ b/src/index.js @@ -9,38 +9,30 @@ class Logger { // use static props -> update babel! defaults = { prefix: '[StackR23]', - debug: {color: 'cyan', prefix: 'DEBUG'}, - error: {color: 'red', prefix: 'ERROR'}, - success: {color: 'green', prefix: 'SUCCESS'} + debug: {style: 'cyan', prefix: 'DEBUG'}, + error: {style: 'red', prefix: 'ERROR'}, + success: {style: 'green', prefix: 'SUCCESS'} } constructor(options) { console.log('options :>> ', options) this.options = _.merge(this.defaults, options) - console.log('this.defaults :>> ', this.defaults) - console.log('this.options :>> ', this.options) } - log(str, typePrefix, styleType, styleString) { - if (arguments.length === 1) { - console.log(chalkExt`{${this.options.prefixColor}.bold ${this.options.prefix}} ${str}`) + log(str, type, styleStringCustom) { + // if (arguments.length === 1) { + // console.log(chalkExt`{${this.options.prefixColor}.bold ${this.options.prefix}} ${str}`) - return true - } + // return true + // } - if (arguments.length === 2) { - const type = typePrefix - const {color, prefix} = this.options[type] // + console.log(this.options[type]) + const {styleString, prefix} = this.options[type] - typePrefix = prefix || type - // styleType = colorType || color - styleString = color - } console.log( - // ${styleType} - chalkExt`{{bold ${this.options.prefix} ${typePrefix}:} {${styleString} ${str}}` + chalkExt`{bold ${prefix}:} {${styleString} ${str}}` ) return true diff --git a/test/index.js b/test/index.js index 3507c80..0a022fd 100644 --- a/test/index.js +++ b/test/index.js @@ -1,8 +1,22 @@ /* eslint-disable-next-line import/no-unresolved */ +import chalk from 'chalk' + import Logger from '../src' +import chalkExt from '../src/chalkExt' + + +let color = 'red' + +console.log( + chalk`{red test}`, + chalkExt`test`, + // chalkExt`{red test}`, +) + +// Logger.error('unexpected bahavior') + -Logger.success('logger running!') -Logger.error('unexpected bahavior') +// Logger.success('logger running!') // Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}') -Logger.debug('standard debug info') +// Logger.debug('standard debug info') From 3e0418b078f52cd7612493c7f1fddd220385bbcf Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 12:14:46 +0200 Subject: [PATCH 03/10] deps: remove eslint plugins (included in custom eslint package) --- package.json | 8 -------- 1 file changed, 8 deletions(-) diff --git a/package.json b/package.json index 49a380a..98c41ff 100644 --- a/package.json +++ b/package.json @@ -89,16 +89,8 @@ "@babel/preset-env": "^7.1.6", "@babel/register": "^7.0.0", "@viewar/config-eslint": "^1.12.0", - "babel-eslint": "^10.0.1", "babel-preset-minify": "^0.5.0", "eslint": "^6.0.0", - "eslint-config-airbnb": "^17.1.0", - "eslint-plugin-import": "^2.17.0", - "eslint-plugin-jsx-a11y": "^6.1.2", - "eslint-plugin-node": "^9.0.0", - "eslint-plugin-promise": "^4.0.1", - "eslint-plugin-react": "^7.12.3", - "eslint-plugin-standard": "^4.0.0", "husky": "^6.0.0", "lint-staged": "^10.5.4", "lodash": "^4.17.21", From e2edbc53c02334abba2acdbdddf5bb857ce1687a Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 12:24:56 +0200 Subject: [PATCH 04/10] mend --- src/index.js | 4 ---- test/chalk.js | 14 +++++++++----- test/index.js | 4 +--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/index.js b/src/index.js index 3e8eb93..66b19ae 100644 --- a/src/index.js +++ b/src/index.js @@ -15,8 +15,6 @@ class Logger { } constructor(options) { - console.log('options :>> ', options) - this.options = _.merge(this.defaults, options) } @@ -27,10 +25,8 @@ class Logger { // return true // } - console.log(this.options[type]) const {styleString, prefix} = this.options[type] - console.log( chalkExt`{bold ${prefix}:} {${styleString} ${str}}` ) diff --git a/test/chalk.js b/test/chalk.js index 9dd827e..fe6262a 100644 --- a/test/chalk.js +++ b/test/chalk.js @@ -1,18 +1,22 @@ // import chalk from 'chalk' const chalk = require('chalk') -const chalkExt = require('../dist/chalkExt').default; + +const Logger = require('../src/index').default +const chalkExt = require('../src/chalkExt').default + + +Logger.error('ERROR TEST') // console.log( // chalk.red('test'), // chalk`is this blue? {blue TEST}` // ) +let color = 'red' console.log( - // chalk('is this {blue blue?}') - // chalk`{red TEST}` -); + chalk`{red TEST}` +) -let color = 'red' console.log( chalkExt`{${color}Bright.bgBlack TEST}` diff --git a/test/index.js b/test/index.js index 0a022fd..d847d4a 100644 --- a/test/index.js +++ b/test/index.js @@ -8,9 +8,7 @@ import chalkExt from '../src/chalkExt' let color = 'red' console.log( - chalk`{red test}`, - chalkExt`test`, - // chalkExt`{red test}`, + chalk`{red TEST}` ) // Logger.error('unexpected bahavior') From b9ccc5a25b64995cd953e1df6d05efb846976160 Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 12:27:45 +0200 Subject: [PATCH 05/10] deps: upgrade babel packages --- package.json | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 98c41ff..ee74e15 100644 --- a/package.json +++ b/package.json @@ -83,18 +83,16 @@ }, "homepage": "https://github.com/stackr23/logger#readme", "devDependencies": { - "@babel/cli": "^7.1.5", - "@babel/core": "^7.1.6", - "@babel/plugin-proposal-class-properties": "^7.1.0", - "@babel/preset-env": "^7.1.6", - "@babel/register": "^7.0.0", + "@babel/cli": "^7.13.16", + "@babel/core": "^7.14.0", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/preset-env": "^7.14.1", + "@babel/register": "^7.13.16", "@viewar/config-eslint": "^1.12.0", - "babel-preset-minify": "^0.5.0", - "eslint": "^6.0.0", + "babel-preset-minify": "^0.5.1", "husky": "^6.0.0", "lint-staged": "^10.5.4", - "lodash": "^4.17.21", - "travis-deploy-once": "^5.0.9" + "lodash": "^4.17.21" }, "dependencies": { "chalk": "^4.1.1" From 042a83ecbbf8ef3f65a2ae099f580dbf7829425c Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 13:06:26 +0200 Subject: [PATCH 06/10] chalkExt not needed anymore --- src/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 66b19ae..5cf90e3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ /* eslint-disable no-param-reassign */ /* eslint no-console: off */ import _ from 'lodash' +import chalk from 'chalk' import chalkExt from './chalkExt' @@ -8,27 +9,31 @@ class Logger { // use static props -> update babel! defaults = { - prefix: '[StackR23]', - debug: {style: 'cyan', prefix: 'DEBUG'}, - error: {style: 'red', prefix: 'ERROR'}, - success: {style: 'green', prefix: 'SUCCESS'} + prefix: '[StackR23]', + style: 'yellowBright.bold', + debug: {style: 'cyan', prefix: 'DEBUG'}, + error: {style: 'red', prefix: 'ERROR'}, + success: {style: 'green', prefix: 'SUCCESS'} } constructor(options) { this.options = _.merge(this.defaults, options) } - log(str, type, styleStringCustom) { + log(str, type, styleCustom) { // if (arguments.length === 1) { // console.log(chalkExt`{${this.options.prefixColor}.bold ${this.options.prefix}} ${str}`) // return true // } - const {styleString, prefix} = this.options[type] + const {style, prefix} = this.options + const typeOptions = this.options[type] console.log( - chalkExt`{bold ${prefix}:} {${styleString} ${str}}` + chalk`{${style} ${prefix}} {bold.${typeOptions.style} ${typeOptions.prefix}:}`, + chalk`{${styleCustom || typeOptions.style} ${str}}` + // chalkExt`{bold ${prefix}:} {${styleString} ${str}}` ) return true From 7295fd9825d1f61bdf121ce778e4bd811e0ffea7 Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 13:06:53 +0200 Subject: [PATCH 07/10] just some tests --- test/chalk.js | 6 +++--- test/index.js | 26 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/test/chalk.js b/test/chalk.js index fe6262a..3ca0313 100644 --- a/test/chalk.js +++ b/test/chalk.js @@ -1,11 +1,11 @@ // import chalk from 'chalk' const chalk = require('chalk') -const Logger = require('../src/index').default -const chalkExt = require('../src/chalkExt').default +// const Logger = require('../src/index').default +const chalkExt = require('../dist/chalkExt').default -Logger.error('ERROR TEST') +// Logger.error('ERROR TEST') // console.log( // chalk.red('test'), diff --git a/test/index.js b/test/index.js index d847d4a..7907840 100644 --- a/test/index.js +++ b/test/index.js @@ -1,20 +1,34 @@ -/* eslint-disable-next-line import/no-unresolved */ import chalk from 'chalk' -import Logger from '../src' +import Logger from '../src/index' import chalkExt from '../src/chalkExt' +console.log( + chalk`There are {red.bold 5280 feet} in a mile.` +) -let color = 'red' +let color = 'blue', + str = 'fgdgfsdg' console.log( - chalk`{red TEST}` + chalk`{${color} ${str}}` ) -// Logger.error('unexpected bahavior') + +// /* eslint-disable-next-line import/no-unresolved */ +// import chalk from 'chalk' + +// // import Logger from '../src' +// // const chalkExt = require('../dist/chalkExt').default + + +// let color = 'red' + + +Logger.error('unexpected bahavior') -// Logger.success('logger running!') +Logger.success('logger running!') // Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}') // Logger.debug('standard debug info') From d2921812dabf48dacaaec87e0b6f855a282cf2cd Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 13:09:50 +0200 Subject: [PATCH 08/10] just some tests --- src/index.js | 1 + test/index.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 5cf90e3..8bc501f 100644 --- a/src/index.js +++ b/src/index.js @@ -48,4 +48,5 @@ class Logger { success = str => this.log(str, 'success') //, `${this.options.successColor}Bright`, this.options.successColor) } +export {Logger} export default new Logger() diff --git a/test/index.js b/test/index.js index 7907840..216a655 100644 --- a/test/index.js +++ b/test/index.js @@ -1,8 +1,12 @@ import chalk from 'chalk' -import Logger from '../src/index' +// import Logger from '../src/index' +import {Logger} from '../src/index' import chalkExt from '../src/chalkExt' + +const log = new Logger({prefix: ''}) + console.log( chalk`There are {red.bold 5280 feet} in a mile.` ) @@ -25,10 +29,10 @@ console.log( // let color = 'red' -Logger.error('unexpected bahavior') +log.error('unexpected bahavior') -Logger.success('logger running!') +log.success('logger running!') // Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}') // Logger.debug('standard debug info') From 16f01133e12ed2ab5d41dc2bec209fae0960d63c Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 13:12:14 +0200 Subject: [PATCH 09/10] used Logger options --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 8bc501f..4d477dd 100644 --- a/src/index.js +++ b/src/index.js @@ -30,6 +30,9 @@ class Logger { const {style, prefix} = this.options const typeOptions = this.options[type] + // concat chalk string to prevent extra spaces + // if (prefix) {} + console.log( chalk`{${style} ${prefix}} {bold.${typeOptions.style} ${typeOptions.prefix}:}`, chalk`{${styleCustom || typeOptions.style} ${str}}` From 1871a68c99dc275a35c16c443f9c1cea0f6ae2ce Mon Sep 17 00:00:00 2001 From: DoubleU23 <5007050+DoubleU23@users.noreply.github.com> Date: Tue, 4 May 2021 15:55:02 +0200 Subject: [PATCH 10/10] * feat: pass options to Logger instance * feat: customization of strings and prefixes * fix: fix tests --- src/index.js | 46 +++++++++++++++++----------------------------- test/chalk.js | 25 ------------------------- test/index.js | 39 ++++++++------------------------------- 3 files changed, 25 insertions(+), 85 deletions(-) delete mode 100644 test/chalk.js diff --git a/src/index.js b/src/index.js index 4d477dd..3e5bcbe 100644 --- a/src/index.js +++ b/src/index.js @@ -1,54 +1,42 @@ /* eslint-disable no-param-reassign */ /* eslint no-console: off */ import _ from 'lodash' -import chalk from 'chalk' import chalkExt from './chalkExt' +// TODO: use static props -> update babel! class Logger { - // use static props -> update babel! defaults = { - prefix: '[StackR23]', - style: 'yellowBright.bold', - debug: {style: 'cyan', prefix: 'DEBUG'}, - error: {style: 'red', prefix: 'ERROR'}, - success: {style: 'green', prefix: 'SUCCESS'} + prefix: '{bold.yellow [StackR23] }', + log: {style: 'reset', prefix: 'bold.yellow LOG - '}, + debug: {style: 'cyan', prefix: '{bold.cyan DEBUG: }'}, + error: {style: 'red', prefix: '{bold.red ERROR: }'}, + success: {style: 'green', prefix: '{bold.green SUCCESS: }'} } constructor(options) { this.options = _.merge(this.defaults, options) } - log(str, type, styleCustom) { - // if (arguments.length === 1) { - // console.log(chalkExt`{${this.options.prefixColor}.bold ${this.options.prefix}} ${str}`) + log(str, type = 'log', styleCustom) { + const {prefix, [type]: typeOptions} = this.options - // return true - // } - - const {style, prefix} = this.options - const typeOptions = this.options[type] - - // concat chalk string to prevent extra spaces - // if (prefix) {} + if (arguments.length === 1) { + console.log(chalkExt`${prefix}${str}`) + return + } console.log( - chalk`{${style} ${prefix}} {bold.${typeOptions.style} ${typeOptions.prefix}:}`, - chalk`{${styleCustom || typeOptions.style} ${str}}` - // chalkExt`{bold ${prefix}:} {${styleString} ${str}}` + (prefix ? chalkExt`${prefix}` : '') + + (typeOptions.prefix ? chalkExt`${typeOptions.prefix}` : '') + + chalkExt`{${typeOptions.style} ${str}}` ) - - return true } - dir = arg => console.dir(...arg) - debug = str => this.log(str, 'debug') - - error = str => this.log(str, 'error') //, `${this.options.errorColor}Bright.bgBlack`, this.options.errorColor) - - success = str => this.log(str, 'success') //, `${this.options.successColor}Bright`, this.options.successColor) + error = str => this.log(str, 'error') + success = str => this.log(str, 'success') } export {Logger} diff --git a/test/chalk.js b/test/chalk.js deleted file mode 100644 index 3ca0313..0000000 --- a/test/chalk.js +++ /dev/null @@ -1,25 +0,0 @@ -// import chalk from 'chalk' -const chalk = require('chalk') - -// const Logger = require('../src/index').default -const chalkExt = require('../dist/chalkExt').default - - -// Logger.error('ERROR TEST') - -// console.log( -// chalk.red('test'), -// chalk`is this blue? {blue TEST}` -// ) - -let color = 'red' -console.log( - chalk`{red TEST}` -) - - -console.log( - chalkExt`{${color}Bright.bgBlack TEST}` -) - - diff --git a/test/index.js b/test/index.js index 216a655..5f7dd99 100644 --- a/test/index.js +++ b/test/index.js @@ -1,38 +1,15 @@ -import chalk from 'chalk' - -// import Logger from '../src/index' import {Logger} from '../src/index' -import chalkExt from '../src/chalkExt' - - -const log = new Logger({prefix: ''}) - -console.log( - chalk`There are {red.bold 5280 feet} in a mile.` -) - -let color = 'blue', - str = 'fgdgfsdg' - -console.log( - chalk`{${color} ${str}}` -) - -// /* eslint-disable-next-line import/no-unresolved */ -// import chalk from 'chalk' - -// // import Logger from '../src' -// // const chalkExt = require('../dist/chalkExt').default - - -// let color = 'red' +const log = new Logger({ + prefix: '{cyan.bold [CUSTOM PREFIX] }', + debug: {prefix: '{bold.blue CUSTOMDEBUG }'} +}) +log.debug('standard debug message') +log.debug('{bgBlue.magenta CUSTOM{reset.yellow debug}{bgBlack.cyan info}}') log.error('unexpected bahavior') - - log.success('logger running!') -// Logger.log('{reset.magenta custom {bgBlackBright.yellow output style}}') -// Logger.debug('standard debug info') + +log.log('{bgBlue.bold.magenta custom output style}')