From ff6f3dd3bc72f87a4dadeee43ddb0140345eb434 Mon Sep 17 00:00:00 2001 From: tal-rofe Date: Sun, 16 Apr 2023 19:53:19 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20exporting=20async=20?= =?UTF-8?q?prompter=20issue=20was=20resolved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit here: https://github.com/commitizen/cz-cli/issues/926 --- src/index.ts | 61 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/index.ts b/src/index.ts index 079b856a..3cc7bfc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,40 +8,39 @@ import { formatHeader, formatIssues, formatBreakingChange } from './pipes/commit import { getQuestions } from './utils/questions'; import type { ICommitFunc } from './interfaces/commit'; -const prompter = (cz: Inquirer, commit: ICommitFunc) => { +const prompter = async (cz: Inquirer, commit: ICommitFunc) => { cz.prompt.registerPrompt('autocomplete', InquirerAutoComplete); cz.prompt.registerPrompt('maxlength-input', InquirerMaxLength); - // ! - There is an open issue for using "then" rather than "await": https://github.com/commitizen/cz-cli/issues/926 - getConfiguration().then(async (configuration) => { - const wrapOptions = { - indent: '', - trim: true, - width: configuration.maxCommitLineWidth, - }; - - const questions = await getQuestions(configuration); - const answers = await cz.prompt(questions); - - commit( - [ - formatHeader( - configuration.headerFormat, - answers.type.type, - answers.scope, - answers.type.emoji, - answers.ticket_id, - answers.subject, - ), - wrap(answers.body || '', wrapOptions), - wrap(formatBreakingChange(answers.breakingBody) || '', wrapOptions), - formatIssues(answers.issues), - ] - .filter(Boolean) - .join('\n\n') - .trim(), - ); - }); + const configuration = await getConfiguration(); + + const wrapOptions = { + indent: '', + trim: true, + width: configuration.maxCommitLineWidth, + }; + + const questions = await getQuestions(configuration); + const answers = await cz.prompt(questions); + + commit( + [ + formatHeader( + configuration.headerFormat, + answers.type.type, + answers.scope, + answers.type.emoji, + answers.ticket_id, + answers.subject, + ), + wrap(answers.body || '', wrapOptions), + wrap(formatBreakingChange(answers.breakingBody) || '', wrapOptions), + formatIssues(answers.issues), + ] + .filter(Boolean) + .join('\n\n') + .trim(), + ); }; const InqObj = { prompter };