Skip to content

Commit a572ee2

Browse files
committed
🔨 Refactor: change promptConfig from export default to named exports
1 parent d6e6076 commit a572ee2

File tree

1 file changed

+44
-76
lines changed

1 file changed

+44
-76
lines changed

lib/promptConfig.js

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,55 @@
11
import chalk from 'chalk';
2-
import execa from 'execa';
3-
import inquirer from 'inquirer';
42
import getConfig from './getConfig';
53

6-
const promptConfig = {
7-
config: () => getConfig(),
4+
const config = () => getConfig();
85

9-
choices: (configuration) => {
10-
const choicesList = [];
6+
const choices = (configuration) => {
7+
const choicesList = [];
118

12-
configuration.types.forEach((type) => {
13-
const emoji = `${type.emoji} ` || '';
14-
const configType = type.type;
15-
const description = type.description || '';
9+
configuration.types.forEach((type) => {
10+
const emoji = `${type.emoji} ` || '';
11+
const configType = type.type;
12+
const description = type.description || '';
1613

17-
choicesList.push({
18-
value: emoji + configType,
19-
name: `${chalk.bold(configType)} ${description}`,
20-
});
14+
choicesList.push({
15+
value: emoji + configType,
16+
name: `${chalk.bold(configType)} ${description}`,
2117
});
18+
});
2219

23-
return choicesList;
24-
},
25-
26-
answerTypes: (configuration) => {
27-
const configTypeList = [];
28-
configuration.types.forEach((type) => {
29-
const configType = type.type;
30-
31-
configTypeList.push(configType);
32-
});
33-
return configTypeList;
34-
},
35-
36-
questions: (choices) => {
37-
const questionsList = [
38-
{
39-
type: 'list',
40-
name: 'type',
41-
message: 'Select the type of your commit:',
42-
choices,
43-
},
44-
{
45-
type: 'input',
46-
name: 'description',
47-
message: 'Enter your commit message:',
48-
validate: /* istanbul ignore next */ input => (input ? true : 'A commit message is mandatory!'),
49-
},
50-
{
51-
type: 'confirm',
52-
name: 'moreInfo',
53-
message: 'Do you want to add more information to your commit?',
54-
default: false,
55-
},
56-
{
57-
type: 'editor',
58-
name: 'editor',
59-
message: 'This will let you add more information',
60-
when: /* istanbul ignore next */ answers => answers.moreInfo,
61-
default: /* istanbul ignore next */ answers => `${answers.type} ${answers.description}\n\n\n`,
62-
},
63-
];
64-
return questionsList;
65-
},
20+
return choicesList;
21+
};
6622

67-
prompt: (questions) => {
68-
const config = promptConfig.config();
69-
const types = promptConfig.answerTypes(config);
70-
const cli = inquirer.prompt(questions).then((answers) => {
71-
const message = answers.moreInfo ? `${answers.editor}` : `${answers.type} ${answers.description}`;
72-
/* istanbul ignore if */
73-
if (types.indexOf(answers.type.split(' ')[1]) !== -1) {
74-
return execa('git', ['commit', '-m', message])
75-
.then(result => console.log(result.stdout))
76-
.catch((err) => {
77-
console.error(chalk.red("Have you thought about 'git add' some files? Add files and try run following again:\n"));
78-
console.error(chalk.green(err.cmd));
79-
});
80-
}
81-
return answers.type;
82-
});
83-
return cli;
84-
},
23+
const questions = (choicesList) => {
24+
const questionsList = [
25+
{
26+
type: 'list',
27+
name: 'type',
28+
message: 'Select the type of your commit:',
29+
choicesList,
30+
},
31+
{
32+
type: 'input',
33+
name: 'description',
34+
message: 'Enter your commit message:',
35+
validate: input => (input ? true : 'A commit message is mandatory!'),
36+
},
37+
{
38+
type: 'confirm',
39+
name: 'moreInfo',
40+
message: 'Do you want to add more information to your commit?',
41+
default: false,
42+
},
43+
{
44+
type: 'editor',
45+
name: 'editor',
46+
message: 'This will let you add more information',
47+
when: answers => answers.moreInfo,
48+
default: answers => `${answers.type} ${answers.description}\n\n\n`,
49+
},
50+
];
51+
52+
return questionsList;
8553
};
8654

87-
export default promptConfig;
55+
export { config, choices, questions };

0 commit comments

Comments
 (0)