77import { fuzzyFilter , style } from '@cz-git/inquirer'
88import type { Answers , CommitizenGitOptions , Option } from '../shared'
99import {
10- getCurrentScopes ,
10+ getAnswersScope ,
11+ getAnswersType ,
1112 getMaxSubjectLength ,
1213 getProcessSubject ,
14+ getScopesList ,
1315 isSingleItem ,
1416 isString ,
1517 log ,
1618 parseStandardScopes ,
17- resolveDefaultType ,
1819 resolveListItemPinTop ,
1920 resovleCustomListTemplate ,
2021 useThemeCode ,
@@ -53,9 +54,9 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
5354 initialCheckedValue : options . defaultScope , // checkbox mode
5455 source : ( answer : Answers , input : string ) => {
5556 let scopeSource : Option [ ] = [ ]
56- const _answerType = resolveDefaultType ( options , answer )
57+ const answerType = getAnswersType ( options , answer )
5758 scopeSource = parseStandardScopes (
58- getCurrentScopes ( options . scopes , options . scopeOverrides , _answerType ) ,
59+ getScopesList ( options . scopes , options . scopeOverrides , answerType ) ,
5960 )
6061 scopeSource = resovleCustomListTemplate (
6162 scopeSource ,
@@ -83,12 +84,12 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
8384 return input . length !== 0 ? true : style . red ( '[ERROR] scope is required' )
8485 } ,
8586 when : ( answer : Answers ) => {
86- const _answerType = resolveDefaultType ( options , answer )
87+ const answerType = getAnswersType ( options , answer )
8788 return ! isSingleItem (
8889 options . allowCustomScopes ,
8990 options . allowEmptyScopes ,
9091 parseStandardScopes (
91- getCurrentScopes ( options . scopes , options . scopeOverrides , _answerType ) ,
92+ getScopesList ( options . scopes , options . scopeOverrides , answerType ) ,
9293 ) ,
9394 )
9495 } ,
@@ -111,8 +112,8 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
111112 return input . length !== 0 ? true : style . red ( '[ERROR] scope is required' )
112113 } ,
113114 when : ( answers : Answers ) => {
114- return answers . scope === '___CUSTOM___'
115- || ( isString ( options . defaultScope ) && ( options . defaultScope as string ) . startsWith ( '___CUSTOM___:' ) )
115+ const { isCustomScope , isInputMode } = getAnswersScope ( options , answers )
116+ return isCustomScope || isInputMode
116117 } ,
117118 transformer : ( input : string ) => useThemeCode ( input , options . themeColorCode ) ,
118119 } ,
@@ -125,12 +126,15 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
125126 const processedSubject = getProcessSubject ( subject )
126127 if ( processedSubject . length === 0 )
127128 return style . red ( '[ERROR] subject is required' )
129+
128130 if ( ! options . minSubjectLength && ! options . maxSubjectLength ) {
129131 log ( 'err' , 'Error [Subject Length] Option' )
130132 return false
131133 }
132- const _answerType = resolveDefaultType ( options , answers )
133- const maxSubjectLength = getMaxSubjectLength ( _answerType , answers . scope , options )
134+
135+ const answerType = getAnswersType ( options , answers )
136+ const { answerScope } = getAnswersScope ( options , answers )
137+ const maxSubjectLength = getMaxSubjectLength ( answerType , answerScope , options )
134138 if ( options . minSubjectLength && processedSubject . length < options . minSubjectLength ) {
135139 return style . red (
136140 `[ERROR]subject length must be greater than or equal to ${ options . minSubjectLength } characters` ,
@@ -148,8 +152,9 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
148152 transformer : ( subject : string , answers : Answers ) => {
149153 const { minSubjectLength, isIgnoreCheckMaxSubjectLength } = options
150154 const subjectLength = subject . length
151- const _answerType = resolveDefaultType ( options , answers )
152- const maxSubjectLength = getMaxSubjectLength ( _answerType , answers . scope , options )
155+ const answerType = getAnswersType ( options , answers )
156+ const { answerScope } = getAnswersScope ( options , answers )
157+ const maxSubjectLength = getMaxSubjectLength ( answerType , answerScope , options )
153158 let tooltip
154159 let isWarning = false
155160 if ( typeof minSubjectLength === 'number' && subjectLength < minSubjectLength ) {
@@ -160,7 +165,9 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
160165 tooltip = `${ subjectLength - maxSubjectLength } chars over the expected`
161166 isWarning = true
162167 }
163- else { tooltip = `${ subjectLength - maxSubjectLength } chars over the limit` }
168+ else {
169+ tooltip = `${ subjectLength - maxSubjectLength } chars over the limit`
170+ }
164171 }
165172 else {
166173 tooltip = `${ maxSubjectLength - subjectLength } more chars allowed`
@@ -218,11 +225,11 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
218225 message : options . messages ?. breaking ,
219226 completeValue : options . defaultBody || undefined ,
220227 when : ( answers : Answers ) => {
221- const _answerType = resolveDefaultType ( options , answers )
228+ const answerType = getAnswersType ( options , answers )
222229 if (
223230 options . allowBreakingChanges
224- && _answerType
225- && options . allowBreakingChanges . includes ( _answerType )
231+ && answerType
232+ && options . allowBreakingChanges . includes ( answerType )
226233 )
227234 return true
228235
0 commit comments