Skip to content

Commit

Permalink
Replace lib/utils/output.js with console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 16, 2012
1 parent 4431b14 commit 1977584
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 126 deletions.
13 changes: 6 additions & 7 deletions lib/bin.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module.exports = bin

var npm = require("./npm.js")
, output = require("./utils/output.js")

bin.usage = "npm bin\nnpm bin -g\n(just prints the bin folder)"

function bin (args, cb) {
var path = require("path")
, b = npm.bin
function bin (args, silent, cb) {
if (typeof cb !== "function") cb = silent, silent = false
var b = npm.bin
, PATH = (process.env.PATH || "").split(":")

output.write(b, function (er) { cb(er, b) })
if (!silent) console.log(b)
process.nextTick(cb.bind(this, null, b))

if (npm.config.get("global") && PATH.indexOf(b) === -1) {
output.write("(not in PATH env variable)"
,npm.config.get("logfd"))
npm.config.get("logstream").write("(not in PATH env variable)\n")
}
}
4 changes: 2 additions & 2 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var npm = require("./npm.js")
, cmdShim = require("./utils/cmd-shim.js")
, cmdShimIfExists = cmdShim.ifExists
, asyncMap = require("slide").asyncMap
, output = require("./utils/output.js")

module.exports = build
build.usage = "npm build <folder>\n(this is plumbing)"
Expand Down Expand Up @@ -150,7 +149,8 @@ function linkBins (pkg, folder, parent, gtop, cb) {
, out = npm.config.get("parseable")
? dest + "::" + src + ":BINFILE"
: dest + " -> " + src
output.write(out, cb)
console.log(out)
cb()
})
})
}, cb)
Expand Down
9 changes: 3 additions & 6 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ var mkdir = require("mkdirp")
, registry = npm.registry
, log = require("npmlog")
, path = require("path")
, output
, sha = require("./utils/sha.js")
, asyncMap = require("slide").asyncMap
, semver = require("semver")
Expand Down Expand Up @@ -145,19 +144,17 @@ function read (name, ver, forceBypass, cb) {

// npm cache ls [<path>]
function ls (args, cb) {
output = output || require("./utils/output.js")
args = args.join("/").split("@").join("/")
if (args.substr(-1) === "/") args = args.substr(0, args.length - 1)
var prefix = npm.config.get("cache")
if (0 === prefix.indexOf(process.env.HOME)) {
prefix = "~" + prefix.substr(process.env.HOME.length)
}
ls_(args, npm.config.get("depth"), function(er, files) {
output.write(files.map(function (f) {
console.log(files.map(function (f) {
return path.join(prefix, f)
}).join("\n").trim(), function (er) {
return cb(er, files)
})
}).join("\n").trim())
cb(er, files)
})
}

Expand Down
7 changes: 4 additions & 3 deletions lib/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ completion.usage = "npm completion >> ~/.bashrc\n"
+ "npm completion >> ~/.zshrc\n"
+ "source <(npm completion)"

var output = require("./utils/output.js")
, configDefs = require("./utils/config-defs.js")
var configDefs = require("./utils/config-defs.js")
, configTypes = configDefs.types
, shorthands = configDefs.shorthands
, nopt = require("nopt")
Expand Down Expand Up @@ -200,7 +199,9 @@ function wrapCb (cb, opts) { return function (er, compls) {
})
console.error([er && er.stack, compls, opts.partialWord])
if (er || compls.length === 0) return cb(er)
output.write(compls.join("\n"), 1, false, cb)

console.log(compls.join("\n"))
cb()
}}

// the current word has a dash. Return the config names,
Expand Down
10 changes: 6 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var ini = require("./utils/ini.js")
, exec = require("./utils/exec.js")
, fs = require("graceful-fs")
, dc
, output = require("./utils/output.js")
, types = require("./utils/config-defs.js").types

config.completion = function (opts, cb) {
Expand Down Expand Up @@ -140,7 +139,8 @@ function get (key, cb) {
if (key.charAt(0) === "_") {
return cb(new Error("---sekretz---"))
}
output.write(npm.config.get(key), cb)
console.log(npm.config.get(key))
cb()
}

function sort (a, b) {
Expand Down Expand Up @@ -273,7 +273,8 @@ function list (cb) {
+ "; HOME = " + process.env.HOME + eol
+ "; 'npm config ls -l' to show all defaults." + eol

return output.write(msg, cb)
console.log(msg)
cb()
}

var defaults = ini.defaultConfig
Expand All @@ -290,7 +291,8 @@ function list (cb) {
})
msg += eol

return output.write(msg, cb)
console.log(msg)
cb()
}

