2016-03-27 15:19:13 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash/fp');
|
|
|
|
var inquirer = require('inquirer');
|
|
|
|
var util = require('../util');
|
|
|
|
|
2016-03-31 09:00:02 +00:00
|
|
|
var contributionChoices = _.flow(
|
|
|
|
util.contributionTypes,
|
|
|
|
_.toPairs,
|
|
|
|
_.sortBy(function (pair) {
|
|
|
|
return pair[1].description;
|
|
|
|
}),
|
|
|
|
_.map(function (pair) {
|
|
|
|
return {
|
|
|
|
name: pair[1].symbol + ' ' + pair[1].description,
|
|
|
|
value: pair[0]
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2017-11-06 23:39:41 +00:00
|
|
|
function getQuestions(options, username, contributions, allContributions) {
|
2016-03-27 15:19:13 +00:00
|
|
|
return [{
|
|
|
|
type: 'input',
|
|
|
|
name: 'username',
|
2016-05-05 14:27:26 +00:00
|
|
|
message: 'What is the contributor\'s GitHub username?',
|
2016-03-27 15:19:13 +00:00
|
|
|
when: !username
|
|
|
|
}, {
|
|
|
|
type: 'checkbox',
|
|
|
|
name: 'contributions',
|
2016-05-05 14:27:26 +00:00
|
|
|
message: 'What are the contribution types?',
|
2016-03-27 15:19:13 +00:00
|
|
|
when: !contributions,
|
2017-11-06 23:39:41 +00:00
|
|
|
default: function (answers) {
|
|
|
|
// default values for contributions when updating existing users
|
|
|
|
return allContributions
|
|
|
|
.filter((entry) => entry.login.toLowerCase() === answers.username.toLowerCase())
|
|
|
|
.reduce((memo, entry) => memo.concat(entry.contributions), []);
|
|
|
|
},
|
2017-11-02 16:53:55 +00:00
|
|
|
choices: contributionChoices(options),
|
|
|
|
validate: input => input.length ? true : 'Use space to select at least one contribution type.'
|
2016-03-27 15:19:13 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2017-11-06 23:39:41 +00:00
|
|
|
module.exports = function prompt(options, username, contributions, allContributions) {
|
2016-03-27 15:19:13 +00:00
|
|
|
var defaults = {
|
|
|
|
username: username,
|
|
|
|
contributions: contributions && contributions.split(',')
|
|
|
|
};
|
2017-11-06 23:39:41 +00:00
|
|
|
var questions = getQuestions(options, username, contributions, allContributions);
|
2017-02-15 21:25:32 +00:00
|
|
|
return inquirer.prompt(questions)
|
|
|
|
.then(_.assign(defaults));
|
2016-03-27 15:19:13 +00:00
|
|
|
};
|