mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 14:06:34 +00:00
1305a7cd92
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
33 lines
1 KiB
JavaScript
33 lines
1 KiB
JavaScript
'use strict';
|
|
|
|
var _ = require('lodash/fp');
|
|
var util = require('../util');
|
|
var add = require('./add');
|
|
var github = require('./github');
|
|
var prompt = require('./prompt');
|
|
|
|
function isNewContributor(contributorList, username) {
|
|
return !_.find({login: username}, contributorList);
|
|
}
|
|
|
|
module.exports = function addContributor(options, username, contributions) {
|
|
const answersP = prompt(options, username, contributions);
|
|
const contributorsP = answersP
|
|
.then(answers => add(options, answers.username, answers.contributions, github));
|
|
|
|
const writeContributorsP = contributorsP.then(
|
|
contributors => util.configFile.writeContributors(options.config, contributors)
|
|
);
|
|
|
|
return Promise.all([answersP, contributorsP, writeContributorsP])
|
|
.then(res => {
|
|
const answers = res[0];
|
|
const contributors = res[1];
|
|
return {
|
|
username: answers.username,
|
|
contributions: answers.contributions,
|
|
contributors: contributors,
|
|
newContributor: isNewContributor(options.contributors, answers.username)
|
|
};
|
|
});
|
|
};
|