2016-03-21 21:40:32 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-03-21 22:53:02 +00:00
|
|
|
var _ = require('lodash/fp');
|
|
|
|
var series = require('async/series');
|
|
|
|
|
2016-03-21 21:40:32 +00:00
|
|
|
var prompt = require('./prompt');
|
|
|
|
var configFile = require('../configFile');
|
2016-03-21 22:53:02 +00:00
|
|
|
var markdown = require('../markdown');
|
|
|
|
var initContent = require('./initContent');
|
|
|
|
|
|
|
|
function injectInFile(file, fn, cb) {
|
|
|
|
markdown.read(file, function (error, content) {
|
|
|
|
if (error) {
|
|
|
|
return cb(error);
|
|
|
|
}
|
|
|
|
markdown.write(file, fn(content), cb);
|
|
|
|
});
|
|
|
|
}
|
2016-03-21 21:40:32 +00:00
|
|
|
|
2016-03-21 22:53:02 +00:00
|
|
|
module.exports = function init(callback) {
|
2016-03-21 21:40:32 +00:00
|
|
|
prompt(function postPrompt(result) {
|
2016-03-21 22:53:02 +00:00
|
|
|
var tasks = [
|
|
|
|
function writeConfig(cb) {
|
|
|
|
configFile.writeConfig('.all-contributorsrc', result.config, cb);
|
|
|
|
},
|
|
|
|
function addContributorsList(cb) {
|
|
|
|
injectInFile(result.contributorFile, initContent.addContributorsList, cb);
|
|
|
|
},
|
|
|
|
result.badgeFile && function addBadge(cb) {
|
|
|
|
injectInFile(result.badgeFile, initContent.addBadge, cb);
|
|
|
|
}
|
|
|
|
];
|
|
|
|
series(_.compact(tasks), callback);
|
2016-03-21 21:40:32 +00:00
|
|
|
});
|
|
|
|
};
|