all-contributors-cli/lib/init/prompt.js

78 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-03-21 21:40:32 +00:00
'use strict';
var _ = require('lodash/fp');
var inquirer = require('inquirer');
var git = require('../util').git;
2016-03-21 21:40:32 +00:00
var questions = [{
type: 'input',
name: 'projectName',
2016-05-05 14:27:26 +00:00
message: 'What\'s the name of the repository?'
2016-03-21 21:40:32 +00:00
}, {
type: 'input',
name: 'projectOwner',
2016-05-05 14:27:26 +00:00
message: 'Who is the owner of the repository?'
2016-03-21 21:40:32 +00:00
}, {
type: 'input',
name: 'contributorFile',
message: 'In which file should contributors be listed?',
default: 'README.md'
}, {
type: 'confirm',
name: 'needBadge',
2016-05-05 14:27:26 +00:00
message: 'Do you want a badge tallying the number of contributors?'
2016-03-21 21:40:32 +00:00
}, {
type: 'input',
name: 'badgeFile',
2016-05-05 14:27:26 +00:00
message: 'In which file should the badge be shown?',
2016-03-21 21:40:32 +00:00
when: function (answers) {
return answers.needBadge;
},
default: function (answers) {
return answers.contributorFile;
}
}, {
type: 'input',
name: 'imageSize',
2016-05-05 14:27:26 +00:00
message: 'How big should the avatars be? (in px)',
2016-03-21 21:40:32 +00:00
filter: parseInt,
default: 100
}, {
type: 'confirm',
name: 'commit',
2016-05-05 14:27:26 +00:00
message: 'Do you want this badge to auto-commit when contributors are added?',
default: true
2016-03-21 21:40:32 +00:00
}];
var uniqueFiles = _.flow(
_.compact,
_.uniq
);
module.exports = function prompt(cb) {
git.getRepoInfo(function (error, repoInfo) {
if (error) {
return cb(error);
}
if (repoInfo) {
questions[0].default = repoInfo.projectName;
questions[1].default = repoInfo.projectOwner;
}
inquirer.prompt(questions, function treatAnswers(answers) {
var config = {
projectName: answers.projectName,
projectOwner: answers.projectOwner,
files: uniqueFiles([answers.contributorFile, answers.badgeFile]),
imageSize: answers.imageSize,
commit: answers.commit,
contributors: []
};
return cb({
config: config,
contributorFile: answers.contributorFile,
badgeFile: answers.badgeFile
});
2016-03-21 21:40:32 +00:00
});
});
};