/
options.ts
441 lines (393 loc) · 12.9 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/**
* @description: cz-git types
* @author: @Zhengqbbb (zhengqbbb@gmail.com)
* @license: MIT
* @copyright: Copyright (c) 2022-present Qiubin Zheng
*/
import type { QuestionsType } from '../../generator'
import type { CommitlintUserConfig } from './commitlint'
export interface UserConfig extends CommitlintUserConfig {
prompt?: CommitizenGitOptions
}
export type Config = Omit<Partial<typeof defaultConfig>, 'scopes'> & {
scopes: ScopesType
disableScopeLowerCase?: boolean
disableSubjectLowerCase?: boolean
maxHeaderLength?: number
maxSubjectLength?: number
minSubjectLength?: number
defaultScope?: string
defaultSubject?: string
defaultBody?: string
defaultFooterPrefix?: string
defaultIssues?: string
}
export interface Answers {
/**
* @default: Select the type of change that you're committing:
*/
type?: string
/**
* @default: Denote the SCOPE of this change (optional):
*/
scope?: string | string[]
/**
* @default: Denote the SCOPE of this change:
*/
customScope?: string
/**
* @default: Write a SHORT, IMPERATIVE tense description of the change:\n
*/
subject?: string
/**
* @default:Provide a LONGER description of the change (optional). Use "|" to break new line:\n
*/
body?: string
/**
* @default: Is any BREAKING CHANGE (add "!" in header) (optional) ?
* @use need turn on options "markBreakingChangeMode"
*/
markBreaking?: string | boolean
/**
* @default: List any BREAKING CHANGES (optional). Use "|" to break new line:\n
*/
breaking?: string
/**
* @default: Select the ISSUES type of change (optional):
*/
footerPrefixsSelect?: string
footerPrefix?: string
/**
* @default: Input ISSUES prefix:
*/
customFooterPrefixs?: string
/**
* @default: List any ISSUES AFFECTED by this change. E.g.: #31, #34:
*/
footer?: string
/**
* @default: Are you sure you want to proceed with the commit above?
*/
confirmCommit?: string
}
export type ScopesType = string[] | Array<{ name: string; value?: string }>
export interface CommitizenType {
registerPrompt: (type: string, plugin: unknown) => void
prompt: (qs: QuestionsType) => Promise<Answers>
}
export interface Option {
/**
* @description: show prompt name
*/
name: string
/**
* @description: output real value
*/
value: string
}
export interface TypesOption extends Option {
/**
* @description: Submit emoji commit string
* @see: https://gitmoji.dev/
* @example: ":bug:" => 🐛
*/
emoji?: string
}
export interface CommitMessageOptions {
type: string
scope: string
emoji: string
markBreaking: string
subject: string
defaultHeader: string
body: string
breaking: string
footer: string
defaultMessage: string
}
export interface CommitizenGitOptions {
/**
* @description: define commonly used commit message alias
* @default: { fd: "docs: fix typos" }
* @use commitizen CLI: "cz_alias=fd cz"
* @use czg CLI: "czg --alias=fd" | "czg :fd"
* @note use commitizen CLI will meet process not exit. cz-git can't resolve it.
*/
alias?: Record<string, string>
/**
* @description: Customize prompt questions
*/
messages?: Answers
/**
* @description: the prompt inquirer primary color
* @rule `38;5;${color_code}`
* @tip the color_code can get by https://github.com/sindresorhus/xterm-colors
* @example "38;5;043"
* @default: "" = cyan color
*/
themeColorCode?: string
/**
* @description: Customize prompt type
*/
types?: TypesOption[]
/**
* @description: Add extra types to default types
* @use Use when you don't want to add bloated defaults and don't want to adjust the default order in configuration
* @example `typesAppend: [ { value: "workflow", name: "workflow: Workflow changes"} ],`
* @default: []
*/
typesAppend?: TypesOption[]
/**
* @description: default types list fuzzy search types `value` options. if choose `false` will search `name` options
* @default: true
*/
typesSearchValueKey?: boolean
/**
* @description: Use emoji ?| it will be use typesOption.emoji code
* @default: false
*/
useEmoji?: boolean
/**
* @description: Set the location of emoji in header
* @default: "center"
*/
emojiAlign?: 'left' | 'center' | 'right'
/**
* @description: Provides a select of prompt to select module scopes
* @note it auto import value from rule "scope-enum" with `@commitlint`
* @use want to add scopes description or when you not use commitlint
*/
scopes?: ScopesType
/**
* @description: Provides an overriding select of prompt to select module scopes under specific typs
* @note use this option should set `scopes` option to realize distinguish
* @example: [test] => provide select e2eTest unitTest
*/
scopeOverrides?: { [type: string]: ScopesType }
/**
* @description: Filter select of prompt to select module scopes by the scope.value
* @default: ['.DS_Store']
*/
scopeFilters?: string[]
/**
* @description: Whether to enable scope multiple mode
* @default: false
*/
enableMultipleScopes?: boolean
/**
* @description: Multiple choice scope separator
* @default: ","
*/
scopeEnumSeparator?: string
/**
* @description: Whether to show "custom" when selecting scopes
* @note it auto check rule "scope-enum" set the option with `@commitlint`
* @use when you not use commitlint
* @default true
*/
allowCustomScopes?: boolean
/**
* @description: Whether to show "empty" when selecting scopes
* @default true
*/
allowEmptyScopes?: boolean
/**
* @description: Set the location of empty option (empty) and custom option (custom) in selection range
* @default: "bottom"
*/
customScopesAlign?: 'top' | 'bottom' | 'top-bottom' | 'bottom-top'
/**
* @default: "custom"
*/
customScopesAlias?: string
/**
* @default: "empty"
*/
emptyScopesAlias?: string
/**
* @description: Subject is need upper case first.
* @default false
*/
upperCaseSubject?: boolean
/**
* @description: Whether to add extra prompt BREAKCHANGE ask. to add an extra "!" to the header
* @see: https://cz-git.qbb.sh/recipes/breakingchange
* @default: false
*/
markBreakingChangeMode?: boolean
/**
* @description: Allow breaking changes in the included types output box
* @default: ['feat', 'fix']
*/
allowBreakingChanges?: string[]
/**
* @description: set body and BREAKING CHANGE max length to breakline
* @default: 100
* @note it auto check rule "body-max-line-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
breaklineNumber?: number
/**
* @description: body and BREAKINGCHANGES new line char
* @default: "|"
*/
breaklineChar?: string
/**
* @description: Provides a select issue prefix box in footer
* @default: issuePrefixs: [{ value: "closed", name: "ISSUES has been processed" }]
*/
issuePrefixs?: Option[]
/**
* @default: "top"
*/
customIssuePrefixsAlign?: 'top' | 'bottom' | 'top-bottom' | 'bottom-top'
/**
* @default: "skip"
*/
emptyIssuePrefixsAlias?: string
/**
* @default: "custom"
*/
customIssuePrefixsAlias?: string
/**
* @description: Whether to show "custom" selecting issue prefixs
* @default true
*/
allowCustomIssuePrefixs?: boolean
/**
* @description: Whether to show "skip(empty)" when selecting issue prefixs
* @default true
*/
allowEmptyIssuePrefixs?: boolean
/**
* @description: Prompt final determination whether to display the color
* @default: true
*/
confirmColorize?: boolean
/**
* @description: List of questions you want to skip
* @default: []
* @example: ['body']
*/
skipQuestions?: Array<'scope' | 'body' | 'breaking' | 'footerPrefix' | 'footer'>
/**
* @description: Force set max header length | Equivalent setting maxSubjectLength.
* @note it auto check rule "header-max-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
maxHeaderLength?: number
/**
* @description: Force set max subject length.
* @note it auto check rule "subject-max-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
maxSubjectLength?: number
/**
* @description: Force set header width.
* @note it auto check rule "subject-min-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
minSubjectLength?: number
/**
* @description: pin type item the top of the types list (match item value)
*/
defaultType?: string
/**
* @description: Whether to use display default value in custom scope
* @tip pin scope item the top of the scope list (match item value)
* @example: When you want to use default, just keybord <Enter> it
*/
defaultScope?: string
/**
* @description: default value show subject template prompt
* @example: If you want to use template complate. just keybord <Tab> or <Right Arrow> it
* @example: If you want to use default, just keybord <Enter> it
*/
defaultSubject?: string
/**
* @description: default value show body and BREAKINGCHANGES template prompt
* @example: If you want to use template complate. just keybord <Tab> or <Right Arrow> it
* @example: When you want to use default, just keybord <Enter> it
*/
defaultBody?: string
/**
* @description: default value show issuePrefixs custom template prompt
* @example: If you want to use template complate. just keybord <Tab> or <Right Arrow> it
* @example: When you want to use default, just keybord <Enter> it
*/
defaultFooterPrefix?: string
/**
* @description: default value show issue foot template prompt
* @example: If you want to use template complate. just keybord <Tab> or <Right Arrow> it
* @example: When you want to use default, just keybord <Enter> it
*/
defaultIssues?: string
formatMessageCB?: (messageMod: CommitMessageOptions) => string
}
export const defaultConfig = Object.freeze({
alias: { fd: 'docs: fix typos' },
messages: {
type: 'Select the type of change that you\'re committing:',
scope: 'Denote the SCOPE of this change (optional):',
customScope: 'Denote the SCOPE of this change:',
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
markBreaking: 'Is any BREAKING CHANGE (add "!" in header) (optional) ?',
breaking: 'List any BREAKING CHANGES (optional). Use "|" to break new line:\n',
footerPrefixsSelect: 'Select the ISSUES type of change (optional):',
customFooterPrefixs: 'Input ISSUES prefix:',
footer: 'List any ISSUES AFFECTED by this change. E.g.: #31, #34:\n',
confirmCommit: 'Are you sure you want to proceed with the commit above?',
},
types: [
{ value: 'feat', name: 'feat: A new feature', emoji: ':sparkles:' },
{ value: 'fix', name: 'fix: A bug fix', emoji: ':bug:' },
{ value: 'docs', name: 'docs: Documentation only changes', emoji: ':memo:' },
{ value: 'style', name: 'style: Changes that do not affect the meaning of the code', emoji: ':lipstick:' },
{ value: 'refactor', name: 'refactor: A code change that neither fixes a bug nor adds a feature', emoji: ':recycle:' },
{ value: 'perf', name: 'perf: A code change that improves performance', emoji: ':zap:' },
{ value: 'test', name: 'test: Adding missing tests or correcting existing tests', emoji: ':white_check_mark:' },
{ value: 'build', name: 'build: Changes that affect the build system or external dependencies', emoji: ':package:' },
{ value: 'ci', name: 'ci: Changes to our CI configuration files and scripts', emoji: ':ferris_wheel:' },
{ value: 'chore', name: 'chore: Other changes that don\'t modify src or test files', emoji: ':hammer:' },
{ value: 'revert', name: 'revert: Reverts a previous commit', emoji: ':rewind:' },
],
typesAppend: [],
typesSearchValueKey: true,
themeColorCode: '',
useEmoji: false,
emojiAlign: 'center',
scopes: [],
enableMultipleScopes: false,
scopeEnumSeparator: ',',
allowCustomScopes: true,
allowEmptyScopes: true,
customScopesAlign: 'bottom',
customScopesAlias: 'custom',
emptyScopesAlias: 'empty',
upperCaseSubject: false,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
breaklineChar: '|',
skipQuestions: [],
issuePrefixs: [{ value: 'closed', name: 'closed: ISSUES has been processed' }],
customIssuePrefixsAlign: 'top',
emptyIssuePrefixsAlias: 'skip',
customIssuePrefixsAlias: 'custom',
allowCustomIssuePrefixs: true,
allowEmptyIssuePrefixs: true,
confirmColorize: true,
maxHeaderLength: Infinity,
maxSubjectLength: Infinity,
minSubjectLength: 0,
scopeOverrides: undefined,
scopeFilters: ['.DS_Store'],
defaultType: '',
defaultScope: '',
defaultBody: '',
defaultSubject: '',
defaultFooterPrefix: '',
defaultIssues: '',
formatMessageCB: undefined,
} as CommitizenGitOptions)