all-contributors-cli/lib/init/index.js

36 lines
973 B
JavaScript
Raw Normal View History

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-27 15:08:25 +00:00
var util = require('../util');
2016-03-21 21:40:32 +00:00
var prompt = require('./prompt');
2016-03-21 22:53:02 +00:00
var initContent = require('./initContent');
2016-03-27 15:08:25 +00:00
var configFile = util.configFile;
var markdown = util.markdown;
2016-03-21 22:53:02 +00:00
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
});
};