Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow for a config object with a 'get' function #5

Closed
wants to merge 1 commit into from

2 participants

@mfncooper
Collaborator

See discussion at npm/npm#3379.

@isaacs
Owner

Thanks! Landed with a slight modification to add toJSON: function() { return data } so that the plane-jane config jsons the same as the original data when passed around. (Mostly just to make the test pass)

@isaacs isaacs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 29, 2013
  1. @mfncooper
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 4 deletions.
  1. +4 −4 default-input.js
  2. +8 −0 init-package-json.js
View
8 default-input.js
@@ -167,11 +167,11 @@ if (!package.keywords) {
}
if (!package.author) {
- exports.author = config['init.author.name']
+ exports.author = config.get('init.author.name')
? {
- "name" : config['init.author.name'],
- "email" : config['init.author.email'],
- "url" : config['init.author.url']
+ "name" : config.get('init.author.name'),
+ "email" : config.get('init.author.email'),
+ "url" : config.get('init.author.url')
}
: prompt('author')
}
View
8 init-package-json.js
@@ -17,6 +17,14 @@ var readJson = require('read-package-json')
function init (dir, input, config, cb) {
if (typeof config === 'function')
cb = config, config = {}
+
+ // accept either a plain-jane object, or a config object
+ // with a "get" method.
+ if (typeof config.get !== 'function') {
+ var data = config
+ config = { get: function (k) { return data[k] } }
+ }
+
var package = path.resolve(dir, 'package.json')
input = path.resolve(input)
var pkg
Something went wrong with that request. Please try again.