(prompter: PromptModule)
| 15 | * @return commit message |
| 16 | */ |
| 17 | export async function input(prompter: PromptModule): Promise<string> { |
| 18 | const { rules } = await load(); |
| 19 | const parts = ["type", "scope", "subject", "body", "footer"] as const; |
| 20 | const headerParts = ["type", "scope", "subject"]; |
| 21 | |
| 22 | const headerLengthRule = getRules("header", rules).find(getHasName("max-length")); |
| 23 | const maxLength = getMaxLength(headerLengthRule); |
| 24 | |
| 25 | try { |
| 26 | const questions: DistinctQuestion<Result>[] = []; |
| 27 | prompter.registerPrompt("input-custom", InputCustomPrompt); |
| 28 | |
| 29 | for (const input of parts) { |
| 30 | const inputSetting: InputSetting = settings[input]; |
| 31 | const inputRules = getRules(input, rules); |
| 32 | if (headerParts.includes(input) && maxLength < Infinity) { |
| 33 | inputSetting.header = { |
| 34 | length: maxLength, |
| 35 | }; |
| 36 | } |
| 37 | const question = getPrompt(input, inputRules, inputSetting); |
| 38 | if (question) { |
| 39 | questions.push(question); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | const results = await prompter<Result>(questions); |
| 44 | return format(results); |
| 45 | } catch (err) { |
| 46 | console.error(err); |
| 47 | return ""; |
| 48 | } |
| 49 | } |
no test coverage detected