2016-02-29 10:45:19 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
'use strict';
|
2016-02-29 00:48:55 +00:00
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2016-02-29 10:45:19 +00:00
|
|
|
var assign = require('lodash.assign');
|
|
|
|
|
|
|
|
var markdown = require('./lib/markdown');
|
|
|
|
var getUserInfo = require('./lib/github');
|
|
|
|
var defaultEmojis = require('./lib/emoji');
|
|
|
|
var addContributor = require('./lib/addContributor');
|
|
|
|
|
2016-02-29 23:15:56 +00:00
|
|
|
var cwd = process.cwd();
|
|
|
|
var defaultRCFile = path.join(cwd, '.all-contributorsrc');
|
2016-02-29 10:45:19 +00:00
|
|
|
|
|
|
|
var argv = require('yargs')
|
2016-02-29 21:08:23 +00:00
|
|
|
.command('add', 'add a new contributor')
|
|
|
|
.usage('Usage: $0 add <username> <contribution>')
|
2016-02-29 10:45:19 +00:00
|
|
|
.demand(2)
|
|
|
|
.default('config', defaultRCFile)
|
|
|
|
.default('file', 'README.md')
|
|
|
|
.config('config', function(configPath) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
|
|
} catch (error) {
|
2016-02-29 23:15:56 +00:00
|
|
|
if (configPath !== defaultRCFile) {
|
2016-02-29 10:45:19 +00:00
|
|
|
console.error(error.message);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-02-29 00:48:55 +00:00
|
|
|
}
|
2016-02-29 10:45:19 +00:00
|
|
|
})
|
|
|
|
.default('emoji', {})
|
|
|
|
.pkgConf('all-contributors')
|
|
|
|
.argv;
|
2016-02-29 00:48:55 +00:00
|
|
|
|
2016-02-29 10:45:19 +00:00
|
|
|
argv.emoji = assign({}, defaultEmojis, argv.emoji);
|
2016-02-29 21:08:23 +00:00
|
|
|
argv.username = argv._[1];
|
|
|
|
argv.contributions = argv._[2].split(',');
|
2016-02-29 23:15:56 +00:00
|
|
|
argv.file = path.join(cwd, argv.file);
|
2016-02-29 00:48:55 +00:00
|
|
|
|
2016-02-29 10:45:19 +00:00
|
|
|
getUserInfo(argv.username, function(error, user) {
|
2016-02-29 00:48:55 +00:00
|
|
|
if (error) {
|
|
|
|
return console.error(error);
|
|
|
|
}
|
2016-02-29 10:45:19 +00:00
|
|
|
markdown.read(argv.file, function(error, fileContent) {
|
2016-02-29 00:48:55 +00:00
|
|
|
if (error) {
|
|
|
|
return console.error(error);
|
|
|
|
}
|
2016-02-29 10:45:19 +00:00
|
|
|
var newFileContent = addContributor(argv, user, fileContent);
|
|
|
|
markdown.write(argv.file, newFileContent, function(error, fileContent) {
|
2016-02-29 00:48:55 +00:00
|
|
|
if (error) {
|
|
|
|
return console.error(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|