question-store
Advanced tools
Comparing version 0.3.1 to 0.3.2
62
index.js
@@ -37,6 +37,2 @@ /*! | ||
if (!this.options.name && !this.options.dest) { | ||
throw new Error('expected "options.name" or "options.dest" to be a string'); | ||
} | ||
this.inquirer = this.options.inquirer || utils.inquirer; | ||
@@ -50,2 +46,6 @@ this.enqueued = false; | ||
this.data = {}; | ||
if (!this.options.storeName && !this.options.dest) { | ||
this.option('storeName', utils.project(this.cwd)); | ||
} | ||
use(this); | ||
@@ -126,2 +126,18 @@ } | ||
/** | ||
* Returns true if `questions.cache` or `questions.groups` has | ||
* question `name`. | ||
* | ||
* ```js | ||
* var name = questions.has('name'); | ||
* //=> true | ||
* ``` | ||
* @return {String} The name of the question to check | ||
* @api public | ||
*/ | ||
Questions.prototype.has = function(name) { | ||
return !!(this.cache[name] || this.groups[name]); | ||
}; | ||
/** | ||
* Delete the answer for question `name` for the current (or given) locale. | ||
@@ -308,6 +324,6 @@ * | ||
var opts = utils.extend({}, this.options, options); | ||
opts.dest = this.dest; | ||
opts.cwd = this.cwd; | ||
var question = new Question(name, val, opts); | ||
question.dest = this.dest; | ||
question.cwd = this.cwd; | ||
this.emit('set', question.name, question); | ||
@@ -496,12 +512,9 @@ this.cache[question.name] = question; | ||
names = names || Object.keys(this.cache); | ||
var questions = this.buildQueue(names, opts.locale); | ||
var self = this; | ||
// force exit if "ctrl+c" is pressed | ||
utils.forceExit(); | ||
setImmediate(function() { | ||
utils.async.reduce(questions, {}, function(answers, question, next) { | ||
var key = question.name; | ||
self.emit('ask', key, question, answers); | ||
@@ -539,7 +552,12 @@ | ||
while (++i < len) { | ||
var key = keys[i]; | ||
if (utils.isObject(key) && key.isQuestion) { | ||
if (queue.indexOf(key.name) === -1) { | ||
queue.push(key.name); | ||
arr.push(key); | ||
var val = keys[i]; | ||
if (typeof val === 'string') { | ||
val = this.get(val); | ||
} | ||
if (utils.isObject(val) && val.isQuestion) { | ||
if (queue.indexOf(val.name) === -1) { | ||
queue.push(val.name); | ||
arr.push(val); | ||
} | ||
@@ -551,3 +569,3 @@ continue; | ||
var name = this.queue[j]; | ||
if (utils.hasKey(key, name)) { | ||
if (utils.hasKey(val, name)) { | ||
var question = this.get(name); | ||
@@ -662,2 +680,8 @@ | ||
if (this.options.storeName) { | ||
var dir = utils.resolveDir('~/answers'); | ||
var dest = path.resolve(dir, this.options.storeName); | ||
return (this.paths.dest = dest); | ||
} | ||
if (this.options.dest) { | ||
@@ -667,6 +691,2 @@ var dest = path.resolve(utils.resolveDir(this.options.dest)); | ||
} | ||
var name = path.join(utils.gm, this.options.name, 'answers'); | ||
var dest = path.resolve(utils.resolveDir(name)); | ||
return (this.paths.dest = dest); | ||
} | ||
@@ -673,0 +693,0 @@ }); |
@@ -288,2 +288,3 @@ /*! | ||
set: function(dest) { | ||
this.answer.dest = dest; | ||
this.cache.dest = dest; | ||
@@ -296,3 +297,5 @@ }, | ||
var dest = utils.resolveDir(this.options.dest || '~/answers'); | ||
return (this.cache.dest = dest); | ||
this.answer.dest = dest; | ||
this.cache.dest = dest; | ||
return dest; | ||
} | ||
@@ -299,0 +302,0 @@ }); |
@@ -14,2 +14,3 @@ 'use strict'; | ||
require('extend-shallow', 'extend'); | ||
require('project-name', 'project'); | ||
require('answer-store', 'Answer'); | ||
@@ -16,0 +17,0 @@ require('isobject', 'isObject'); |
{ | ||
"name": "question-store", | ||
"description": "Ask questions, persist the answers. Basic support for i18n and storing answers based on current working directory.", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"homepage": "https://github.com/jonschlinkert/question-store", | ||
@@ -37,2 +37,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"option-cache": "^3.2.0", | ||
"project-name": "^0.2.3", | ||
"resolve-dir": "^0.1.0", | ||
@@ -39,0 +40,0 @@ "set-value": "^0.3.2", |
@@ -18,2 +18,4 @@ # question-store [![NPM version](https://img.shields.io/npm/v/question-store.svg)](https://www.npmjs.com/package/question-store) | ||
_(TOC generated by [verb](https://github.com/verbose/verb))_ | ||
## Install | ||
@@ -109,4 +111,17 @@ | ||
### [.del](index.js#L134) | ||
### [.has](index.js#L135) | ||
Returns true if `questions.cache` or `questions.groups` has question `name`. | ||
* `returns` **{String}**: The name of the question to check | ||
**Example** | ||
```js | ||
var name = questions.has('name'); | ||
//=> true | ||
``` | ||
### [.del](index.js#L150) | ||
Delete the answer for question `name` for the current (or given) locale. | ||
@@ -125,3 +140,3 @@ | ||
### [.getAnswer](index.js#L171) | ||
### [.getAnswer](index.js#L187) | ||
@@ -150,3 +165,3 @@ Get the answer for question `name` at the current cwd. | ||
### [.getDefaultAnswer](index.js#L197) | ||
### [.getDefaultAnswer](index.js#L213) | ||
@@ -172,3 +187,3 @@ Get the default answer object for question `name` for the current locale. Optionally specify a locale to get the default answer for that locale. | ||
### [.isAnswered](index.js#L216) | ||
### [.isAnswered](index.js#L232) | ||
@@ -188,3 +203,3 @@ Return true if question `name` has been answered for the current locale and the current working directory. | ||
### [.setData](index.js#L234) | ||
### [.setData](index.js#L250) | ||
@@ -206,3 +221,3 @@ Set data to be used for answering questions, or as default answers when `force` is true. | ||
### [.hasData](index.js#L254) | ||
### [.hasData](index.js#L270) | ||
@@ -222,3 +237,3 @@ Return true if property `key` has a value on `questions.data`. | ||
### [.getData](index.js#L271) | ||
### [.getData](index.js#L287) | ||
@@ -240,3 +255,3 @@ Get the value of property `key` from `questions.data`. | ||
### [.question](index.js#L287) | ||
### [.question](index.js#L303) | ||
@@ -256,3 +271,3 @@ Get the `question` instance stored for the given `name`. This is the entire `Question` object, with all answers for all locales and directories. | ||
### [.delQuestion](index.js#L328) | ||
### [.delQuestion](index.js#L344) | ||
@@ -271,3 +286,3 @@ Delete a question. | ||
### [.getGroup](index.js#L396) | ||
### [.getGroup](index.js#L412) | ||
@@ -298,3 +313,3 @@ Get a group with the given `key`. If `key` has a dot, only the substring before the dot is used for the lookup. | ||
### [.deleteAll](index.js#L410) | ||
### [.deleteAll](index.js#L426) | ||
@@ -313,3 +328,3 @@ Delete answers for all questions for the current (or given) locale. | ||
### [.erase](index.js#L428) | ||
### [.erase](index.js#L444) | ||
@@ -328,3 +343,3 @@ Erase all answers for question `name` from the file system. | ||
### [.ask](index.js#L473) | ||
### [.ask](index.js#L489) | ||
@@ -347,3 +362,3 @@ Ask one or more questions, with the given `options` and callback. | ||
### [.getIndex](index.js#L576) | ||
### [.getIndex](index.js#L594) | ||
@@ -364,3 +379,3 @@ Get a the index of question `name` from the queue. | ||
### [.unqueue](index.js#L621) | ||
### [.unqueue](index.js#L639) | ||
@@ -569,2 +584,2 @@ Remove a question from the queue. | ||
_This file was generated by [verb](https://github.com/verbose/verb) on December 13, 2015._ | ||
_This file was generated by [verb](https://github.com/verbose/verb) on December 15, 2015._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41077
1047
568
17
+ Addedproject-name@^0.2.3
+ Addedcwd@0.9.1(transitive)
+ Addedfile-name@0.1.0(transitive)
+ Addedfind-file-up@0.1.3(transitive)
+ Addedfind-pkg@0.1.2(transitive)
+ Addedfs-exists-sync@0.1.0(transitive)
+ Addedgit-config-path@1.0.1(transitive)
+ Addedgit-repo-name@0.6.0(transitive)
+ Addedparse-git-config@1.1.1(transitive)
+ Addedproject-name@0.2.6(transitive)
+ Addedremote-origin-url@0.5.3(transitive)