diff --git a/lib/questions/scope.js b/lib/questions/scope.js index 23f1a306..69a66a8c 100644 --- a/lib/questions/scope.js +++ b/lib/questions/scope.js @@ -1,5 +1,5 @@ /** - * Searches for the scopes starting with the given substring. + * Searches for the scopes containing the given substring. * * @param {string} substring Substring to search with. * @param {string[]} scopes Scopes list. @@ -26,7 +26,6 @@ exports.createQuestion = (state) => { } const question = { - choices: scopes, message: 'Select the scope this component affects:', name: 'scope', source: (_answers, input) => findScope(input, scopes), diff --git a/lib/questions/type.js b/lib/questions/type.js index 891c0c0c..12296755 100644 --- a/lib/questions/type.js +++ b/lib/questions/type.js @@ -10,13 +10,30 @@ const typeToListItem = ({types, disableEmoji}, type) => { }; }; +/** + * Searches for the type that includes the given substring. + * + * @param {string} substring Substring to search with. + * @param {string[]} config The whole config. + */ +const findType = function (substring, config) { + const input = (substring || '').toLowerCase(); + let foundTypes = config.list; + + if (input !== '') { + foundTypes = config.list.filter((type) => type.toLowerCase().includes(input)); + } + + return Promise.resolve(foundTypes.map((type) => typeToListItem(config, type))) +}; + exports.createQuestion = (state) => { const {config} = state; const question = { - choices: config.list.map((type) => typeToListItem(config, type)), message: 'Select the type of change that you\'re committing:', name: 'type', - type: 'list' + source: (_answers, input) => findType(input, config), + type: 'autocomplete' }; return question;