base-questions
Advanced tools
Comparing version 0.2.2 to 0.2.3
46
index.js
@@ -22,6 +22,9 @@ /*! | ||
if (app.hasQuestions) return; | ||
app.define('hasQuestions', true); | ||
function updateOpts() { | ||
var baseOpts = (base.options && base.options.questions) || {}; | ||
var appOpts = (app.options && app.options.questions) || {}; | ||
options = utils.extend({}, appOpts, baseOpts, options); | ||
options = utils.merge({}, appOpts, baseOpts, options); | ||
} | ||
@@ -45,5 +48,2 @@ | ||
questions.setData(app.store.data); | ||
questions.setData(app.cache.data); | ||
// listen for `ask` event and attempt to set the default | ||
@@ -54,2 +54,5 @@ // value using stored data, before the question is asked | ||
var ctx = utils.merge({}, app.store.data, app.cache.data); | ||
questions.setData(ctx); | ||
var init = options.init || options.force; | ||
@@ -72,3 +75,3 @@ if (init) { | ||
answer = utils.get(app.cache.data, key); | ||
answer = utils.get(ctx, key); | ||
if (answer) { | ||
@@ -79,4 +82,8 @@ question.answer.set(answer); | ||
if (!question.isAnswered(options.locale) && store.has(key)) { | ||
question.answer.setDefault(store.get(key)); | ||
if (!question.isAnswered(options.locale)) { | ||
if (store.has(key)) { | ||
question.answer.setDefault(store.get(key)); | ||
return; | ||
} | ||
questions.options.force = true; | ||
} | ||
@@ -89,19 +96,8 @@ }); | ||
// than questions, so we only set if it doesn't already exist. | ||
questions.on('answer', function(key, val, question) { | ||
questions.on('answer', function(key, answer, question) { | ||
if (question.options.isDefault) { | ||
store.set(key, val); | ||
store.set(key, answer); | ||
} | ||
}); | ||
/** | ||
* Load questions to ask. Answers are | ||
* passed to templates as context. | ||
*/ | ||
opts.questions = utils.commonQuestions(opts.questions); | ||
for (var key in opts.questions) { | ||
questions.visit(key, opts.questions[key]); | ||
} | ||
delete opts.questions; | ||
// decorate the `questions` instance onto `app` | ||
@@ -172,2 +168,12 @@ app.define('questions', questions); | ||
/** | ||
* Load questions to ask. Answers are passed to templates as context. | ||
*/ | ||
opts.questions = utils.commonQuestions(opts.questions); | ||
for (var key in opts.questions) { | ||
app.questions.visit(key, opts.questions[key]); | ||
} | ||
delete opts.questions; | ||
/** | ||
* Ask one or more questions, with the given `options` and callback. | ||
@@ -174,0 +180,0 @@ * |
{ | ||
"name": "base-questions", | ||
"description": "Plugin for base-methods that adds methods for prompting the user and storing the answers on a project-by-project basis.", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"homepage": "https://github.com/jonschlinkert/base-questions", | ||
@@ -25,9 +25,9 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"common-questions": "^0.1.1", | ||
"extend-shallow": "^2.0.1", | ||
"for-own": "^0.1.3", | ||
"get-value": "^2.0.0", | ||
"lazy-cache": "^0.2.4", | ||
"get-value": "^2.0.2", | ||
"lazy-cache": "^1.0.2", | ||
"micromatch": "^2.3.5", | ||
"question-store": "^0.3.0", | ||
"set-value": "^0.3.1", | ||
"mixin-deep": "^1.1.3", | ||
"question-store": "^0.3.2", | ||
"set-value": "^0.3.2", | ||
"to-choices": "^0.1.1" | ||
@@ -34,0 +34,0 @@ }, |
@@ -5,2 +5,13 @@ # base-questions [![NPM version](https://img.shields.io/npm/v/base-questions.svg)](https://www.npmjs.com/package/base-questions) [![Build Status](https://img.shields.io/travis/jonschlinkert/base-questions.svg)](https://travis-ci.org/jonschlinkert/base-questions) | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [API](#api) | ||
- [Related projects](#related-projects) | ||
- [Running tests](#running-tests) | ||
- [Contributing](#contributing) | ||
- [Author](#author) | ||
- [License](#license) | ||
_(TOC generated by [verb](https://github.com/verbose/verb))_ | ||
## Install | ||
@@ -14,3 +25,3 @@ | ||
## Usage [![Build Status](https://img.shields.io/travis/jonschlinkert/base-questions.svg)](https://www.npmjs.com/) | ||
## Usage | ||
@@ -71,3 +82,3 @@ Try running the [actual examples](./example.js) if it helps to see the following example in action. | ||
### [.choices](index.js#L126) | ||
### [.choices](index.js#L122) | ||
@@ -97,3 +108,3 @@ Create a "choices" question from an array. | ||
### [.question](index.js#L163) | ||
### [.question](index.js#L159) | ||
@@ -125,3 +136,3 @@ Add a question to be asked at a later point. | ||
### [.ask](index.js#L186) | ||
### [.ask](index.js#L192) | ||
@@ -183,2 +194,2 @@ Ask one or more questions, with the given `options` and callback. | ||
_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 17, 2015._ |
@@ -15,4 +15,4 @@ 'use strict'; | ||
require('extend-shallow', 'extend'); | ||
require('question-store', 'questions'); | ||
require('mixin-deep', 'merge'); | ||
require('common-questions'); | ||
@@ -19,0 +19,0 @@ require('micromatch', 'mm'); |
14449
202
189
+ Addedmixin-deep@^1.1.3
- Removedextend-shallow@^2.0.1
- Removedlazy-cache@0.2.7(transitive)
Updatedget-value@^2.0.2
Updatedlazy-cache@^1.0.2
Updatedquestion-store@^0.3.2
Updatedset-value@^0.3.2