forked from all-contributors/cli
/
prompt.js
122 lines (119 loc) · 2.78 KB
/
prompt.js
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
const _ = require('lodash/fp')
const inquirer = require('inquirer')
const git = require('../util').git
const questions = [
{
type: 'input',
name: 'projectName',
message: "What's the name of the repository?",
},
{
type: 'input',
name: 'projectOwner',
message: 'Who is the owner of the repository?',
},
{
type: 'list',
name: 'repoType',
message: 'What is the repository type?',
choices: [
{
value: 'github',
name: 'GitHub',
},
{
value: 'gitlab',
name: 'GitLab',
},
],
default: 'github',
},
{
type: 'input',
name: 'repoHost',
message:
"Where is the repository hosted? Hit Enter if it's on GitHub or GitLab",
default: function(answers) {
if (answers.repoType === 'github') {
return 'https://github.com'
} else if (answers.repoType === 'gitlab') {
return 'https://gitlab.com'
}
},
},
{
type: 'input',
name: 'privateToken',
message:
'What is the personal access token? (If you use a self hosted repository)',
default: '',
},
{
type: 'input',
name: 'contributorFile',
message: 'In which file should contributors be listed?',
default: 'README.md',
},
{
type: 'confirm',
name: 'needBadge',
message: 'Do you want a badge tallying the number of contributors?',
},
{
type: 'input',
name: 'badgeFile',
message: 'In which file should the badge be shown?',
when: function(answers) {
return answers.needBadge
},
default: function(answers) {
return answers.contributorFile
},
},
{
type: 'input',
name: 'imageSize',
message: 'How big should the avatars be? (in px)',
filter: parseInt,
default: 100,
},
{
type: 'confirm',
name: 'commit',
message:
'Do you want this badge to auto-commit when contributors are added?',
default: true,
},
]
const uniqueFiles = _.flow(
_.compact,
_.uniq,
)
module.exports = function prompt() {
return git
.getRepoInfo()
.then(repoInfo => {
if (repoInfo) {
questions[0].default = repoInfo.projectName
questions[1].default = repoInfo.projectOwner
}
return inquirer.prompt(questions)
})
.then(answers => {
return {
config: {
projectName: answers.projectName,
projectOwner: answers.projectOwner,
repoType: answers.repoType,
repoHost: answers.repoHost,
privateToken: answers.privateToken,
files: uniqueFiles([answers.contributorFile, answers.badgeFile]),
imageSize: answers.imageSize,
commit: answers.commit,
contributors: [],
},
contributorFile: answers.contributorFile,
badgeFile: answers.badgeFile,
}
})
}