|
| 1 | +import chalk from 'chalk'; |
| 2 | +import ruleWarningMessages from './rules/ruleWarningMessages'; |
| 3 | +import combineTypeScope from './helpers/combineTypeScope'; |
| 4 | + |
| 5 | +const choices = (config) => { |
| 6 | + const choicesList = []; |
| 7 | + |
| 8 | + config.types.forEach((type) => { |
| 9 | + const emoji = config.emoji && type.emoji ? `${type.emoji} ` : ''; |
| 10 | + const configType = type.type; |
| 11 | + const description = type.description || ''; |
| 12 | + |
| 13 | + choicesList.push({ |
| 14 | + value: emoji + configType, |
| 15 | + name: `${chalk.bold(configType)} ${description}`, |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + return choicesList; |
| 20 | +}; |
| 21 | + |
| 22 | +const questions = (config) => { |
| 23 | + const choicesList = choices(config); |
| 24 | + const questionsList = [ |
| 25 | + { |
| 26 | + type: 'list', |
| 27 | + name: 'type', |
| 28 | + message: 'Select the type of your commit:', |
| 29 | + choices: choicesList, |
| 30 | + }, |
| 31 | + { |
| 32 | + type: 'input', |
| 33 | + name: 'scope', |
| 34 | + message: 'Enter your scope (no whitespaces allowed):', |
| 35 | + when: () => config.scope, |
| 36 | + validate: input => (input.match(/\s/) !== null ? 'No whitespaces allowed' : true), |
| 37 | + filter: input => (input ? `(${input})` : input), |
| 38 | + }, |
| 39 | + { |
| 40 | + type: 'input', |
| 41 | + name: 'description', |
| 42 | + message: 'Enter your commit message:', |
| 43 | + validate: (input) => { |
| 44 | + const warnings = ruleWarningMessages(input, config); |
| 45 | + |
| 46 | + return warnings || true; |
| 47 | + }, |
| 48 | + }, |
| 49 | + { |
| 50 | + type: 'confirm', |
| 51 | + name: 'body', |
| 52 | + message: 'Do you want to add a body?', |
| 53 | + when: () => config.body, |
| 54 | + default: false, |
| 55 | + }, |
| 56 | + { |
| 57 | + type: 'editor', |
| 58 | + name: 'editor', |
| 59 | + message: 'This will let you add more information', |
| 60 | + when: answers => answers.body, |
| 61 | + default: (answers) => { |
| 62 | + const type = combineTypeScope(answers.type, answers.scope); |
| 63 | + |
| 64 | + return `${type} ${answers.description}\n\n\n`; |
| 65 | + }, |
| 66 | + }, |
| 67 | + ]; |
| 68 | + |
| 69 | + return questionsList; |
| 70 | +}; |
| 71 | + |
| 72 | +export default questions; |
| 73 | +export { choices }; |
0 commit comments