Comparing version 0.1.1 to 1.0.0
86
log.js
@@ -0,1 +1,4 @@ | ||
'use strict' | ||
var Progress = require('are-we-there-yet') | ||
var Gauge = require('gauge') | ||
var EE = require('events').EventEmitter | ||
@@ -23,2 +26,76 @@ var log = exports = module.exports = new EE | ||
log.gauge = new Gauge(log.cursor) | ||
log.tracker = new Progress.TrackerGroup() | ||
// no progress bars unless asked | ||
log.progressEnabled = false | ||
var unicodeEnabled = undefined | ||
log.enableUnicode = function () { | ||
unicodeEnabled = true | ||
log.gauge.theme = Gauge.unicode | ||
} | ||
log.disableUnicode = function () { | ||
unicodeEnabled = false | ||
log.gauge.theme = Gauge.ascii | ||
} | ||
log.enableProgress = function () { | ||
if (this.progressEnabled) return | ||
this.progressEnabled = true | ||
if (this._pause) return | ||
this.tracker.on('change', this.showProgress) | ||
this.gauge.enable() | ||
this.showProgress() | ||
} | ||
log.disableProgress = function () { | ||
if (!this.progressEnabled) return | ||
this.clearProgress() | ||
this.progressEnabled = false | ||
this.tracker.removeListener('change', this.showProgress) | ||
this.gauge.disable() | ||
} | ||
var trackerConstructors = ['newGroup', 'newItem', 'newStream'] | ||
var mixinLog = function (tracker) { | ||
// mixin the public methods from log into the tracker | ||
// (except: conflicts and one's we handle specially) | ||
Object.keys(log).forEach(function (P) { | ||
if (P[0] === '_') return | ||
if (trackerConstructors.filter(function (C) { return C === P }).length) return | ||
if (tracker[P]) return | ||
if (typeof log[P] !== 'function') return | ||
var func = log[P] | ||
tracker[P] = function () { | ||
return func.apply(log, arguments) | ||
} | ||
}) | ||
// if the new tracker is a group, make sure any subtrackers get | ||
// mixed in too | ||
if (tracker instanceof Progress.TrackerGroup) { | ||
trackerConstructors.forEach(function (C) { | ||
var func = tracker[C] | ||
tracker[C] = function () { return mixinLog(func.apply(tracker, arguments)) } | ||
}) | ||
} | ||
return tracker | ||
} | ||
// Add tracker constructors to the top level log object | ||
trackerConstructors.forEach(function (C) { | ||
log[C] = function () { return mixinLog(this.tracker[C].apply(this.tracker, arguments)) } | ||
}) | ||
log.clearProgress = function () { | ||
if (!this.progressEnabled) return | ||
this.gauge.hide() | ||
} | ||
log.showProgress = function (name) { | ||
if (!this.progressEnabled) return | ||
this.gauge.show(name, this.tracker.completed()) | ||
}.bind(log) // bind for use in tracker's on-change listener | ||
// temporarily stop emitting, but don't drop | ||
@@ -38,2 +115,3 @@ log.pause = function () { | ||
}, this) | ||
if (this.progressEnabled) this.enableProgress() | ||
} | ||
@@ -93,2 +171,3 @@ | ||
} | ||
if (this.progressEnabled) this.gauge.pulse(m.prefix) | ||
var l = this.levels[m.level] | ||
@@ -101,2 +180,3 @@ if (l === undefined) return | ||
var disp = log.disp[m.level] || m.level | ||
this.clearProgress() | ||
m.message.split(/\r?\n/).forEach(function (line) { | ||
@@ -113,2 +193,3 @@ if (this.heading) { | ||
}, this) | ||
this.showProgress() | ||
} | ||
@@ -120,2 +201,7 @@ | ||
this.cursor = ansi(this.stream, { enabled: colorEnabled }) | ||
var options = {} | ||
if (unicodeEnabled != null) { | ||
options.theme = unicodeEnabled ? Gauge.unicode : Gauge.ascii | ||
} | ||
this.gauge = new Gauge(options, this.cursor) | ||
} | ||
@@ -122,0 +208,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "logger for npm", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"repository": { | ||
@@ -16,3 +16,5 @@ "type": "git", | ||
"dependencies": { | ||
"ansi": "~0.3.0" | ||
"ansi": "~0.3.0", | ||
"are-we-there-yet": "~1.0.0", | ||
"gauge": "~1.0.2" | ||
}, | ||
@@ -19,0 +21,0 @@ "devDependencies": { |
@@ -83,2 +83,18 @@ # npmlog | ||
## log.enableProgress() | ||
Enable the display of log activity spinner and progress bar | ||
## log.disableProgress() | ||
Disable the display of a progress bar | ||
## log.enableUnicode() | ||
Force the unicode theme to be used for the progress bar. | ||
## log.disableUnicode() | ||
Disable the use of unicode in the progress bar. | ||
## log.pause() | ||
@@ -127,2 +143,24 @@ | ||
## log.newItem(name, todo, weight) | ||
* `name` {String} Optional; progress item name. | ||
* `todo` {Number} Optional; total amount of work to be done. Default 0. | ||
* `weight` {Number} Optional; the weight of this item relative to others. Default 1. | ||
This adds a new `are-we-there-yet` item tracker to the progress tracker. The | ||
object returned has the `log[level]` methods but is otherwise an | ||
`are-we-there-yet` `Tracker` object. | ||
## log.newStream(name, todo, weight) | ||
This adds a new `are-we-there-yet` stream tracker to the progress tracker. The | ||
object returned has the `log[level]` methods but is otherwise an | ||
`are-we-there-yet` `TrackerStream` object. | ||
## log.newGroup(name, weight) | ||
This adds a new `are-we-there-yet` tracker group to the progress tracker. The | ||
object returned has the `log[level]` methods but is otherwise an | ||
`are-we-there-yet` `TrackerGroup` object. | ||
# Events | ||
@@ -129,0 +167,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
27303
8
558
1
192
3
1
+ Addedare-we-there-yet@~1.0.0
+ Addedgauge@~1.0.2
+ Addedare-we-there-yet@1.0.6(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addedgauge@1.0.2(transitive)
+ Addedhas-unicode@1.0.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)