diff options
author | isaacs <i@izs.me> | 2010-10-29 05:34:34 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-10-29 05:34:34 +0400 |
commit | af9302894ee1eabfaff8cdc1424c215c45b48a0a (patch) | |
tree | 97d7a8962dfc06d98c2770c65f1387e8bb542556 /lib/init.js | |
parent | ed004e0817334c58d7a56fd0bbdeca048783f29b (diff) |
refactor output to go through central module
This is the dramatic refactor which was alluded to in ed004e0.
1. All output goes through a central module.
2. Callbacks are called when data is flushed, but only ever called once
3. Set "outfd" and "logfd" to direct output and error to different places,
or set to a writable stream when using npm programmatically.
4. Clean up the many varied ways to write data to the console.
5. Set colors smarter, and allow overriding by setting the "color" config.
Diffstat (limited to 'lib/init.js')
-rw-r--r-- | lib/init.js | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/init.js b/lib/init.js index 365dcb6e3..705077486 100644 --- a/lib/init.js +++ b/lib/init.js @@ -12,6 +12,7 @@ var prompt = require("./utils/prompt") , semver = require("./utils/semver") , log = require("./utils/log") , npm = require("../npm") + , output = require("./utils/output") init.usage = "npm init [folder]" @@ -34,14 +35,15 @@ function init (args, cb) { } function init_ (data, folder, cb) { var dl - process.stdout.write - (["This utility will walk you through creating a package.json file." - ,"It only covers the most common items, and tries to guess sane defaults." - ,"See `npm help json` for definitive documentation on these fields" - ,"and exactly what they do." - ,"Press ^C at any time to quit." - ,"" - ].join("\n")) + , outfd = npm.config.get("outfd") + output.write(outfd, + ["This utility will walk you through creating a package.json file." + ,"It only covers the most common items, and tries to guess sane defaults." + ,"See `npm help json` for definitive documentation on these fields" + ,"and exactly what they do." + ,"Press ^C at any time to quit." + ,"" + ].join("\n")) promiseChain(cb) ( prompt , ["Package name: ", defaultName(folder, data)] @@ -98,7 +100,6 @@ function init_ (data, folder, cb) { data.main = m } ) - (log.info, ["still here", "ok"]) ( defaultLib, [data, folder], function (d) { dl = d } ) ( function (cb) { prompt("Which folder do your modules live in: ", dl, cb) @@ -144,8 +145,7 @@ function init_ (data, folder, cb) { + "\n\n" + str + "\n\n" - if (!process.stdout.write(msg)) process.stdout.on("drain", cb) - else cb() + output.write(outfd, msg, cb) }) (function (cb) { prompt("\nIs this ok? ", "yes", function (er, ok) { |