Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-06-06 13:40:04 +0400
committerisaacs <i@izs.me>2012-06-06 13:40:04 +0400
commit0cf98d9542e8b7f004f0d98221942e3e1173612a (patch)
treea195e771ec88d206dca6e577e421a3d1fc658c19 /node_modules/npmlog
parenta41d0c91054cfa896ffb0a5366a30f206cfa2feb (diff)
Add npmlog and ansi as deps
Diffstat (limited to 'node_modules/npmlog')
-rw-r--r--node_modules/npmlog/README.md150
-rw-r--r--node_modules/npmlog/log.js146
-rw-r--r--node_modules/npmlog/package.json38
3 files changed, 334 insertions, 0 deletions
diff --git a/node_modules/npmlog/README.md b/node_modules/npmlog/README.md
new file mode 100644
index 000000000..590d1c0de
--- /dev/null
+++ b/node_modules/npmlog/README.md
@@ -0,0 +1,150 @@
+# npmlog
+
+The logger util that npm uses.
+
+This logger is very basic. It does the logging for npm. It supports
+custom levels and colored output.
+
+By default, logs are written to stderr. If you want to send log messages
+to outputs other than streams, then you can change the `log.stream`
+member, or you can just listen to the events that it emits, and do
+whatever you want with them.
+
+# Basic Usage
+
+```
+var log = require('npmlog')
+
+// additional stuff ---------------------------+
+// message ----------+ |
+// prefix ----+ | |
+// level -+ | | |
+// v v v v
+ log.info('fyi', 'I have a kitty cat: %j', myKittyCat)
+```
+
+## log.level
+
+* {String}
+
+The level to display logs at. Any logs at or above this level will be
+displayed. The special level `silent` will prevent anything from being
+displayed ever.
+
+## log.record
+
+* {Array}
+
+An array of all the log messages that have been entered.
+
+## log.maxRecordSize
+
+* {Number}
+
+The maximum number of records to keep. If log.record gets bigger than
+10% over this value, then it is sliced down to 90% of this value.
+
+The reason for the 10% window is so that it doesn't have to resize a
+large array on every log entry.
+
+## log.prefixStyle
+
+* {Object}
+
+A style object that specifies how prefixes are styled. (See below)
+
+## log.headingStyle
+
+* {Object}
+
+A style object that specifies how the heading is styled. (See below)
+
+## log.heading
+
+* {String} Default: ""
+
+If set, a heading that is printed at the start of every line.
+
+## log.stream
+
+* {Stream} Default: `process.stderr`
+
+The stream where output is written.
+
+## log.enableColor()
+
+Force colors to be used on all messages, regardless of the output
+stream.
+
+## log.disableColor()
+
+Disable colors on all messages.
+
+## log.pause()
+
+Stop emitting messages to the stream, but do not drop them.
+
+## log.resume()
+
+Emit all buffered messages that were written while paused.
+
+## log.log(level, prefix, message, ...)
+
+* `level` {String} The level to emit the message at
+* `prefix` {String} A string prefix. Set to "" to skip.
+* `message...` Arguments to `util.format`
+
+Emit a log message at the specified level.
+
+## log[level](prefix, message, ...)
+## log.silly(prefix, message, ...)
+## log.verbose(prefix, message, ...)
+## log.info(prefix, message, ...)
+## log.http(prefix, message, ...)
+## log.warn(prefix, message, ...)
+## log.error(prefix, message, ...)
+
+Like `log.log(level, prefix, message, ...)`. In this way, each level is
+given a shorthand, so you can do `log.info(prefix, message)`.
+
+## log.addLevel(level, n, style, disp)
+
+* `level` {String} Level indicator
+* `n` {Number} The numeric level
+* `style` {Object} Object with fg, bg, inverse, etc.
+* `disp` {String} Optional replacement for `level` in the output.
+
+Sets up a new level with a shorthand function and so forth.
+
+Note that if the number is `Infinity`, then setting the level to that
+will cause all log messages to be suppressed. If the number is
+`-Infinity`, then the only way to show it is to enable all log messages.
+
+# Events
+
+Events are all emitted with the message object.
+
+* `log` Emitted for all messages
+* `log.<level>` Emitted for all messages with the `<level>` level.
+* `<prefix>` Messages with prefixes also emit their prefix as an event.
+
+# Style Objects
+
+Style objects can have the following fields:
+
+* `fg` {String} Color for the foreground text
+* `bg` {String} Color for the background
+* `bold`, `inverse`, `underline` {Boolean} Set the associated property
+* `bell` {Boolean} Make a noise (This is pretty annoying, probably.)
+
+# Message Objects
+
+Every log event is emitted with a message object, and the `log.record`
+list contains all of them that have been created. They have the
+following fields:
+
+* `id` {Number}
+* `level` {String}
+* `prefix` {String}
+* `message` {String} Result of `util.format()`
+* `messageRaw` {Array} Arguments to `util.format()`
diff --git a/node_modules/npmlog/log.js b/node_modules/npmlog/log.js
new file mode 100644
index 000000000..aef6c9d82
--- /dev/null
+++ b/node_modules/npmlog/log.js
@@ -0,0 +1,146 @@
+var EE = require('events').EventEmitter
+var log = exports = module.exports = new EE
+var util = require('util')
+
+var ansi = require('ansi')
+log.cursor = ansi(process.stderr)
+log.stream = process.stderr
+
+// by default, let ansi decide based on tty-ness.
+var colorEnabled = undefined
+log.enableColor = function () {
+ colorEnabled = true
+ this.cursor.enabled = true
+}
+log.disableColor = function () {
+ colorEnabled = false
+ this.cursor.enabled = false
+}
+
+// default level
+log.level = 'info'
+
+// temporarily stop emitting, but don't drop
+log.pause = function () {
+ this._paused = true
+}
+
+log.resume = function () {
+ if (!this._paused) return
+ this._paused = false
+
+ var b = this._buffer
+ this._buffer = []
+ b.forEach(function (m) {
+ this.emitLog(m)
+ }, this)
+}
+
+log._buffer = []
+
+var id = 0
+log.record = []
+log.maxRecordSize = 10000
+log.log = function (lvl, prefix, message) {
+ var l = this.levels[lvl]
+ if (l === undefined) {
+ return this.emit('error', new Error(util.format(
+ 'Undefined log level: %j', lvl)))
+ }
+
+ var a = new Array(arguments.length - 2)
+ for (var i = 2; i < arguments.length; i ++) {
+ a[i-2] = arguments[i]
+ }
+ message = util.format.apply(util, a)
+
+ var m = { id: id++,
+ level: lvl,
+ prefix: prefix,
+ message: message,
+ messageRaw: a }
+
+ this.emit('log', m)
+ this.emit('log.' + lvl, m)
+ if (m.prefix) this.emit(m.prefix, m)
+
+ this.record.push(m)
+ var mrs = this.maxRecordSize
+ var n = this.record.length - mrs
+ if (n > mrs / 10) {
+ var newSize = Math.floor(mrs * 0.9)
+ this.record = this.record.slice(-1 * newSize)
+ }
+
+ this.emitLog(m)
+}
+
+log.emitLog = function (m) {
+ if (this._paused) {
+ this._buffer.push(m)
+ return
+ }
+ var l = this.levels[m.level]
+ if (l === undefined) return
+ if (l < this.levels[this.level]) return
+ if (l > 0 && !isFinite(l)) return
+
+ var style = log.style[m.level]
+ var disp = log.disp[m.level] || m.level
+ m.message.split(/\r?\n/).forEach(function (line) {
+ if (this.heading) {
+ this.write(this.heading, this.headingStyle)
+ this.write(' ')
+ }
+ this.write(disp, log.style[m.level])
+ var p = m.prefix || ''
+ if (p) this.write(' ')
+ this.write(p, this.prefixStyle)
+ this.write(' ' + line + '\n')
+ }, this)
+}
+
+log.write = function (msg, style) {
+ if (!this.cursor) return
+ if (this.stream !== this.cursor.stream) {
+ this.cursor = ansi(this.stream, { enabled: colorEnabled })
+ }
+
+ style = style || {}
+ if (style.fg) this.cursor.fg[style.fg]()
+ if (style.bg) this.cursor.bg[style.bg]()
+ if (style.bold) this.cursor.bold()
+ if (style.underline) this.cursor.underline()
+ if (style.inverse) this.cursor.inverse()
+ if (style.beep) this.cursor.beep()
+ this.cursor.write(msg).reset()
+}
+
+log.addLevel = function (lvl, n, style, disp) {
+ if (!disp) disp = lvl
+ this.levels[lvl] = n
+ this.style[lvl] = style
+ if (!this[lvl]) this[lvl] = function () {
+ var a = new Array(arguments.length + 1)
+ a[0] = lvl
+ for (var i = 0; i < arguments.length; i ++) {
+ a[i + 1] = arguments[i]
+ }
+ return this.log.apply(this, a)
+ }
+ this.disp[lvl] = disp
+}
+
+log.prefixStyle = { fg: 'magenta' }
+log.headingStyle = { fg: 'white', bg: 'black' }
+
+log.style = {}
+log.levels = {}
+log.disp = {}
+log.addLevel('silly', -Infinity, { inverse: true }, 'sill')
+log.addLevel('verbose', 1000, { fg: 'blue', bg: 'black' }, 'verb')
+log.addLevel('info', 2000, { fg: 'green', inverse: true })
+log.addLevel('http', 3000, { fg: 'green' })
+log.addLevel('warn', 4000, { fg: 'black', bg: 'red' }, 'WARN')
+log.addLevel('error', 5000, { fg: 'red', bg: 'black' }, 'ERR!')
+log.addLevel('silent', Infinity)
diff --git a/node_modules/npmlog/package.json b/node_modules/npmlog/package.json
new file mode 100644
index 000000000..39b724741
--- /dev/null
+++ b/node_modules/npmlog/package.json
@@ -0,0 +1,38 @@
+{
+ "author": {
+ "name": "Isaac Z. Schlueter",
+ "email": "i@izs.me",
+ "url": "http://blog.izs.me/"
+ },
+ "name": "npmlog",
+ "description": "logger for npm",
+ "version": "0.0.1",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/isaacs/npmlog.git"
+ },
+ "main": "log.js",
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "dependencies": {
+ "ansi": "~0.1.2"
+ },
+ "devDependencies": {
+ "tap": ""
+ },
+ "_npmUser": {
+ "name": "isaacs",
+ "email": "i@izs.me"
+ },
+ "_id": "npmlog@0.0.1",
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ },
+ "_engineSupported": true,
+ "_npmVersion": "1.1.24",
+ "_nodeVersion": "v0.7.10-pre",
+ "_defaultsLoaded": true,
+ "_from": "npmlog"
+}