all-contributors-cli/lib/init/prompt.js
Jeroen Engels 1305a7cd92 fix: Bump inquirer to v3 and promisify everything (#34)
BREAKING CHANGE: Drop support for Node < v4. This uses native Promises available from Node v4.

* fix: Bump inquirer to v3.0.1. Fixes #33 to improve Windows support.

* refactor: Promisify everything as inquirer uses Promises from 1.0.0 onwards
2017-02-15 22:25:32 +01:00

75 lines
1.8 KiB
JavaScript

'use strict';
var _ = require('lodash/fp');
var inquirer = require('inquirer');
var git = require('../util').git;
var 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: '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
}];
var 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,
files: uniqueFiles([answers.contributorFile, answers.badgeFile]),
imageSize: answers.imageSize,
commit: answers.commit,
contributors: []
},
contributorFile: answers.contributorFile,
badgeFile: answers.badgeFile
};
});
};