diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-09-19 10:35:35 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-09-19 10:36:08 +0400 |
commit | 5e8fff3f836e9ace5689d3eccf45c3d9e09cffac (patch) | |
tree | 7afbe2b6bdf4a154efa5d8dbacdf6acffff7f2aa /node_modules/init-package-json | |
parent | fb5724fd98e1509c939693568df83d11417ea337 (diff) |
init-package-json@1.1.0
part of #5925
Diffstat (limited to 'node_modules/init-package-json')
4 files changed, 59 insertions, 49 deletions
diff --git a/node_modules/init-package-json/default-input.js b/node_modules/init-package-json/default-input.js index 8b335f967..721da45b7 100644 --- a/node_modules/init-package-json/default-input.js +++ b/node_modules/init-package-json/default-input.js @@ -38,11 +38,14 @@ function readDeps (test) { return function (cb) { }) }} +var name = package.name || basename +exports.name = yes ? name : prompt('name', name) + +var version = package.version || config.get('init.version') || '1.0.0' +exports.version = yes ? version : prompt('version', version) -exports.name = prompt('name', package.name || basename) -exports.version = prompt('version', package.version || config.get('init.version') || '1.0.0') if (!package.description) { - exports.description = prompt('description') + exports.description = yes ? '' : prompt('description') } if (!package.main) { @@ -63,7 +66,8 @@ if (!package.main) { else f = f[0] - return cb(null, prompt('entry point', f || 'index.js')) + var index = f || 'index.js' + return cb(null, yes ? index : prompt('entry point', index)) }) } } @@ -121,26 +125,32 @@ function setupScripts (d, cb) { function tx (test) { return test || notest } - if (!s.test || s.test === notest) { - if (d.indexOf('tap') !== -1) - s.test = prompt('test command', 'tap test/*.js', tx) - else if (d.indexOf('expresso') !== -1) - s.test = prompt('test command', 'expresso test', tx) - else if (d.indexOf('mocha') !== -1) - s.test = prompt('test command', 'mocha', tx) - else - s.test = prompt('test command', tx) + var commands = { + 'tap':'tap test/*.js' + , 'expresso':'expresso test' + , 'mocha':'mocha' + } + var command + Object.keys(commands).forEach(function (k) { + if (d.indexOf(k) !== -1) command = commands[k] + }) + var ps = 'test command' + if (yes) { + s.test = command || notest + } else { + s.test = command ? prompt(ps, command, tx) : prompt(ps, tx) + } } - return cb(null, s) } if (!package.repository) { exports.repository = function (cb) { fs.readFile('.git/config', 'utf8', function (er, gconf) { - if (er || !gconf) return cb(null, prompt('git repository')) - + if (er || !gconf) { + return cb(null, yes ? '' : prompt('git repository')) + } gconf = gconf.split(/\r?\n/) var i = gconf.indexOf('[remote "origin"]') if (i !== -1) { @@ -152,13 +162,13 @@ if (!package.repository) { if (u && u.match(/^git@github.com:/)) u = u.replace(/^git@github.com:/, 'https://github.com/') - return cb(null, prompt('git repository', u)) + return cb(null, yes ? u : prompt('git repository', u)) }) } } if (!package.keywords) { - exports.keywords = prompt('keywords', function (s) { + exports.keywords = yes ? '' : prompt('keywords', function (s) { if (!s) return undefined if (Array.isArray(s)) s = s.join(' ') if (typeof s !== 'string') return s @@ -176,6 +186,5 @@ if (!package.author) { : prompt('author') } -exports.license = prompt('license', package.license || - config.get('init.license') || - 'ISC') +var license = package.license || config.get('init.license') || 'ISC' +exports.license = yes ? license : prompt('license', license) diff --git a/node_modules/init-package-json/init-package-json.js b/node_modules/init-package-json/init-package-json.js index 2600e77b0..cac761c39 100644 --- a/node_modules/init-package-json/init-package-json.js +++ b/node_modules/init-package-json/init-package-json.js @@ -1,5 +1,6 @@ module.exports = init +module.exports.yes = yes var PZ = require('promzard').PromZard var path = require('path') @@ -14,6 +15,13 @@ var read = require('read') // readJson.extras(file, data, cb) var readJson = require('read-package-json') +function yes (conf) { + return !!( + conf.get('yes') || conf.get('y') || + conf.get('force') || conf.get('f') + ) +} + function init (dir, input, config, cb) { if (typeof config === 'function') cb = config, config = {} @@ -35,7 +43,7 @@ function init (dir, input, config, cb) { var package = path.resolve(dir, 'package.json') input = path.resolve(input) var pkg - var ctx = {} + var ctx = { yes: yes(config) } var es = readJson.extraSet readJson.extraSet = es.filter(function (fn) { @@ -91,14 +99,21 @@ function init (dir, input, config, cb) { delete pkg.repository var d = JSON.stringify(pkg, null, 2) + '\n' + function write (yes) { + fs.writeFile(package, d, 'utf8', function (er) { + if (!er && yes) console.log('Wrote to %s:\n\n%s\n', package, d) + return cb(er, pkg) + }) + } + if (ctx.yes) { + return write(true) + } console.log('About to write to %s:\n\n%s\n', package, d) read({prompt:'Is this ok? ', default: 'yes'}, function (er, ok) { if (!ok || ok.toLowerCase().charAt(0) !== 'y') { console.log('Aborted.') } else { - fs.writeFile(package, d, 'utf8', function (er) { - return cb(er, pkg) - }) + return write() } }) }) diff --git a/node_modules/init-package-json/node_modules/promzard/package.json b/node_modules/init-package-json/node_modules/promzard/package.json index 703b34ac4..f66857539 100644 --- a/node_modules/init-package-json/node_modules/promzard/package.json +++ b/node_modules/init-package-json/node_modules/promzard/package.json @@ -27,7 +27,7 @@ "homepage": "https://github.com/isaacs/promzard", "_id": "promzard@0.2.2", "_shasum": "918b9f2b29458cb001781a8856502e4a79b016e0", - "_from": "promzard@>=0.2.0-0 <0.3.0-0", + "_from": "promzard@>=0.2.0 <0.3.0", "_npmVersion": "1.4.10", "_npmUser": { "name": "isaacs", @@ -44,5 +44,6 @@ "tarball": "http://registry.npmjs.org/promzard/-/promzard-0.2.2.tgz" }, "directories": {}, - "_resolved": "https://registry.npmjs.org/promzard/-/promzard-0.2.2.tgz" + "_resolved": "https://registry.npmjs.org/promzard/-/promzard-0.2.2.tgz", + "readme": "ERROR: No README data found!" } diff --git a/node_modules/init-package-json/package.json b/node_modules/init-package-json/package.json index c716cd6e8..dc98eac23 100644 --- a/node_modules/init-package-json/package.json +++ b/node_modules/init-package-json/package.json @@ -1,6 +1,6 @@ { "name": "init-package-json", - "version": "1.0.1", + "version": "1.1.0", "main": "init-package-json.js", "scripts": { "test": "tap test/*.js" @@ -37,29 +37,14 @@ "prompt", "start" ], - "gitHead": "e1a5917ba1723ab5dcedacbffb5b10208d203e2f", + "readme": "# init-package-json\n\nA node module to get your node module started.\n\n## Usage\n\n```javascript\nvar init = require('init-package-json')\nvar path = require('path')\n\n// a path to a promzard module. In the event that this file is\n// not found, one will be provided for you.\nvar initFile = path.resolve(process.env.HOME, '.npm-init')\n\n// the dir where we're doin stuff.\nvar dir = process.cwd()\n\n// extra stuff that gets put into the PromZard module's context.\n// In npm, this is the resolved config object. Exposed as 'config'\n// Optional.\nvar configData = { some: 'extra stuff' }\n\n// Any existing stuff from the package.json file is also exposed in the\n// PromZard module as the `package` object. There will also be free\n// vars for:\n// * `filename` path to the package.json file\n// * `basename` the tip of the package dir\n// * `dirname` the parent of the package dir\n\ninit(dir, initFile, configData, function (er, data) {\n // the data's already been written to {dir}/package.json\n // now you can do stuff with it\n})\n```\n\nOr from the command line:\n\n```\n$ npm-init\n```\n\nSee [PromZard](https://github.com/isaacs/promzard) for details about\nwhat can go in the config file.\n", + "readmeFilename": "README.md", + "gitHead": "f6ced3cecbee6b4717624a6a905db3566100c90a", "bugs": { "url": "https://github.com/isaacs/init-package-json/issues" }, "homepage": "https://github.com/isaacs/init-package-json", - "_id": "init-package-json@1.0.1", - "_shasum": "c01b08cc90504ebc448d57b468e66fc08293e8a8", - "_from": "init-package-json@>=1.0.0-0 <1.1.0-0", - "_npmVersion": "2.0.0-beta.3", - "_npmUser": { - "name": "isaacs", - "email": "i@izs.me" - }, - "maintainers": [ - { - "name": "isaacs", - "email": "i@izs.me" - } - ], - "dist": { - "shasum": "c01b08cc90504ebc448d57b468e66fc08293e8a8", - "tarball": "http://registry.npmjs.org/init-package-json/-/init-package-json-1.0.1.tgz" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/init-package-json/-/init-package-json-1.0.1.tgz" + "_id": "init-package-json@1.1.0", + "_shasum": "fea80c641974421ddd4c6169c3a911118b116d5c", + "_from": "init-package-json@>=1.1.0 <1.2.0" } |