Skip to content

Commit

Permalink
Merge branch 'master' into dev-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Oct 11, 2018
2 parents 31f1894 + e7b5ebd commit 4c0252d
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 32 deletions.
16 changes: 16 additions & 0 deletions demo/index.html
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Consola</title>
</head>
<body>
Open developer tools to see the magic!
<script type="module">
import consola from '../src/browser.js'

for (let type of Object.keys(consola.types).sort()) {
consola[type](`A message with consola.${type}()`)
}
</script>
</body>
</html>
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -8,8 +8,10 @@
"browser": "dist/consola.js",
"scripts": {
"build": "yarn build:cjs && yarn build:browser",
"build:cjs": "bili -t node --format cjs src/index.js",
"build:browser": "bili --format umd src/browser.js",
"build:cjs": "bili -t node --format cjs src/index.js --replace.__NPM_VERSION__ $npm_package_version",
"build:browser": "bili --format umd src/browser.js --replace.__NPM_VERSION__ $npm_package_version",
"node": "node demo",
"browser": "serve",
"lint": "eslint .",
"test": "yarn lint && yarn build && jest test",
"prepublish": "yarn build",
Expand Down Expand Up @@ -60,6 +62,7 @@
"esm": "^3.0.84",
"jest": "^23.6.0",
"lodash": "^4.17.11",
"serve": "^10.0.2",
"standard-version": "^4.4.0",
"winston": "^3.1.0"
}
Expand Down
8 changes: 8 additions & 0 deletions serve.json
@@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "",
"destination": "/demo/index.html"
}
]
}
4 changes: 2 additions & 2 deletions src/browser.js
@@ -1,5 +1,5 @@
import Consola from './consola'
import BrowserReporter from './reporters/browser'
import Consola from './consola.js'
import BrowserReporter from './reporters/browser.js'

if (!window.consola) {
// Create new consola instance
Expand Down
11 changes: 4 additions & 7 deletions src/consola.js
@@ -1,6 +1,5 @@
import Types from './types'
import { isLogObj } from './utils'
import { version } from '../package.json'
import Types from './types.js'
import { isLogObj } from './utils.js'

export default class Consola {
constructor (options = {}) {
Expand Down Expand Up @@ -73,8 +72,7 @@ export default class Consola {
delete logObj.scope
}

// Log
return this._log(logObj)
this._log(logObj)
}

// Bind function to instance of Consola
Expand All @@ -88,7 +86,6 @@ export default class Consola {
for (const reporter of this.reporters) {
reporter.log(logObj)
}
return this
}

_deprecated (what, alter) {
Expand Down Expand Up @@ -129,6 +126,6 @@ export default class Consola {
}

Object.defineProperty(Consola.prototype, '__VERSION__', {
value: version,
value: '__NPM_VERSION__',
writable: false
})
1 change: 0 additions & 1 deletion src/reporters/basic.js
Expand Up @@ -10,7 +10,6 @@ export default class BasicReporter {
this.options = Object.assign({
stream: process.stdout,
errStream: process.stderr,
showType: false,
timeFormat: 'HH:mm:ss',
formats: {
/* eslint-disable no-multi-spaces */
Expand Down
12 changes: 7 additions & 5 deletions src/reporters/fancy.js
Expand Up @@ -35,6 +35,7 @@ export const ICONS = {
export default class FancyReporter extends BasicReporter {
constructor (options) {
super(Object.assign({
showType: true,
formats: {
/* eslint-disable no-multi-spaces */
default: '' +
Expand Down Expand Up @@ -68,6 +69,7 @@ export default class FancyReporter extends BasicReporter {
}, options))

this._colorCache = {}
showType: true
}

formatStack (stack) {
Expand All @@ -84,12 +86,12 @@ export default class FancyReporter extends BasicReporter {
this.clear()
}

const format = this.options.formats[logObj.badge ? 'badge' : 'default']
const format = this.options.formats[logObj.badge ? 'badge' : 'default']

const colors = ['grey', logObj.color, logObj.additionalColor]
colors.forEach((color) => {
if (color && color.length && !this._colorCache[color]) {
this._colorCache[color] = chalkColor(color)('|').split('|')
const colors = ['grey', logObj.color, logObj.additionalColor]
colors.forEach((color) => {
if (color && color.length && !this._colorCache[color]) {
this._colorCache[color] = chalkColor(color)('|').split('|')
}
})

Expand Down

0 comments on commit 4c0252d

Please sign in to comment.