mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 22:16:31 +00:00
190813c61e
* Show a helpful message when .all-contributorsrc doesn't exist. * Adding unit tests. * Better test descriptions. * Just code improvements.
36 lines
852 B
JavaScript
36 lines
852 B
JavaScript
'use strict';
|
|
|
|
var fs = require('fs');
|
|
var _ = require('lodash/fp');
|
|
|
|
function readConfig(configPath) {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
} catch (error) {
|
|
if (error.code === 'ENOENT') {
|
|
throw new Error('Configuration file not found: ' + configPath);
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
function writeConfig(configPath, content, cb) {
|
|
return fs.writeFile(configPath, JSON.stringify(content, null, 2) + '\n', cb);
|
|
}
|
|
|
|
function writeContributors(configPath, contributors, cb) {
|
|
var config;
|
|
try {
|
|
config = readConfig(configPath);
|
|
} catch (error) {
|
|
return cb(error);
|
|
}
|
|
var content = _.assign(config, {contributors: contributors});
|
|
return writeConfig(configPath, content, cb);
|
|
}
|
|
|
|
module.exports = {
|
|
readConfig: readConfig,
|
|
writeConfig: writeConfig,
|
|
writeContributors: writeContributors
|
|
};
|