UNPKG

1.17 kBJavaScriptView Raw
1
2// initialize a package.json file
3
4module.exports = init
5
6var log = require("npmlog")
7 , npm = require("./npm.js")
8 , initJson = require("init-package-json")
9
10init.usage = "npm init [--force/-f]"
11
12function init (args, cb) {
13 var dir = process.cwd()
14 log.pause()
15 npm.spinner.stop()
16 var initFile = npm.config.get("init-module")
17 if (!initJson.yes(npm.config)) {
18 console.log(
19 ["This utility will walk you through creating a package.json file."
20 ,"It only covers the most common items, and tries to guess sane defaults."
21 ,""
22 ,"See `npm help json` for definitive documentation on these fields"
23 ,"and exactly what they do."
24 ,""
25 ,"Use `npm install <pkg> --save` afterwards to install a package and"
26 ,"save it as a dependency in the package.json file."
27 ,""
28 ,"Press ^C at any time to quit."
29 ].join("\n"))
30 }
31 initJson(dir, initFile, npm.config, function (er, data) {
32 log.resume()
33 log.silly("package data", data)
34 if (er && er.message === "canceled") {
35 log.warn("init", "canceled")
36 return cb(null, data)
37 }
38 log.info("init", "written successfully")
39 cb(er, data)
40 })
41}