Skip to content

Commit 1167109

Browse files
authored
feat(cz-git,cli): add confirmCommit in skipQuestions #86 (#88)
1 parent 89facc8 commit 1167109

10 files changed

Lines changed: 437 additions & 327 deletions

File tree

‎docs/config/engineer.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ If commitlint is used, it will automatically read `body-max-line-length` and set
131131
## skipQuestions
132132

133133
- **description** : The question specified by the custom selection is not displayed
134-
- **type** : `Array<"scope" | "body" | "breaking" | "footerPrefix" | "footer">`
134+
- **type** : `Array<'scope' | 'body' | 'breaking' | 'footerPrefix' | 'footer' | 'confirmCommit'>`
135135
- **default** : `[]`
136136

137137
## issuePrefixes

‎docs/zh/config/engineer.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ sitemap:
131131
## skipQuestions
132132

133133
- **描述** : 自定义选择指定的问题不显示
134-
- **类型** : `Array<"scope" | "body" | "breaking" | "footerPrefix" | "footer">`
134+
- **类型** : `Array<'scope' | 'body' | 'breaking' | 'footerPrefix' | 'footer' | 'confirmCommit'>`
135135
- **默认** : `[]`
136136

137137
## issuePrefixes

‎package.json‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,32 @@
6060
}
6161
},
6262
"devDependencies": {
63-
"@antfu/eslint-config": "^0.29.2",
64-
"@commitlint/cli": "^17.2.0",
65-
"@commitlint/config-conventional": "^17.2.0",
63+
"@antfu/eslint-config": "^0.33.1",
64+
"@commitlint/cli": "^17.3.0",
65+
"@commitlint/config-conventional": "^17.3.0",
6666
"@cz-git/inquirer": "workspace:*",
6767
"@types/fs-extra": "^9.0.13",
6868
"@types/inquirer": "8.2.3",
69-
"@types/node": "^18.11.8",
69+
"@types/node": "^18.11.11",
7070
"@types/rimraf": "^3.0.2",
7171
"bumpp": "7.2.0",
72-
"concurrently": "^7.5.0",
72+
"concurrently": "^7.6.0",
7373
"conventional-changelog-cli": "^2.2.2",
7474
"cz-git": "workspace:*",
7575
"czg": "workspace:*",
76-
"eslint": "^8.26.0",
76+
"eslint": "^8.29.0",
7777
"fast-glob": "^3.2.12",
7878
"js-yaml": "^4.1.0",
79-
"lint-staged": "^13.0.3",
79+
"lint-staged": "^13.1.0",
8080
"ora": "^6.1.2",
8181
"pathe": "^0.3.9",
82-
"pnpm": "^7.14.1",
82+
"pnpm": "^7.18.1",
8383
"rimraf": "^3.0.2",
8484
"simple-git-hooks": "^2.8.1",
8585
"ts-node": "^10.9.1",
86-
"tsup": "6.3.0",
87-
"tsx": "^3.11.0",
88-
"typescript": "^4.8.4",
89-
"vitest": "^0.24.4"
86+
"tsup": "6.5.0",
87+
"typescript": "^4.9.4",
88+
"vitest": "^0.25.6"
9089
},
9190
"engines": {
9291
"pnpm": ">=7"

‎packages/cli/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"cachedir": "^2.3.0",
3939
"cz-git": "workspace:*",
4040
"dedent": "^0.7.0",
41-
"fs-extra": "^10.1.0",
41+
"fs-extra": "^11.1.0",
4242
"inquirer": "8.2.4",
4343
"minimist": "^1.2.7",
4444
"rimraf": "3.0.2"

‎packages/cz-git/src/generator/question.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
isSingleItem,
1414
log,
1515
parseStandardScopes,
16+
previewMessage,
1617
resolveListItemPinTop,
1718
resovleCustomListTemplate,
1819
} from '../shared'
@@ -268,19 +269,17 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
268269
],
269270
default: 0,
270271
message(answers: Answers) {
271-
const SEP = options.confirmColorize
272-
? style.gray('###--------------------------------------------------------###')
273-
: '###--------------------------------------------------------###'
274-
console.info(
275-
`\n${SEP}\n${generateMessage(answers, options, options.confirmColorize)}\n${SEP}\n`,
272+
previewMessage(
273+
generateMessage(answers, options, options.confirmColorize),
274+
options.confirmColorize,
276275
)
277276
return options.messages?.confirmCommit
278277
},
279278
},
280279
].filter(
281280
i =>
282281
!options.skipQuestions?.includes(
283-
i.name as 'scope' | 'body' | 'breaking' | 'footer' | 'footerPrefix',
282+
i.name as 'scope' | 'body' | 'breaking' | 'footer' | 'footerPrefix' | 'confirmCommit',
284283
),
285284
)
286285
}

‎packages/cz-git/src/index.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { CompleteInput, SearchCheckbox, SearchList } from '@cz-git/inquirer'
99
import { configLoader } from '@cz-git/loader'
10-
import { editCommit, log } from './shared'
10+
import { editCommit, log, previewMessage } from './shared'
1111
import { generateMessage, generateOptions, generateQuestions, getAliasMessage } from './generator'
1212
import type { CommitizenType } from './shared'
1313

@@ -35,6 +35,15 @@ export const prompter = (
3535
cz.registerPrompt('search-checkbox', SearchCheckbox)
3636
cz.registerPrompt('complete-input', CompleteInput)
3737
cz.prompt(questions).then((answers) => {
38+
if (options.skipQuestions?.includes('confirmCommit')) {
39+
commit(generateMessage(answers, options))
40+
previewMessage(
41+
generateMessage(answers, options, options.confirmColorize),
42+
options.confirmColorize,
43+
)
44+
return 0
45+
}
46+
3847
switch (answers.confirmCommit) {
3948
case 'edit':
4049
editCommit(answers, options, commit)

‎packages/cz-git/src/shared/types/options.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export interface CommitizenGitOptions {
386386
* @default: []
387387
* @example: ['body']
388388
*/
389-
skipQuestions?: Array<'scope' | 'body' | 'breaking' | 'footerPrefix' | 'footer'>
389+
skipQuestions?: Array<'scope' | 'body' | 'breaking' | 'footerPrefix' | 'footer' | 'confirmCommit'>
390390

391391
/**
392392
* @description: Force set max header length | Equivalent setting maxSubjectLength.

‎packages/cz-git/src/shared/utils/editor.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ export const getPreparedCommit = (context: string) => {
244244
.split(/\r\n|\r|\n/)
245245

246246
if (preparedCommit.length && preparedCommit[0]) {
247-
if (context === 'subject') { [message] = preparedCommit }
247+
if (context === 'subject') {
248+
[message] = preparedCommit
249+
}
248250
else if (context === 'body' && preparedCommit.length > 1) {
249251
preparedCommit.shift()
250252
message = preparedCommit.join('|')

‎packages/cz-git/src/shared/utils/util.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,10 @@ export const getMaxSubjectLength = (
189189
}
190190
return countLength(optionMaxLength, typeLength, scopeLength, emojiLength)
191191
}
192+
193+
export const previewMessage = (msg: string, confirmColorize = false) => {
194+
const SEP = confirmColorize
195+
? '\u001B[90m###--------------------------------------------------------###\u001B[0m'
196+
: '###--------------------------------------------------------###'
197+
console.info(`\n${SEP}\n${msg}\n${SEP}\n`)
198+
}

0 commit comments

Comments
 (0)