mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 05:56:29 +00:00
Add init command to generate rc file
This commit is contained in:
parent
dafef7536a
commit
a33ef2307f
5 changed files with 83 additions and 1 deletions
7
cli.js
7
cli.js
|
@ -5,6 +5,7 @@
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
|
var init = require('./lib/init');
|
||||||
var generate = require('./lib/generate');
|
var generate = require('./lib/generate');
|
||||||
var markdown = require('./lib/markdown');
|
var markdown = require('./lib/markdown');
|
||||||
var updateContributors = require('./lib/contributors');
|
var updateContributors = require('./lib/contributors');
|
||||||
|
@ -19,6 +20,8 @@ var argv = require('yargs')
|
||||||
.usage('Usage: $0 generate')
|
.usage('Usage: $0 generate')
|
||||||
.command('add', 'add a new contributor')
|
.command('add', 'add a new contributor')
|
||||||
.usage('Usage: $0 add <username> <contribution>')
|
.usage('Usage: $0 add <username> <contribution>')
|
||||||
|
.command('init', 'Prepare the project to be used with this tool')
|
||||||
|
.usage('Usage: $0 init')
|
||||||
.demand(2)
|
.demand(2)
|
||||||
.default('files', ['README.md'])
|
.default('files', ['README.md'])
|
||||||
.default('contributorsPerLine', 7)
|
.default('contributorsPerLine', 7)
|
||||||
|
@ -60,7 +63,9 @@ function onError(error) {
|
||||||
|
|
||||||
var command = argv._[0];
|
var command = argv._[0];
|
||||||
|
|
||||||
if (command === 'generate') {
|
if (command === 'init') {
|
||||||
|
init(onError);
|
||||||
|
} else if (command === 'generate') {
|
||||||
startGeneration(argv, onError);
|
startGeneration(argv, onError);
|
||||||
} else if (command === 'add') {
|
} else if (command === 'add') {
|
||||||
var username = argv._[1];
|
var username = argv._[1];
|
||||||
|
|
|
@ -17,6 +17,10 @@ function readConfig(configPath) {
|
||||||
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeConfig(configPath, content, cb) {
|
||||||
|
return fs.writeFile(configPath, formatCommaFirst(content), cb);
|
||||||
|
}
|
||||||
|
|
||||||
function writeContributors(configPath, contributors, cb) {
|
function writeContributors(configPath, contributors, cb) {
|
||||||
var config = readConfig(configPath);
|
var config = readConfig(configPath);
|
||||||
var content = _.assign(config, {contributors: contributors});
|
var content = _.assign(config, {contributors: contributors});
|
||||||
|
@ -25,5 +29,6 @@ function writeContributors(configPath, contributors, cb) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
readConfig: readConfig,
|
readConfig: readConfig,
|
||||||
|
writeConfig: writeConfig,
|
||||||
writeContributors: writeContributors
|
writeContributors: writeContributors
|
||||||
};
|
};
|
||||||
|
|
10
lib/init/index.js
Normal file
10
lib/init/index.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var prompt = require('./prompt');
|
||||||
|
var configFile = require('../configFile');
|
||||||
|
|
||||||
|
module.exports = function init(cb) {
|
||||||
|
prompt(function postPrompt(result) {
|
||||||
|
configFile.writeConfig('.all-contributorsrc', result.config, cb);
|
||||||
|
});
|
||||||
|
};
|
61
lib/init/prompt.js
Normal file
61
lib/init/prompt.js
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var _ = require('lodash/fp');
|
||||||
|
var inquirer = require('inquirer');
|
||||||
|
|
||||||
|
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
|
||||||
|
}];
|
||||||
|
|
||||||
|
var uniqueFiles = _.flow(
|
||||||
|
_.compact,
|
||||||
|
_.uniq
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports = function prompt(cb) {
|
||||||
|
inquirer.prompt(questions, function treatAnswers(answers) {
|
||||||
|
var config = {
|
||||||
|
projectName: answers.projectName,
|
||||||
|
projectOwner: answers.projectOwner,
|
||||||
|
files: uniqueFiles([answers.contributorFile, answers.badgeFile]),
|
||||||
|
imageSize: answers.imageSize,
|
||||||
|
contributors: []
|
||||||
|
};
|
||||||
|
return cb({
|
||||||
|
config: config,
|
||||||
|
contributorFile: answers.contributorFile,
|
||||||
|
badgeFile: answers.badgeFile
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
|
@ -26,6 +26,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/jfmengels/all-contributors-cli#readme",
|
"homepage": "https://github.com/jfmengels/all-contributors-cli#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"inquirer": "^0.12.0",
|
||||||
"lodash": "^4.6.1",
|
"lodash": "^4.6.1",
|
||||||
"request": "^2.69.0",
|
"request": "^2.69.0",
|
||||||
"yargs": "^4.3.2"
|
"yargs": "^4.3.2"
|
||||||
|
|
Loading…
Reference in a new issue