@@ -54,15 +54,21 @@ var getListDefault = function (question, defaultValue) {
54
54
*
55
55
* @param {Object } question Inquirer prompt item
56
56
* @param {String|Array } answer The inquirer answer
57
+ * @param {Boolean } storeAll Should store default values
57
58
* @return {Boolean } Answer to be stored
58
59
* @private
59
60
*/
60
- var storeListAnswer = function ( question , answer ) {
61
- var choiceValues = _ . map ( question . choices , 'value' ) ;
61
+ var storeListAnswer = function ( question , answer , storeAll ) {
62
+ var choiceValues = _ . map ( question . choices , function ( choice ) {
63
+ if ( choice . hasOwnProperty ( 'value' ) ) {
64
+ return choice . value ;
65
+ }
66
+ return choice ;
67
+ } ) ;
62
68
var choiceIndex = choiceValues . indexOf ( answer ) ;
63
69
64
70
// Check if answer is not equal to default value
65
- if ( question . default !== choiceIndex ) {
71
+ if ( storeAll || question . default !== choiceIndex ) {
66
72
return true ;
67
73
}
68
74
@@ -75,12 +81,13 @@ var storeListAnswer = function (question, answer) {
75
81
*
76
82
* @param {Object } question Inquirer prompt item
77
83
* @param {String|Array } answer The inquirer answer
84
+ * @param {Boolean } storeAll Should store default values
78
85
* @return {Boolean } Answer to be stored
79
86
* @private
80
87
*/
81
- var storeAnswer = function ( question , answer ) {
88
+ var storeAnswer = function ( question , answer , storeAll ) {
82
89
// Check if answer is not equal to default value or is undefined
83
- if ( answer !== undefined && question . default !== answer ) {
90
+ if ( answer !== undefined && ( storeAll || question . default !== answer ) ) {
84
91
return true ;
85
92
}
86
93
@@ -142,13 +149,15 @@ promptSuggestion.prefillQuestions = function (store, questions) {
142
149
* @param {Store } store `.yo-rc-global` global config
143
150
* @param {Array|Object } questions Original prompt questions
144
151
* @param {Object } answers The inquirer answers
152
+ * @param {Boolean } storeAll Should store default values
145
153
*/
146
- promptSuggestion . storeAnswers = function ( store , questions , answers ) {
154
+ promptSuggestion . storeAnswers = function ( store , questions , answers , storeAll ) {
147
155
assert ( store , 'A store parameter is required' ) ;
148
156
assert ( answers , 'A answers parameter is required' ) ;
149
157
assert ( questions , 'A questions parameter is required' ) ;
150
158
assert . ok ( _ . isObject ( answers ) , 'answers must be a object' ) ;
151
159
160
+ storeAll = storeAll || false ;
152
161
var promptValues = store . get ( 'promptValues' ) || { } ;
153
162
154
163
if ( ! Array . isArray ( questions ) ) {
@@ -167,11 +176,11 @@ promptSuggestion.storeAnswers = function (store, questions, answers) {
167
176
switch ( question . type ) {
168
177
case 'rawlist' :
169
178
case 'expand' :
170
- saveAnswer = storeListAnswer ( question , answer ) ;
179
+ saveAnswer = storeListAnswer ( question , answer , storeAll ) ;
171
180
break ;
172
181
173
182
default :
174
- saveAnswer = storeAnswer ( question , answer ) ;
183
+ saveAnswer = storeAnswer ( question , answer , storeAll ) ;
175
184
break ;
176
185
}
177
186
0 commit comments