66
77// @ts -ignore
88import { commitizenConfigLoader } from "@cz-git/loader" ;
9- import { defaultConfig , Option } from "./share" ;
9+ import { defaultConfig , Option , UserConfig } from "./share" ;
1010import {
1111 getMaxLength ,
1212 getMinLength ,
@@ -17,7 +17,8 @@ import {
1717 buildCommit ,
1818 log ,
1919 enumRuleIsActive ,
20- getEnumList
20+ getEnumList ,
21+ getValueByCallBack
2122} from "./until" ;
2223import type { Answers , Config , CommitizenGitOptions } from "./share" ;
2324
@@ -38,16 +39,20 @@ const pkgConfig: Config = commitizenConfigLoader() ?? {};
3839
3940/* eslint-disable prettier/prettier */
4041/* prettier-ignore */
41- export const generateOptions = ( clConfig : any ) : CommitizenGitOptions => {
42- const clPromptConfig = clConfig . prompt ?? { } ;
42+ export const generateOptions = ( clConfig : UserConfig ) : CommitizenGitOptions => {
43+ let clPromptConfig = clConfig . prompt ?? { } ;
44+ clPromptConfig = getValueByCallBack (
45+ clPromptConfig ,
46+ [ "defaultScope" , "defaultSubject" , "defaultBody" , "defaultFooterPrefix" , "defaultIssues" ]
47+ )
4348
4449 return {
4550 messages : pkgConfig . messages ?? clPromptConfig . messages ?? defaultConfig . messages ,
4651 types : pkgConfig . types ?? clPromptConfig . types ?? defaultConfig . types ,
4752 useEmoji : pkgConfig . useEmoji ?? clPromptConfig . useEmoji ?? defaultConfig . useEmoji ,
48- scopes : pkgConfig . scopes ?? clPromptConfig . scopes ?? getEnumList ( clConfig ?. rules ?. [ "scope-enum" ] ) ,
53+ scopes : pkgConfig . scopes ?? clPromptConfig . scopes ?? getEnumList ( clConfig ?. rules ?. [ "scope-enum" ] as any ) ,
4954 scopeOverrides : pkgConfig . scopeOverrides ?? clPromptConfig . scopeOverrides ?? defaultConfig . scopeOverrides ,
50- allowCustomScopes : pkgConfig . allowCustomScopes ?? clPromptConfig . allowCustomScopes ?? ! enumRuleIsActive ( clConfig ?. rules ?. [ "scope-enum" ] ) ,
55+ allowCustomScopes : pkgConfig . allowCustomScopes ?? clPromptConfig . allowCustomScopes ?? ! enumRuleIsActive ( clConfig ?. rules ?. [ "scope-enum" ] as any ) ,
5156 allowEmptyScopes : pkgConfig . allowEmptyScopes ?? clPromptConfig . allowEmptyScopes ?? defaultConfig . allowEmptyScopes ,
5257 customScopesAlign : pkgConfig . customScopesAlign ?? clPromptConfig . customScopesAlign ?? defaultConfig . customScopesAlign ,
5358 customScopesAlias : pkgConfig . customScopesAlias ?? clPromptConfig . customScopesAlias ?? defaultConfig . customScopesAlias ,
@@ -61,12 +66,13 @@ export const generateOptions = (clConfig: any): CommitizenGitOptions => {
6166 emptyIssuePrefixsAlias : pkgConfig . emptyIssuePrefixsAlias ?? clPromptConfig . emptyIssuePrefixsAlias ?? defaultConfig . emptyIssuePrefixsAlias ,
6267 customIssuePrefixsAlias : pkgConfig . customIssuePrefixsAlias ?? clPromptConfig . customIssuePrefixsAlias ?? defaultConfig . customIssuePrefixsAlias ,
6368 confirmColorize : pkgConfig . confirmColorize ?? clPromptConfig . confirmColorize ?? defaultConfig . confirmColorize ,
64- maxHeaderLength : CZ_MAN_HEADER_LENGTH ? parseInt ( CZ_MAN_HEADER_LENGTH ) : getMaxLength ( clConfig ?. rules ?. [ "header-max-length" ] ) ,
65- maxSubjectLength : CZ_MAN_SUBJECT_LENGTH ? parseInt ( CZ_MAN_SUBJECT_LENGTH ) : getMaxLength ( clConfig ?. rules ?. [ "subject-max-length" ] ) ,
66- minSubjectLength : CZ_MIN_SUBJECT_LENGTH ? parseInt ( CZ_MIN_SUBJECT_LENGTH ) : getMinLength ( clConfig ?. rules ?. [ "subject-min-length" ] ) ,
69+ maxHeaderLength : CZ_MAN_HEADER_LENGTH ? parseInt ( CZ_MAN_HEADER_LENGTH ) : getMaxLength ( clConfig ?. rules ?. [ "header-max-length" ] as any ) ,
70+ maxSubjectLength : CZ_MAN_SUBJECT_LENGTH ? parseInt ( CZ_MAN_SUBJECT_LENGTH ) : getMaxLength ( clConfig ?. rules ?. [ "subject-max-length" ] as any ) ,
71+ minSubjectLength : CZ_MIN_SUBJECT_LENGTH ? parseInt ( CZ_MIN_SUBJECT_LENGTH ) : getMinLength ( clConfig ?. rules ?. [ "subject-min-length" ] as any ) ,
6772 defaultScope : CZ_SCOPE ?? clPromptConfig . defaultScope ?? defaultConfig . defaultScope ,
6873 defaultSubject : CZ_SUBJECT ?? clPromptConfig . defaultSubject ?? defaultConfig . defaultSubject ,
6974 defaultBody : CZ_BODY ?? clPromptConfig . defaultBody ?? defaultConfig . defaultBody ,
75+ defaultFooterPrefix : clPromptConfig . defaultFooterPrefix ?? defaultConfig . defaultFooterPrefix ,
7076 defaultIssues : CZ_ISSUES ?? clPromptConfig . defaultIssues ?? defaultConfig . defaultIssues
7177 }
7278}
@@ -76,6 +82,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
7682 log ( "err" , "Error [types] Option" ) ;
7783 return false ;
7884 }
85+
7986 return [
8087 {
8188 type : "autocomplete" ,
@@ -220,6 +227,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
220227 {
221228 type : "input" ,
222229 name : "footer" ,
230+ default : options . defaultIssues || undefined ,
223231 when ( answers : Answers ) {
224232 return ( answers . footerPrefix as string | boolean ) !== false ;
225233 } ,
0 commit comments