heroku-cli-util
Advanced tools
Comparing version 5.10.12 to 6.0.0
@@ -0,1 +1,7 @@ | ||
5.10.12 / 2016-05-18 | ||
==================== | ||
* 5.10.12 | ||
* added ability to update action message | ||
5.10.11 / 2016-05-16 | ||
@@ -179,12 +185,1 @@ ==================== | ||
* updated jshintrc | ||
* 5.8.3 | ||
* update dependencies | ||
5.8.3 / 2016-03-08 | ||
================== | ||
* Merge pull request [#51](https://github.com/heroku/heroku-cli-util/issues/51) from heroku/update-deps | ||
update dependencies | ||
* Merge pull request [#50](https://github.com/heroku/heroku-cli-util/issues/50) from heroku/mocha-junit | ||
added mocha junit reporter for circle ci | ||
* added mocha junit reporter for circle ci |
'use strict'; | ||
let _ = require('lodash'); | ||
let chalk = require('chalk'); | ||
const chalk = require('chalk'); | ||
const pickBy = require('lodash.pickby'); | ||
const mapValues = require('lodash.mapvalues'); | ||
@@ -12,7 +13,7 @@ let colors = { | ||
let definedColors = _.pickBy(colors, function(value) { | ||
let definedColors = pickBy(colors, function(value) { | ||
return typeof(chalk[value]) === 'function'; | ||
}); | ||
let boundColors = _.mapValues(definedColors, v => s => chalk[v](s)); | ||
let boundColors = mapValues(definedColors, v => s => chalk[v](s)); | ||
@@ -19,0 +20,0 @@ boundColors.release = s => chalk.blue.bold(s); |
187
lib/table.js
'use strict'; | ||
let stripAnsi = require('..').color.stripColor; | ||
let _ = require('lodash'); | ||
let cli = require('..'); | ||
const stripAnsi = require('..').color.stripColor; | ||
const cli = require('..'); | ||
let defaults = { | ||
colSep: ' ', | ||
after: _.noop, | ||
headerAnsi: _.identity, | ||
printLine: cli.log, | ||
printRow: function(cells) { | ||
this.printLine(cells.join(this.colSep).trimRight()); | ||
}, | ||
printHeader: function(cells) { | ||
this.printRow(cells.map(_.ary(this.headerAnsi, 1))); | ||
this.printRow(cells.map(function(hdr) { return hdr.replace(/./g, '─'); })); | ||
} | ||
}; | ||
let colDefaults = { | ||
format: value => value ? value.toString() : '', | ||
width: 0, | ||
label: function() { return this.key.toString(); }, | ||
get: function(row) { | ||
let value; | ||
let path = _.result(this, 'key'); | ||
if(!path) { | ||
value = row; | ||
} else { | ||
value = _.get(row, path); | ||
} | ||
return this.format(value, row); | ||
}, | ||
}; | ||
function calcWidth(cell) { | ||
let lines = stripAnsi(cell).split(/[\r\n]+/); | ||
let lineLengths = lines.map(_.property('length')); | ||
return Math.max.apply(Math, lineLengths); | ||
} | ||
function pad(string, length) { | ||
let visibleLength = stripAnsi(string).length; | ||
let diff = length - visibleLength; | ||
return string + _.repeat(' ', Math.max(0, diff)); | ||
} | ||
/** | ||
@@ -75,55 +28,115 @@ * Generates a Unicode table and feeds it into configured printer. | ||
*/ | ||
function table(data, options) { | ||
_.defaults(options, defaults); | ||
function table (data, options) { | ||
const ary = require('lodash.ary'); | ||
const defaults = require('lodash.defaults'); | ||
const get = require('lodash.get'); | ||
const identity = require('lodash.identity'); | ||
const keys = require('lodash.keys'); | ||
const noop = require('lodash.noop'); | ||
const partial = require('lodash.partial'); | ||
const property = require('lodash.property'); | ||
const repeat = require('lodash.repeat'); | ||
const result = require('lodash.result'); | ||
let columns = options.columns || _.keys(data[0] || {}); | ||
let _defaults = { | ||
colSep: ' ', | ||
after: noop, | ||
headerAnsi: identity, | ||
printLine: cli.log, | ||
printRow: function(cells) { | ||
this.printLine(cells.join(this.colSep).trimRight()); | ||
}, | ||
printHeader: function(cells) { | ||
this.printRow(cells.map(ary(this.headerAnsi, 1))); | ||
this.printRow(cells.map(function(hdr) { return hdr.replace(/./g, '─'); })); | ||
} | ||
}; | ||
if(typeof columns[0] === 'string') { | ||
columns = columns.map(function(k) { return {key: k}; }); | ||
} | ||
let colDefaults = { | ||
format: value => value ? value.toString() : '', | ||
width: 0, | ||
label: function() { return this.key.toString(); }, | ||
let defaultsApplied = false; | ||
for(let row of data) { | ||
row.height = 1; | ||
for(let col of columns) { | ||
if(!defaultsApplied) { _.defaults(col, colDefaults); } | ||
get: function(row) { | ||
let value; | ||
let path = result(this, 'key'); | ||
let cell = col.get(row); | ||
if(!path) { | ||
value = row; | ||
} else { | ||
value = get(row, path); | ||
} | ||
col.width = Math.max( | ||
_.result(col, 'label').length, | ||
col.width, | ||
calcWidth(cell) | ||
); | ||
return this.format(value, row); | ||
}, | ||
}; | ||
row.height = Math.max( | ||
row.height, | ||
cell.split(/[\r\n]+/).length | ||
); | ||
} | ||
defaultsApplied = true; | ||
function calcWidth(cell) { | ||
let lines = stripAnsi(cell).split(/[\r\n]+/); | ||
let lineLengths = lines.map(property('length')); | ||
return Math.max.apply(Math, lineLengths); | ||
} | ||
if (options.printHeader) { | ||
options.printHeader(columns.map(function(col) { | ||
let label = _.result(col, 'label'); | ||
return pad(label, col.width || label.length ); | ||
})); | ||
} | ||
function pad(string, length) { | ||
let visibleLength = stripAnsi(string).length; | ||
let diff = length - visibleLength; | ||
function getNthLineOfCell(n, row, col) { | ||
// TODO memoize this | ||
let lines = col.get(row).split(/[\r\n]+/); | ||
return pad(lines[n] || '', col.width); | ||
return string + repeat(' ', Math.max(0, diff)); | ||
} | ||
for(let row of data) { | ||
for(let i = 0; i < row.height; i++) { | ||
let cells = columns.map(_.partial(getNthLineOfCell, i, row)); | ||
options.printRow(cells); | ||
function render () { | ||
let columns = options.columns || keys(data[0] || {}); | ||
if(typeof columns[0] === 'string') { | ||
columns = columns.map(function(k) { return {key: k}; }); | ||
} | ||
options.after(row, options); | ||
let defaultsApplied = false; | ||
for(let row of data) { | ||
row.height = 1; | ||
for(let col of columns) { | ||
if(!defaultsApplied) { defaults(col, colDefaults); } | ||
let cell = col.get(row); | ||
col.width = Math.max( | ||
result(col, 'label').length, | ||
col.width, | ||
calcWidth(cell) | ||
); | ||
row.height = Math.max( | ||
row.height, | ||
cell.split(/[\r\n]+/).length | ||
); | ||
} | ||
defaultsApplied = true; | ||
} | ||
if (options.printHeader) { | ||
options.printHeader(columns.map(function(col) { | ||
let label = result(col, 'label'); | ||
return pad(label, col.width || label.length ); | ||
})); | ||
} | ||
function getNthLineOfCell(n, row, col) { | ||
// TODO memoize this | ||
let lines = col.get(row).split(/[\r\n]+/); | ||
return pad(lines[n] || '', col.width); | ||
} | ||
for(let row of data) { | ||
for(let i = 0; i < row.height; i++) { | ||
let cells = columns.map(partial(getNthLineOfCell, i, row)); | ||
options.printRow(cells); | ||
} | ||
options.after(row, options); | ||
} | ||
} | ||
defaults(options, _defaults); | ||
render(); | ||
} | ||
module.exports = table; |
{ | ||
"name": "heroku-cli-util", | ||
"description": "Set of helpful CLI utilities", | ||
"version": "5.10.12", | ||
"version": "6.0.0", | ||
"author": "Jeff Dickey (@dickeyxxx)", | ||
@@ -10,12 +10,23 @@ "bugs": { | ||
"dependencies": { | ||
"cardinal": "0.7.1", | ||
"chalk": "1.1.3", | ||
"cli-cursor": "1.0.2", | ||
"co": "4.6.0", | ||
"got": "6.3.0", | ||
"heroku-client": "2.4.3", | ||
"lodash": "4.11.1", | ||
"opn": "3.0.3", | ||
"supports-color": "3.1.2", | ||
"tunnel-agent": "0.4.2" | ||
"cardinal": "^0.7.1", | ||
"chalk": "^1.1.3", | ||
"cli-cursor": "^1.0.2", | ||
"co": "^4.6.0", | ||
"got": "^6.3.0", | ||
"heroku-client": "3.0.0-alpha2", | ||
"lodash.ary": "4.0.1", | ||
"lodash.defaults": "4.0.1", | ||
"lodash.get": "4.3.0", | ||
"lodash.identity": "3.0.0", | ||
"lodash.keys": "4.0.7", | ||
"lodash.mapvalues": "4.4.0", | ||
"lodash.noop": "3.0.1", | ||
"lodash.partial": "4.1.4", | ||
"lodash.pickby": "4.4.0", | ||
"lodash.property": "4.3.0", | ||
"lodash.repeat": "4.0.3", | ||
"lodash.result": "4.4.0", | ||
"opn": "^3.0.3", | ||
"supports-color": "^3.1.2", | ||
"tunnel-agent": "^0.4.3" | ||
}, | ||
@@ -32,5 +43,5 @@ "devDependencies": { | ||
"nock": "8.0.0", | ||
"nyc": "6.4.0", | ||
"proxyquire": "1.7.4", | ||
"sinon": "1.17.3", | ||
"nyc": "6.4.4", | ||
"proxyquire": "1.7.9", | ||
"sinon": "1.17.4", | ||
"unexpected": "10.13.2" | ||
@@ -37,0 +48,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1740304
33762
21
+ Addedlodash.ary@4.0.1
+ Addedlodash.defaults@4.0.1
+ Addedlodash.get@4.3.0
+ Addedlodash.identity@3.0.0
+ Addedlodash.keys@4.0.7
+ Addedlodash.mapvalues@4.4.0
+ Addedlodash.noop@3.0.1
+ Addedlodash.partial@4.1.4
+ Addedlodash.pickby@4.4.0
+ Addedlodash.property@4.3.0
+ Addedlodash.repeat@4.0.3
+ Addedlodash.result@4.4.0
+ Addedget-stream@3.0.0(transitive)
+ Addedgot@6.7.1(transitive)
+ Addedheroku-client@3.0.0-alpha2(transitive)
+ Addedlodash._basefor@3.0.3(transitive)
+ Addedlodash._baseiteratee@4.7.0(transitive)
+ Addedlodash._basetostring@4.12.0(transitive)
+ Addedlodash._createwrapper@4.0.5(transitive)
+ Addedlodash._stringtopath@4.8.0(transitive)
+ Addedlodash.ary@4.0.1(transitive)
+ Addedlodash.assigninwith@4.2.0(transitive)
+ Addedlodash.defaults@4.0.1(transitive)
+ Addedlodash.get@4.3.0(transitive)
+ Addedlodash.identity@3.0.0(transitive)
+ Addedlodash.keys@4.0.7(transitive)
+ Addedlodash.keysin@4.2.0(transitive)
+ Addedlodash.mapvalues@4.4.0(transitive)
+ Addedlodash.noop@3.0.1(transitive)
+ Addedlodash.partial@4.1.4(transitive)
+ Addedlodash.pickby@4.4.0(transitive)
+ Addedlodash.property@4.3.0(transitive)
+ Addedlodash.repeat@4.0.3(transitive)
+ Addedlodash.rest@4.0.5(transitive)
+ Addedlodash.result@4.4.0(transitive)
+ Addedlodash.tostring@4.1.4(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsupports-color@3.2.3(transitive)
+ Addedtimed-out@4.0.1(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
+ Addedunzip-response@2.0.1(transitive)
- Removedlodash@4.11.1
- Removedget-stream@1.1.0(transitive)
- Removedgot@6.3.0(transitive)
- Removedheroku-client@2.4.3(transitive)
- Removedinflection@1.13.41.3.8(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedlodash@4.11.1(transitive)
- Removednode-status-codes@2.0.1(transitive)
- Removedpath-proxy@1.0.0(transitive)
- Removedq@1.5.1(transitive)
- Removedsupports-color@3.1.2(transitive)
- Removedtimed-out@2.0.0(transitive)
- Removedtunnel-agent@0.4.2(transitive)
- Removedunzip-response@1.0.2(transitive)
Updatedcardinal@^0.7.1
Updatedchalk@^1.1.3
Updatedcli-cursor@^1.0.2
Updatedco@^4.6.0
Updatedgot@^6.3.0
Updatedheroku-client@3.0.0-alpha2
Updatedopn@^3.0.3
Updatedsupports-color@^3.1.2
Updatedtunnel-agent@^0.4.3