function unknown (action, cb) {
Expand Down
19 changes: 13 additions & 6 deletions lib/help-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module.exports = helpSearch

var fs = require("graceful-fs")
, output = require("./utils/output.js")
, path = require("path")
, asyncMap = require("slide").asyncMap
, cliDocsPath = path.join(__dirname, "..", "doc", "cli")
Expand Down Expand Up @@ -118,8 +117,8 @@ function helpSearch (args, silent, cb) {
}

if (results.length === 0) {
return output.write("No results for "
+ args.map(JSON.stringify).join(" "), cb)
console.log("No results for " + args.map(JSON.stringify).join(" "))
return cb()
}

// sort results by number of results found, then by number of hits
Expand Down Expand Up @@ -164,8 +163,15 @@ function helpSearch (args, silent, cb) {
})
out = newOut.join("")
}
out = out.split("\1").join("\033[31;40m")
.split("\2").join("\033[0m")
if (npm.config.get("color")) {
var color = "\033[31;40m"
, reset = "\033[0m"
} else {
var color = ""
, reset = ""
}
out = out.split("\1").join(color)
.split("\2").join(reset)
return out
}).join("\n").trim()
return out
Expand All @@ -179,7 +185,8 @@ function helpSearch (args, silent, cb) {
+ "(run with -l or --long to see more context)"
}

output.write(out.trim(), function (er) { cb(er, results) })
console.log(out.trim())
cb(null, results)
})

})
Expand Down
12 changes: 7 additions & 5 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var fs = require("graceful-fs")
, path = require("path")
, exec = require("./utils/exec.js")
, npm = require("./npm.js")
, output = require("./utils/output.js")
, log = require("npmlog")

function help (args, cb) {
Expand All @@ -35,7 +34,8 @@ function help (args, cb) {
) {
npm.config.set("loglevel", "silent")
log.level = "silent"
return output.write(npm.commands[section].usage, cb)
console.log(npm.commands[section].usage)
return cb()
}

var sectionPath = path.join( __dirname, "..", "man", "man" + num
Expand Down Expand Up @@ -67,7 +67,8 @@ function help (args, cb) {
if (!b) {
return cb(new Error("viewer=browser and no browser set."))
}
output.write("Opening HTML in default browser...", cb)
console.log("Opening HTML in default browser...")
process.nextTick(cb)
// windows is SO weird.
if (process.platform === "win32") {
exec("cmd", ["/c", htmlPath], env, false, function () {})
Expand All @@ -85,7 +86,7 @@ function help (args, cb) {
if (er) return cb(er)
npm.config.set("loglevel", "silent")
log.level = "silent"
output.write
console.log
( ["\nUsage: npm <command>"
, ""
, "where <command> is one of:"
Expand All @@ -104,7 +105,8 @@ function help (args, cb) {
, "Config info can be viewed via: npm help config"
, ""
, "npm@" + npm.version + " " + path.dirname(__dirname)
].join("\n"), function () { cb(er) })
].join("\n"))
cb(er)
})
}

Expand Down
13 changes: 3 additions & 10 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var npm = require("./npm.js")
, cache = require("./cache.js")
, asyncMap = require("slide").asyncMap
, chain = require("slide").chain
, output
, url = require("url")
, mkdir = require("mkdirp")
, lifecycle = require("./utils/lifecycle.js")
Expand All @@ -75,18 +74,12 @@ function install (args, cb_) {
function cb (er, installed) {
if (er) return cb_(er)

output = output || require("./utils/output.js")

var tree = treeify(installed)
, pretty = prettify(tree, installed).trim()

if (pretty) output.write(pretty, afterWrite)
else afterWrite()

function afterWrite (er) {
if (er) return cb_(er)
save(where, installed, tree, pretty, cb_)
}
if (pretty) console.log(pretty)
if (er) return cb_(er)
save(where, installed, tree, pretty, cb_)
}

// the /path/to/node_modules/..
Expand Down
8 changes: 4 additions & 4 deletions lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var npm = require("./npm.js")
, chain = require("slide").chain
, path = require("path")
, rm = require("rimraf")
, output = require("./utils/output.js")
, build = require("./build.js")

module.exports = link
Expand Down Expand Up @@ -153,8 +152,8 @@ function resultPrinter (pkg, src, dest, rp, cb) {
return parseableOutput(dest, rp || src, cb)
}
if (rp === src) rp = null
output.write(where+" -> " + src
+(rp ? " -> " + rp: ""), cb)
console.log(where + " -> " + src + (rp ? " -> " + rp: ""))
cb()
}

function parseableOutput (dest, rp, cb) {
Expand All @@ -165,5 +164,6 @@ function parseableOutput (dest, rp, cb) {
// *just* print the target folder.
// However, we don't actually ever read the version number, so
// the second field is always blank.
output.write(dest + "::" + rp, cb)
console.log(dest + "::" + rp)
cb()
}
23 changes: 17 additions & 6 deletions lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = exports = ls

var npm = require("./npm.js")
, readInstalled = require("read-installed")
, output = require("./utils/output.js")
, log = require("npmlog")
, path = require("path")
, archy = require("archy")
Expand Down Expand Up @@ -58,7 +57,8 @@ function ls (args, silent, cb) {
} else if (data) {
out = makeArchy(bfs, long, dir)
}
output.write(out, function (er) { cb(er, data, lite) })
console.log(out)
cb(null, data, lite)
})
}

