Remove odd rc file formatting (fixes #11)

This commit is contained in:
Jeroen Engels 2016-03-30 19:16:58 +02:00
parent 79473ba017
commit cb5895dbfd
2 changed files with 22 additions and 32 deletions

View file

@ -1,26 +1,26 @@
{ {
"projectOwner": "jfmengels" "projectOwner": "jfmengels",
, "projectName": "all-contributors-cli" "projectName": "all-contributors-cli",
, "imageSize": 100 "imageSize": 100,
, "commit": true "commit": true,
, "contributors": [ "contributors": [
{ {
"login": "jfmengels" "login": "jfmengels",
, "name": "Jeroen Engels" "name": "Jeroen Engels",
, "avatar_url": "https://avatars.githubusercontent.com/u/3869412?v=3" "avatar_url": "https://avatars.githubusercontent.com/u/3869412?v=3",
, "profile": "https://github.com/jfmengels" "profile": "https://github.com/jfmengels",
, "contributions": [ "contributions": [
"code" "code",
, "doc" "doc",
, "test" "test"
] ]
} },
, { {
"login": "kentcdodds" "login": "kentcdodds",
, "name": "Kent C. Dodds" "name": "Kent C. Dodds",
, "avatar_url": "https://avatars.githubusercontent.com/u/1500684?v=3" "avatar_url": "https://avatars.githubusercontent.com/u/1500684?v=3",
, "profile": "http://kentcdodds.com/" "profile": "http://kentcdodds.com/",
, "contributions": [ "contributions": [
"doc" "doc"
] ]
} }

View file

@ -3,28 +3,18 @@
var fs = require('fs'); var fs = require('fs');
var _ = require('lodash/fp'); 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) { function readConfig(configPath) {
return JSON.parse(fs.readFileSync(configPath, 'utf-8')); return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
} }
function writeConfig(configPath, content, cb) { function writeConfig(configPath, content, cb) {
return fs.writeFile(configPath, formatCommaFirst(content), cb); return fs.writeFile(configPath, JSON.stringify(content, null, 2), cb);
} }
function writeContributors(configPath, contributors, cb) { function writeContributors(configPath, contributors, cb) {
var config = readConfig(configPath); var config = readConfig(configPath);
var content = _.assign(config, {contributors: contributors}); var content = _.assign(config, {contributors: contributors});
return fs.writeFile(configPath, formatCommaFirst(content), cb); return fs.writeFile(configPath, JSON.stringify(content, null, 2), cb);
} }
module.exports = { module.exports = {