Skip to content

Commit

Permalink
separate CLI features for pretty.js (bin.js) with default features …
Browse files Browse the repository at this point in the history
…(pretty.js), to be able to use webpack with Node.js code in AWS Lambda environments
  • Loading branch information
Joey van Dijk committed Mar 6, 2017
1 parent 3ad502c commit 9826cfb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
29 changes: 29 additions & 0 deletions bin.js
@@ -0,0 +1,29 @@
#! /usr/bin/env node

'use strict'

var pretty = require('./pretty')

module.exports = pretty

if (require.main === module) {
if (arg('-h') || arg('--help')) {
usage().pipe(process.stdout)
} else if (arg('-v') || arg('--version')) {
console.log(require('./package.json').version)
} else {
process.stdin.pipe(pretty({
timeTransOnly: arg('-t'),
levelFirst: arg('-l')
})).pipe(process.stdout)
}
}

function usage () {
return require('fs')
.createReadStream(require('path').join(__dirname, 'usage.txt'))
}

function arg (s) {
return !!~process.argv.indexOf(s)
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"main": "pino.js",
"browser": "./browser.js",
"bin": {
"pino": "./pretty.js"
"pino": "./bin.js"
},
"files": [
"pino.js",
Expand Down
24 changes: 0 additions & 24 deletions pretty.js
@@ -1,5 +1,3 @@
#! /usr/bin/env node

'use strict'

var split = require('split2')
Expand Down Expand Up @@ -139,25 +137,3 @@ function pretty (opts) {
}

module.exports = pretty

if (require.main === module) {
if (arg('-h') || arg('--help')) {
usage().pipe(process.stdout)
} else if (arg('-v') || arg('--version')) {
console.log(require('./package.json').version)
} else {
process.stdin.pipe(pretty({
timeTransOnly: arg('-t'),
levelFirst: arg('-l')
})).pipe(process.stdout)
}
}

function usage () {
return require('fs')
.createReadStream(require('path').join(__dirname, 'usage.txt'))
}

function arg (s) {
return !!~process.argv.indexOf(s)
}

0 comments on commit 9826cfb

Please sign in to comment.