Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Allow init without prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnisi authored and othiym23 committed Sep 19, 2014
1 parent 1259d85 commit fb5724f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
5 changes: 4 additions & 1 deletion doc/cli/npm-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ npm-init(1) -- Interactively create a package.json file

## SYNOPSIS

npm init
npm init [-f|--force|-y|--yes]

## DESCRIPTION

Expand All @@ -18,6 +18,9 @@ the options in there.
It is strictly additive, so it does not delete options from your package.json
without a really good reason to do so.

If you invoke it with `-f`, `--force`, `-y`, or `--yes`, it will use only
defaults and not prompt you for any options.

## SEE ALSO

* <https://github.com/isaacs/init-package-json>
Expand Down
40 changes: 20 additions & 20 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ var log = require("npmlog")
, npm = require("./npm.js")
, initJson = require("init-package-json")

init.usage = "npm init"
init.usage = "npm init [--force/-f]"

function init (args, cb) {
var dir = process.cwd()
log.pause()
npm.spinner.stop()
var initFile = npm.config.get('init-module')

console.log(
["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."
,""
,"Use `npm install <pkg> --save` afterwards to install a package and"
,"save it as a dependency in the package.json file."
,""
,"Press ^C at any time to quit."
].join("\n"))

var initFile = npm.config.get("init-module")
if (!initJson.yes(npm.config)) {
console.log(
["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."
,""
,"Use `npm install <pkg> --save` afterwards to install a package and"
,"save it as a dependency in the package.json file."
,""
,"Press ^C at any time to quit."
].join("\n"))
}
initJson(dir, initFile, npm.config, function (er, data) {
log.resume()
log.silly('package data', data)
log.info('init', 'written successfully')
if (er && er.message === 'canceled') {
log.warn('init', 'canceled')
log.silly("package data", data)
log.info("init", "written successfully")
if (er && er.message === "canceled") {
log.warn("init", "canceled")
return cb(null, data)
}
cb(er, data)
Expand Down

1 comment on commit fb5724f

@shime
Copy link

@shime shime commented on fb5724f Sep 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Please sign in to comment.