mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 14:06:34 +00:00
34 lines
837 B
JavaScript
34 lines
837 B
JavaScript
'use strict';
|
|
|
|
var fs = require('fs');
|
|
var _ = require('lodash/fp');
|
|
|
|
function formatCommaFirst(o) {
|
|
return JSON.stringify(o, null, 2)
|
|
.split(/(,\n\s+)/)
|
|
.map(function (e, i) {
|
|
return i % 2 ? '\n' + e.substring(4) + ', ' : e;
|
|
})
|
|
.join('') +
|
|
'\n';
|
|
}
|
|
|
|
function readConfig(configPath) {
|
|
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) {
|
|
var config = readConfig(configPath);
|
|
var content = _.assign(config, {contributors: contributors});
|
|
return fs.writeFile(configPath, formatCommaFirst(content), cb);
|
|
}
|
|
|
|
module.exports = {
|
|
readConfig: readConfig,
|
|
writeConfig: writeConfig,
|
|
writeContributors: writeContributors
|
|
};
|