Expand Down Expand Up @@ -205,12 +205,17 @@ function makeArchy (data, long, dir) {
}

function makeArchy_ (data, long, dir, depth, parent, d) {
var color = npm.config.get("color")
if (typeof data === "string") {
if (depth < npm.config.get("depth")) {
// just missing
var p = parent.link || parent.path
log.warn("unmet dependency", "%s in %s", d+" "+data, p)
data = "\033[31;40mUNMET DEPENDENCY\033[0m " + d + " " + data
var unmet = "UNMET DEPENDENCY"
if (color) {
unmet = "\033[31;40m" + unmet + "\033[0m"
}
data = unmet + " " + d + " " + data
} else {
data = d+"@"+ data +" (max depth reached)"
}
Expand All @@ -221,17 +226,23 @@ function makeArchy_ (data, long, dir, depth, parent, d) {
// the top level is a bit special.
out.label = data._id || ""
if (data._found === true && data._id) {
out.label = "\033[33;40m" + out.label.trim() + "\033[m "
var pre = color ? "\033[33;40m" : ""
, post = color ? "\033[m" : ""
out.label = pre + out.label.trim() + post + " "
}
if (data.link) out.label += " -> " + data.link

if (data.invalid) {
if (data.realName !== data.name) out.label += " ("+data.realName+")"
out.label += " \033[31;40minvalid\033[0m"
out.label += " " + (color ? "\033[31;40m" : "")
+ "invalid"
+ (color ? "\033[0m" : "")
}

if (data.extraneous && data.path !== dir) {
out.label += " \033[32;40mextraneous\033[0m"
out.label += " " + (color ? "\033[32;40m" : "")
+ "extraneous"
+ (color ? "\033[0m" : "")
}

if (long) {
Expand Down
7 changes: 3 additions & 4 deletions lib/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ function outdated (args, silent, cb) {
if (typeof cb !== "function") cb = silent, silent = false
var dir = path.resolve(npm.dir, "..")
outdated_(args, dir, {}, function (er, list) {
function cb_ (er) { if (typeof cb === "function") cb(er, list) }

if (er || silent) return cb_(er)
if (er || silent) return cb(er)
var outList = list.map(makePretty)
require("./utils/output.js").write(outList.join("\n"), cb_)
console.log(outList.join("\n"))
cb(null, list)
})
}

Expand Down
5 changes: 2 additions & 3 deletions lib/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ owner.completion = function (opts, cb) {
var npm = require("./npm.js")
, registry = npm.registry
, log = require("npmlog")
, output
, readJson = require("read-package-json")

function owner (args, cb) {
Expand All @@ -91,8 +90,8 @@ function ls (pkg, cb) {
var owners = data.maintainers
if (!owners || !owners.length) msg = "admin party!"
else msg = owners.map(function (o) { return o.name +" <"+o.email+">" }).join("\n")
output = output || require("./utils/output.js")
output.write(msg, function (er) { cb(er, owners) })
console.log(msg)
cb(er, owners)
})
}

Expand Down
Loading

0 comments on commit 1977584

Please sign in to comment.