Skip to content

Commit

Permalink
feat: retain unknown features from command line and before.js
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Jun 9, 2022
1 parent 703032d commit 72a0c79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion lib/run-questionnaire.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function isSame(arr1, arr2) {
return true;
}

function minusSet(list1, list2) {
const left = [];
for (const x of list1) {
if (list2.indexOf(x) === -1 && left.indexOf(x) === -1) {
left.push(x);
}
}
return left;
}

// Get user provided predefinedProperties, preselectedFeatures, go through all the questions,
// Output a cleaned up features.
//
Expand Down Expand Up @@ -86,7 +96,13 @@ async function run(questions, {
await ask(questions[i]);
}

return [{...predefinedProperties, ...properties}, pickedFeatures, notDefaultFeatures];
const unknownFeatures = minusSet(preselectedFeatures, pickedFeatures);

return [
{...predefinedProperties, ...properties},
[...pickedFeatures, ...unknownFeatures],
[...notDefaultFeatures, ...unknownFeatures]
];
}

async function textPrompt(question, {predefinedProperties, unattended, _debug}) {
Expand Down
8 changes: 4 additions & 4 deletions test/run-questionnaire.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ test('run runs through questionnaire with preselectedFeatures and predefinedProp
]);
});

test('run runs through questionnaire with preselectedFeatures and predefinedProperties, and keeps unknown properties', async t => {
test('run runs through questionnaire with preselectedFeatures and predefinedProperties, and keeps unknown properties and selection', async t => {
const result = await run(questions, {
preselectedFeatures: ['postcss'],
preselectedFeatures: ['postcss', 'lorem', 'abc', 'lorem'],
predefinedProperties: {name: 'new-app', foo: 'bar'},
_debug: [2]
});
t.deepEqual(result, [
{name: 'new-app', foo: 'bar'},
['dumber', 'postcss'],
['dumber', 'postcss']
['dumber', 'postcss', 'lorem', 'abc'],
['dumber', 'postcss', 'lorem', 'abc']
]);
});

Expand Down

0 comments on commit 72a0c79

Please sign in to comment.