Skip to content

Commit

Permalink
refactor: 💡 exporting async prompter issue was resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
tal-rofe committed Apr 16, 2023
1 parent a5dcbab commit ff6f3dd
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions src/index.ts
Expand Up @@ -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 };
Expand Down

0 comments on commit ff6f3dd

Please sign in to comment.