Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: 🎸 adds scope search in scopes question
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Bolotskov committed Dec 17, 2019
1 parent caf34ff commit 70bf18b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/questions/scope.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Searches for the scopes starting with the given substring.
*
* @param {string} substring Substring to search with.
* @param {string[]} scopes Scopes list.
*/
const findScope = function (substring, scopes) {
return substring === '' || substring === undefined ?
Promise.resolve(scopes) :
Promise.resolve(scopes.filter((scope) => scope.toLowerCase().includes(substring.toLowerCase().trim())));
};

exports.createQuestion = (state) => {
const {scopes} = state.config;

Expand All @@ -18,7 +30,8 @@ exports.createQuestion = (state) => {
default: 0,
message: 'Select the scope this component affects:',
name: 'scope',
type: 'list'
source: (_answers, input) => findScope(input, scopes),
type: 'autocomplete'
};

return question;
Expand Down
2 changes: 2 additions & 0 deletions lib/runInteractiveQuestions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const inquirer = require('inquirer');
const AutocompletePrompt = require('inquirer-autocomplete-prompt');
const LimitedInputPrompt = require('./LimitedInputPrompt');
const createQuestions = require('./createQuestions');

inquirer.registerPrompt('limitedInput', LimitedInputPrompt);
inquirer.registerPrompt('autocomplete', AutocompletePrompt);

// if (IS_LERNA_PROJECT) {
// const allPackages = getAllPackages().map((pkg) => pkg.name);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"backup": false
},
"dependencies": {
"global": "^4.3.2"
"global": "^4.3.2",
"inquirer-autocomplete-prompt": "^1.0.1"
}
}

0 comments on commit 70bf18b

Please sign in to comment.